Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

main.cpp

Go to the documentation of this file.
00001 // $Id: main.cpp,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00002 
00003 #include "ACEXML/common/FileCharStream.h"
00004 #include "ACEXML/common/HttpCharStream.h"
00005 #include "ACEXML/common/StrCharStream.h"
00006 #include "ACEXML/parser/parser/Parser.h"
00007 #include "Print_Handler.h"
00008 #include "SAXPrint_Handler.h"
00009 #include "ace/Get_Opt.h"
00010 #include "ace/Auto_Ptr.h"
00011 
00012 static const ACEXML_Char *test_string =
00013 ACE_TEXT ("<?xml version='1.0'?> <ACE_Svc_Conf> <static id=\"ACE_Service_Manager\" params='-d -p 4911'/> <dynamic id=\"Test_Task\" type=\"service_object\"> &#65; &amp; <initializer path=\"CCM_App\" init='_make_Test_Task' params='-p 3000'/> </dynamic> </ACE_Svc_Conf>");
00014 
00015 static void
00016 usage (const ACE_TCHAR* program)
00017 {
00018   ACE_ERROR ((LM_ERROR,
00019               ACE_TEXT ("Usage: %s [-sl] [-f <filename> | -u <url>]\n")
00020               ACE_TEXT ("  -s: Use SAXPrint_Handler (Default is Print_Handler)\n")
00021               ACE_TEXT ("  -l: Parse the internal strings (test the StrCharStream class)\n")
00022               ACE_TEXT ("  -f: Specify the filename when -l is not specified\n")
00023               ACE_TEXT ("  -n: Use the \"Simple\" parsing feature\n")
00024               ACE_TEXT ("  -u: URL specifying the path to the file\n"),
00025               program));
00026 }
00027 
00028 int
00029 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
00030 {
00031   ACEXML_Char* filename = 0;
00032   int sax = 0;                  // Use SAXPrint handler or not.
00033   int str = 0;
00034   int simple = 0;
00035   ACEXML_Char* url = 0;
00036 
00037   ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("snf:lu:"));
00038   int c;
00039 
00040   while ((c = get_opt ()) != EOF)
00041     {
00042       switch (c)
00043         {
00044         case 's':
00045           sax = 1;
00046           break;
00047         case 'l':
00048           str = 1;
00049           break;
00050         case 'f':
00051           filename = get_opt.opt_arg ();
00052           break;
00053         case 'n':
00054           simple = 1;
00055           break;
00056         case 'u':
00057           url = get_opt.opt_arg();
00058           break;
00059         default:
00060           usage(argv[0]);
00061           return -1;
00062         }
00063     }
00064 
00065   if (str == 0 && filename == 0 && url == 0) {
00066     usage(argv[0]);
00067     return -1;
00068   }
00069 
00070   ACEXML_DefaultHandler *handler = 0;
00071   auto_ptr<ACEXML_DefaultHandler> cleanup_handler (handler);
00072   ACEXML_CharStream *stm = 0;
00073   ACEXML_FileCharStream *fstm = 0;
00074   ACEXML_HttpCharStream *ustm = 0;
00075     if (filename != 0)
00076       {
00077         ACE_NEW_RETURN (fstm,
00078                         ACEXML_FileCharStream (),
00079                         -1);
00080 
00081         if (fstm->open (filename) != 0)
00082           ACE_ERROR_RETURN ((LM_ERROR,
00083                              ACE_TEXT ("Failed to open XML file: %s\n"),
00084                              filename),
00085                             -1);
00086         stm = fstm;
00087       }
00088     else if (url != 0)
00089       {
00090 
00091         ACE_NEW_RETURN (ustm,
00092                         ACEXML_HttpCharStream (),
00093                         -1);
00094         if (ustm->open (url) != 0)
00095           ACE_ERROR_RETURN ((LM_ERROR,
00096                              ACE_TEXT ("Failed to open URL : %s\n"),
00097                              url),
00098                             -1);
00099         stm = ustm;
00100       }
00101     else {
00102       ACE_NEW_RETURN (stm,
00103                         ACEXML_StrCharStream (test_string),
00104                         -1);
00105       }
00106 
00107   ACEXML_Char* name = (filename == 0) ? url : filename;
00108     if (sax == 0)
00109       ACE_NEW_RETURN (handler,
00110                     ACEXML_Print_Handler (name),
00111                       -1);
00112     else
00113       ACE_NEW_RETURN (handler,
00114                     ACEXML_SAXPrint_Handler (name),
00115                       -1);
00116 
00117   ACEXML_TRY_NEW_ENV
00118     {
00119       ACEXML_Parser parser;
00120       if (simple != 0)
00121         {
00122           parser.setFeature (ACE_TEXT ("Simple"), 1 ACEXML_ENV_ARG_PARAMETER);
00123           ACEXML_TRY_CHECK;
00124         }
00125       ACEXML_InputSource input(stm);
00126 
00127       parser.setContentHandler (handler);
00128       parser.setDTDHandler (handler);
00129       parser.setErrorHandler (handler);
00130       parser.setEntityResolver (handler);
00131 
00132       parser.parse (&input ACEXML_ENV_ARG_PARAMETER);
00133       ACEXML_TRY_CHECK;
00134     }
00135   ACEXML_CATCH (ACEXML_SAXException, ex)
00136     {
00137       ACE_UNUSED_ARG (ex);
00138       ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Exception occurred. Exiting...\n")));
00139   }
00140   ACEXML_ENDTRY;
00141   return 0;
00142 }

Generated on Mon Jun 16 13:23:22 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002