int ACE_TMAIN (int, ACE_TCHAR *[]) { const ACEXML_Char* test = ACE_TEXT("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); const ACEXML_Char* simple = ACE_TEXT("http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent"); ACEXML_HttpCharStream first; ACEXML_HttpCharStream second; ACEXML_Char ch; if (first.open (test) != -1) { while (first.get (ch) != -1) ACE_OS::printf ("%c", ch); } else { first.close(); ACE_ERROR ((LM_ERROR, "Error in opening stream : %m\n")); } if (second.open (simple) != -1) { while (second.get (ch) != -1) ACE_OS::printf ("%c", ch); } else { second.close(); ACE_ERROR ((LM_ERROR, "Error in opening stream : %m\n")); } first.close(); second.close(); return 0; }
ACEXML_CharStream* ACEXML_StreamFactory::create_stream (const ACEXML_Char* uri) { if (uri == 0) return 0; ACEXML_FileCharStream* fstream = 0; ACEXML_HttpCharStream* hstream = 0; if (ACE_OS::strstr (uri, ACE_TEXT("ftp://")) != 0) { return 0; } else if (ACE_OS::strstr (uri, ACE_TEXT ("http://")) != 0) { ACE_NEW_RETURN (hstream, ACEXML_HttpCharStream, 0); if (hstream->open (uri) != -1) return hstream; } else { if (ACE_OS::strstr (uri, ACE_TEXT ("file://")) != 0) uri += 7; // Skip over file:// ACE_NEW_RETURN (fstream, ACEXML_FileCharStream, 0); if (fstream->open (uri) != -1) return fstream; #ifdef USE_ZZIP else { ACEXML_ZipCharStream* zstream = 0; ACE_NEW_RETURN (zstream, ACEXML_ZipCharStream, 0); if (zstream->open (uri) != -1) return zstream; } #endif /* USE_ZZIP */ } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACEXML_Char* filename = 0; int sax = 0; // Use SAXPrint handler or not. int str = 0; #ifdef USE_ZZIP int zip = 0; #endif ACEXML_Char* url = 0; ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("sf:lu:z")); int c; while ((c = get_opt ()) != EOF) { switch (c) { case 's': sax = 1; break; case 'l': str = 1; break; case 'f': filename = get_opt.opt_arg (); break; case 'u': url = get_opt.opt_arg(); break; case 'z': #ifndef USE_ZZIP ACE_ERROR ((LM_ERROR, ACE_TEXT ("ZZIPLIB support has not been") ACE_TEXT (" compiled in. Refer to ") ACE_TEXT ("$ACE_ROOT/ACEXML/README for more ") ACE_TEXT ("information.\n"))); return -1; #else zip = 1; break; #endif /* USE_ZZIP */ default: usage(argv[0]); return -1; } } if (str == 0 && filename == 0 && url == 0) { usage(argv[0]); return -1; } ACEXML_DefaultHandler *handler = 0; ACEXML_CharStream *stm = 0; ACEXML_FileCharStream *fstm = 0; ACEXML_HttpCharStream *ustm = 0; ACEXML_StrCharStream* sstm = 0; #ifdef USE_ZZIP ACEXML_ZipCharStream* zstm = 0; #endif /* USE_ZZIP */ if (filename != 0) { #ifdef USE_ZZIP if (zip) { ACE_NEW_RETURN (zstm, ACEXML_ZipCharStream(), -1); if (zstm->open (filename) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Failed to open XML file: %s\n"), filename), -1); stm = zstm; } else { #endif /* USE_ZZIP */ ACE_NEW_RETURN (fstm, ACEXML_FileCharStream (), -1); if (fstm->open (filename) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Failed to open XML file: %s\n"), filename), -1); stm = fstm; #ifdef USE_ZZIP } #endif /* USE_ZZIP */ } else if (url != 0) { ACE_NEW_RETURN (ustm, ACEXML_HttpCharStream (), -1); if (ustm->open (url) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Failed to open URL : %s\n"), url), -1); stm = ustm; } else { ACE_NEW_RETURN (sstm, ACEXML_StrCharStream, -1); if (sstm->open (test_string, ACE_TEXT ("test_string")) < 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Failed to open string : %s\n"), test_string), -1); stm = sstm; } ACEXML_Char* name = (filename == 0) ? url : filename; if (sax == 0) ACE_NEW_RETURN (handler, ACEXML_Print_Handler (name), -1); else ACE_NEW_RETURN (handler, ACEXML_SAXPrint_Handler (name), -1); auto_ptr<ACEXML_DefaultHandler> cleanup_handler (handler); ACEXML_Parser parser; ACEXML_InputSource input (stm); parser.setContentHandler (handler); parser.setDTDHandler (handler); parser.setErrorHandler (handler); parser.setEntityResolver (handler); try { parser.parse (&input); } catch (const ACEXML_Exception& ex) { ex.print(); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Exception occurred. Exiting...\n"))); } try { parser.parse (&input); } catch (const ACEXML_SAXException& ex) { ex.print(); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Exception occurred. Exiting...\n"))); return 1; } // ACEXML_TRY_EX (THIRD) // { // parser.parse (&input ACEXML_ENV_ARG_PARAMETER); // ACEXML_TRY_CHECK_EX (THIRD); // } // ACEXML_CATCH (ACEXML_SAXException, ex) // { // ex.print(); // ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Exception occurred. Exiting...\n"))); // return 1; // } // ACEXML_ENDTRY; // ACEXML_TRY_EX (FOURTH) // { // parser.parse (&input ACEXML_ENV_ARG_PARAMETER); // ACEXML_TRY_CHECK_EX (FOURTH); // } // ACEXML_CATCH (ACEXML_SAXException, ex) // { // ex.print(); // ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Exception occurred. Exiting...\n"))); // return 1; // } // ACEXML_ENDTRY; return 0; }