int ACEXML_Svcconf_Parser::parse_file (const ACE_TCHAR file[]) { if (file == 0) ACE_ERROR_RETURN ((LM_ERROR, "ACEXML_Svcconf_Parser: No filename specified\n"), -1); ACEXML_FileCharStream *fstm = 0; ACE_NEW_RETURN (fstm, ACEXML_FileCharStream (), 1); if (fstm->open (file) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ACEXML_Svcconf_Parser: Fail to open XML file: %s\n"), file), -1); this->input_stream_.setCharStream (fstm); try { this->parser_.parse (&this->input_stream_); } catch (const ACEXML_SAXException& ex) { ex.print (); return -1; } 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; }
/* static */ int XML_Backing_Store::load_file (const ACE_TString& filename, ACEXML_DefaultHandler& xml_handler, unsigned int debug, FILE* open_file) { // xml input source will take ownership ACEXML_FileCharStream* fstm; ACE_NEW_RETURN (fstm, ACEXML_FileCharStream, -1); int err; // use the open_file stream if it is provided if (open_file != 0) err = fstm->use_stream(open_file, filename.c_str()); else err = fstm->open (filename.c_str()); if (debug > 9) { ORBSVCS_DEBUG ((LM_INFO, ACE_TEXT ("load %s%C\n"), filename.c_str(), ((err == 0) ? ACE_TEXT ("") : ACE_TEXT (" (file doesn't exist)")))); } if (err != 0) { delete fstm; return err; } ACEXML_Parser parser; // InputSource takes ownership ACEXML_InputSource input (fstm); parser.setContentHandler (&xml_handler); parser.setDTDHandler (&xml_handler); parser.setErrorHandler (&xml_handler); parser.setEntityResolver (&xml_handler); try { parser.parse (&input); } catch ( const ACEXML_SAXParseException* sax_ex) { ORBSVCS_ERROR ((LM_ERROR, ACE_TEXT ("Error during load of ImR persistence xml file (%s)."), filename.c_str())); sax_ex->print (); return -1; } catch (const ACEXML_Exception& ex) { ORBSVCS_ERROR ((LM_ERROR, ACE_TEXT ("Error during load of ImR persistence xml file (%s)."), filename.c_str())); ex.print (); return -1; } return 0; }