1 #include "ACEXML/common/FileCharStream.h"
2 #include "ACEXML/common/HttpCharStream.h"
3 #include "ACEXML/common/StrCharStream.h"
4 #include "ACEXML/common/ZipCharStream.h"
5 #include "ACEXML/parser/parser/Parser.h"
6 #include "Print_Handler.h"
7 #include "SAXPrint_Handler.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_main.h"
12 static const ACEXML_Char
*test_string
=
13 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\"> A " <initializer path=\"CCM_App\" init='_make_Test_Task' params='-p 3000'/> </dynamic> </ACE_Svc_Conf>");
16 usage (const ACE_TCHAR
* program
)
19 ACE_TEXT ("Usage: %s [-sl] [-f <filename> | -u <url> | -z <ZIP Archive>]\n")
20 ACE_TEXT (" -s: Use SAXPrint_Handler (Default is Print_Handler)\n")
21 ACE_TEXT (" -l: Parse the internal strings (test the StrCharStream class)\n")
22 ACE_TEXT (" -f: Specify the filename when -l is not specified\n")
23 ACE_TEXT (" -z: Specify that the file is inside a ZIP archive\n")
24 ACE_TEXT (" -u: URL specifying the path to the file\n"),
29 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
31 ACEXML_Char
* filename
= 0;
32 int sax
= 0; // Use SAXPrint handler or not.
39 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT ("sf:lu:z"));
42 while ((c
= get_opt ()) != EOF
)
53 filename
= get_opt
.opt_arg ();
56 url
= get_opt
.opt_arg();
60 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("ZZIPLIB support has not been")
61 ACE_TEXT (" compiled in. Refer to ")
62 ACE_TEXT ("$ACE_ROOT/ACEXML/README for more ")
63 ACE_TEXT ("information.\n")));
75 if (str
== 0 && filename
== 0 && url
== 0) {
80 ACEXML_DefaultHandler
*handler
= 0;
81 ACEXML_CharStream
*stm
= 0;
82 ACEXML_FileCharStream
*fstm
= 0;
83 ACEXML_HttpCharStream
*ustm
= 0;
84 ACEXML_StrCharStream
* sstm
= 0;
86 ACEXML_ZipCharStream
* zstm
= 0;
93 ACE_NEW_RETURN (zstm
, ACEXML_ZipCharStream(), -1);
94 if (zstm
->open (filename
) != 0)
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 ACE_TEXT ("Failed to open XML file: %s\n"),
103 #endif /* USE_ZZIP */
104 ACE_NEW_RETURN (fstm
, ACEXML_FileCharStream (), -1);
105 if (fstm
->open (filename
) != 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 ACE_TEXT ("Failed to open XML file: %s\n"),
113 #endif /* USE_ZZIP */
117 ACE_NEW_RETURN (ustm
, ACEXML_HttpCharStream (), -1);
118 if (ustm
->open (url
) != 0)
119 ACE_ERROR_RETURN ((LM_ERROR
,
120 ACE_TEXT ("Failed to open URL : %s\n"),
127 ACE_NEW_RETURN (sstm
, ACEXML_StrCharStream
, -1);
128 if (sstm
->open (test_string
, ACE_TEXT ("test_string")) < 0)
129 ACE_ERROR_RETURN ((LM_ERROR
,
130 ACE_TEXT ("Failed to open string : %s\n"),
136 ACEXML_Char
* name
= (filename
== 0) ? url
: filename
;
138 ACE_NEW_RETURN (handler
,
139 ACEXML_Print_Handler (name
),
142 ACE_NEW_RETURN (handler
,
143 ACEXML_SAXPrint_Handler (name
),
146 std::unique_ptr
<ACEXML_DefaultHandler
> cleanup_handler (handler
);
148 ACEXML_Parser parser
;
149 ACEXML_InputSource
input (stm
);
151 parser
.setContentHandler (handler
);
152 parser
.setDTDHandler (handler
);
153 parser
.setErrorHandler (handler
);
154 parser
.setEntityResolver (handler
);
158 parser
.parse (&input
);
160 catch (const ACEXML_Exception
& ex
)
163 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("Exception occurred. Exiting...\n")));
167 parser
.parse (&input
);
169 catch (const ACEXML_SAXException
& ex
)
172 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("Exception occurred. Exiting...\n")));