List of usage examples for org.apache.commons.digester Digester getRoot
public Object getRoot()
From source file:org.apache.myfaces.custom.skin.config.ConfigParser.java
/** * *//* ww w . j a v a 2s . c om*/ static public RequestContextBean parseConfigFile(ExternalContext externalContext) { RequestContextBean bean = new RequestContextBean(); InputStream in = externalContext.getResourceAsStream(_SKINS_CONFIG_FILE); if (in == null) { in = externalContext.getResourceAsStream(_TRINIDAD_CONFIG_FILE); } if (in != null) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); Digester digester = new Digester(factory.newSAXParser()); digester.setValidating(false); digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); RequestContextBean.addXmlRules(digester); InputSource input = new InputSource(); input.setByteStream(in); input.setPublicId(_SKINS_CONFIG_FILE); digester.parse(input); bean = (RequestContextBean) digester.getRoot(); } catch (IOException ioe) { _LOG.warning(ioe); } catch (ParserConfigurationException pce) { _LOG.warning(pce); } catch (SAXException saxe) { _LOG.warning(saxe); } finally { try { in.close(); } catch (IOException ioe) { // Ignore ; } } } return bean; }
From source file:org.geotools.data.complex.config.XMLConfigDigester.java
/** * DOCUMENT ME!/*from w w w. j a va 2s. co m*/ * * @param dataStoreConfigUrl * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws IOException * DOCUMENT ME! * @throws NullPointerException * DOCUMENT ME! */ private AppSchemaDataAccessDTO digest(final URL dataStoreConfigUrl) throws IOException { if (dataStoreConfigUrl == null) { throw new NullPointerException("datastore config url"); } // read mapping file into configString and interpolate properties InputStream configStream = null; String configString = null; try { configStream = dataStoreConfigUrl.openStream(); if (configStream == null) { throw new IOException("Can't open datastore config file " + dataStoreConfigUrl); } else { configString = properties.interpolate(InterpolationProperties.readAll(configStream)); } } finally { if (configStream != null) { configStream.close(); } } XMLConfigDigester.LOGGER.fine("parsing complex datastore config: " + dataStoreConfigUrl.toExternalForm()); Digester digester = new Digester(); XMLConfigDigester.LOGGER.fine("digester created"); // URL schema = getClass() // .getResource("../test-data/AppSchemaDataAccess.xsd"); // digester.setSchema(schema.toExternalForm()); digester.setValidating(false); digester.setNamespaceAware(true); digester.setRuleNamespaceURI(XMLConfigDigester.CONFIG_NS_URI); // digester.setRuleNamespaceURI(OGC_NS_URI); AppSchemaDataAccessDTO configDto = new AppSchemaDataAccessDTO(); configDto.setBaseSchemasUrl(dataStoreConfigUrl.toExternalForm()); digester.push(configDto); try { setNamespacesRules(digester); setIncludedTypesRules(digester); setSourceDataStoresRules(digester); setTargetSchemaUriRules(digester); setTypeMappingsRules(digester); } catch (Exception e) { e.printStackTrace(); XMLConfigDigester.LOGGER.log(Level.SEVERE, "setting digester properties: ", e); throw new IOException("Error setting digester properties: " + e.getMessage()); } try { digester.parse(new StringReader(configString)); } catch (SAXException e) { e.printStackTrace(); XMLConfigDigester.LOGGER.log(Level.SEVERE, "parsing " + dataStoreConfigUrl, e); IOException ioe = new IOException("Can't parse complex datastore config. "); ioe.initCause(e); throw ioe; } AppSchemaDataAccessDTO config = (AppSchemaDataAccessDTO) digester.getRoot(); return config; }
From source file:org.sipfoundry.commons.restconfig.RestServerConfigFileParser.java
public RestServerConfig parse(String url) { Digester digester = new Digester(); addRules(digester);//from w ww. j a va 2s .com try { InputSource inputSource = new InputSource(url); digester.parse(inputSource); RestServerConfig restServerConfig = (RestServerConfig) digester.getRoot(); return restServerConfig; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.sipfoundry.fswitchtester.TesterConfigParser.java
public TesterConfig parse(String fileName) { Digester digester = new Digester(); digester.setSchema("file:schema/tester.xsd"); addRules(digester);//from www . j a v a 2 s . c om // Process the input file. String url = "file:" + fileName; try { InputSource inputSource = new InputSource(url); digester.parse(inputSource); return (TesterConfig) digester.getRoot(); } catch (Exception se) { se.printStackTrace(System.err); throw new FreeSwitchTesterException("exception parsing config file", se); } }
From source file:org.sipfoundry.siptester.ItspAccounts.java
public static ItspAccounts createItspAccounts(String url) throws Exception { System.out.println("create ITSP accounts " + url); Digester digester = new Digester(); addRules(digester);/*from w ww . j a v a 2s . com*/ digester.parse(new InputSource(url)); return (ItspAccounts) digester.getRoot(); }
From source file:org.sipfoundry.siptester.SutConfigParser.java
public TraceConfig parse(String url) { Digester digester = new Digester(); addRules(digester);/* w w w . j ava 2 s. c o m*/ InputSource inputSource = new InputSource(url); try { digester.parse(inputSource); } catch (Exception e) { throw new SipTesterException(e); } return (TraceConfig) digester.getRoot(); }
From source file:org.sipfoundry.siptester.TesterConfigParser.java
public SipTesterConfig parse(String url) { Digester digester = new Digester(); addRules(digester);/*w ww . j a v a 2s .c o m*/ InputSource inputSource = new InputSource(url); try { digester.parse(inputSource); } catch (Exception e) { throw new SipTesterException(e); } return (SipTesterConfig) digester.getRoot(); }
From source file:org.sipfoundry.siptester.TestMapParser.java
public TestMap parse(String url) { Digester digester = new Digester(); addRules(digester);//from www . ja v a 2 s . c o m InputSource inputSource = new InputSource(url); try { digester.parse(inputSource); } catch (Exception e) { throw new SipTesterException(e); } return (TestMap) digester.getRoot(); }
From source file:org.sipfoundry.sipxbridge.ConfigurationParser.java
/** * Create an account manager structure and initialize it with the information pointed to by * the given URL.// www . jav a 2s . co m * * @param url -- the rul from where to fetch the config file. * * @return */ public AccountManagerImpl createAccountManager(String url) { // Create a Digester instance Digester digester = new Digester(); digester.setSchema("file:schema/sipxbridge.xsd"); addRules(digester); // Process the input file. try { InputSource inputSource = new InputSource(url); digester.parse(inputSource); AccountManagerImpl accountManagerImpl = (AccountManagerImpl) digester.getRoot(); BridgeConfiguration bridgeConfiguration = accountManagerImpl.getBridgeConfiguration(); if (bridgeConfiguration.getStunServerAddress() == null) { for (ItspAccountInfo itspAccountInfo : accountManagerImpl.getItspAccounts()) { if (itspAccountInfo.isGlobalAddressingUsed() && bridgeConfiguration.getGlobalAddress() == null) throw new SAXException( "Need stun server address or public address to be specified in sipxbridge configuration."); } } return (AccountManagerImpl) digester.getRoot(); } catch (java.io.IOException ioe) { // Note that we do not have a debug file here so we need to print to stderr. ioe.printStackTrace(System.err); throw new SipXbridgeException("Initialization exception", ioe); } catch (org.xml.sax.SAXException se) { se.printStackTrace(System.err); throw new SipXbridgeException("Initialization exception", se); } }
From source file:org.sipfoundry.sipxbridge.symmitron.SymmitronConfigParser.java
public SymmitronConfig parse(String url) { // Create a Digester instance Digester digester = new Digester(); // digester.setSchema("file:schema/sipxrelay.xsd"); addRules(digester);//from w w w . j a v a 2 s . c o m // Process the input file. try { InputSource inputSource = new InputSource(url); digester.parse(inputSource); return (SymmitronConfig) digester.getRoot(); } catch (java.io.IOException ioe) { // Note that we do not have a debug file here so we need to print to stderr. ioe.printStackTrace(System.err); throw new SymmitronException("Intiialzation exception", ioe); } catch (org.xml.sax.SAXException se) { se.printStackTrace(System.err); throw new SymmitronException("Intiialzation exception", se); } }