List of usage examples for org.apache.commons.digester Digester parse
public Object parse(URL url) throws IOException, SAXException
From source file:org.apache.struts.action.RegistryServlet.java
/** * Parse the specified activity definition file for this instance. * * @param path Context-relative resource path of the activity * definition file//from www.j ava2 s. c om * * @exception ServletException on any processing error in parsing */ private void parse(String path) throws ServletException { // Get an input source for the specified path InputStream is = getServletContext().getResourceAsStream(path); if (is == null) throw new UnavailableException("Cannot access resource " + path); // Configure a Digester instance to parse our definition file Digester digester = new Digester(); digester.setNamespaceAware(true); digester.setValidating(false); digester.push(this); // Add rules to recognize the built-in steps that we know about BaseRuleSet brs = new BaseRuleSet(); digester.addRuleSet(brs); digester.addRuleSet(new CoreRuleSet()); digester.addRuleSet(new IoRuleSet()); digester.addRuleSet(new WebRuleSet()); // Add a rule to register the Activity being created digester.setRuleNamespaceURI(brs.getNamespaceURI()); digester.addSetNext("activity", "setActivity", "org.apache.commons.workflow.Activity"); // Parse the activity definition file try { digester.parse(is); } catch (Throwable t) { log("Cannot parse resource " + path, t); throw new UnavailableException("Cannot parse resource " + path); } finally { try { is.close(); } catch (Throwable u) { ; } } }
From source file:org.apache.struts.apps.mailreader.dao.impl.memory.MemoryUserDatabase.java
public void open() throws Exception { FileInputStream fis = null;/*from ww w . ja v a 2 s .c o m*/ BufferedInputStream bis = null; try { // Acquire an input stream to our database file if (log.isDebugEnabled()) { log.debug("Loading database from '" + pathname + "'"); } fis = new FileInputStream(pathname); bis = new BufferedInputStream(fis); // Construct a digester to use for parsing Digester digester = new Digester(); digester.push(this); digester.setValidating(false); digester.addFactoryCreate("database/user", new MemoryUserCreationFactory(this)); digester.addFactoryCreate("database/user/subscription", new MemorySubscriptionCreationFactory()); // Parse the input stream to initialize our database digester.parse(bis); bis.close(); bis = null; fis = null; this.open = true; } catch (Exception e) { log.error("Loading database from '" + pathname + "':", e); throw e; } finally { if (bis != null) { try { bis.close(); } catch (Throwable t) { // do nothing } bis = null; fis = null; } } }
From source file:org.apache.struts.config.TestModuleConfig.java
private void parseConfig(String publicId, String entityURL, String strutsConfig) { // Prepare a Digester for parsing a struts-config.xml file Digester digester = new Digester(); digester.push(config);// w w w. j a v a 2 s .co m digester.setNamespaceAware(true); digester.setValidating(true); digester.addRuleSet(new ConfigRuleSet()); digester.register(publicId, this.getClass().getResource(entityURL).toString()); // Parse the test struts-config.xml file try { InputStream input = this.getClass().getResourceAsStream(strutsConfig); assertNotNull("Got an input stream for " + strutsConfig, input); digester.parse(input); input.close(); } catch (Throwable t) { t.printStackTrace(System.out); fail("Parsing threw exception: " + t); } }
From source file:org.apache.struts.examples.mailreader.memory.MemoryUserDatabase.java
public void open() throws Exception { FileInputStream fis = null;/*from w ww . j a v a 2 s. c o m*/ BufferedInputStream bis = null; try { // Acquire an input stream to our database file if (log.isDebugEnabled()) { log.debug("Loading database from '" + pathname + "'"); } fis = new FileInputStream(pathname); bis = new BufferedInputStream(fis); // Construct a digester to use for parsing Digester digester = new Digester(); digester.push(this); digester.setValidating(false); digester.addFactoryCreate("database/user", new MemoryUserCreationFactory(this)); digester.addFactoryCreate("database/user/subscription", new MemorySubscriptionCreationFactory()); // Parse the input stream to initialize our database digester.parse(bis); bis.close(); bis = null; fis = null; } catch (Exception e) { log.error("Loading database from '" + pathname + "':", e); throw e; } finally { if (bis != null) { try { bis.close(); } catch (Throwable t) { ; } bis = null; fis = null; } } }
From source file:org.apache.struts.plugins.DigestingPlugIn.java
/** * <p>Initialize a <code>Digester</code> and use it to parse a * configuration file, resulting in a root object which will be placed into * the ServletContext.</p>/*from w w w. ja v a2 s .c om*/ * * @param servlet ActionServlet that is managing all the * modules in this web application * @param config ModuleConfig for the module with which * this plug-in is associated * * @throws ServletException if this <code>PlugIn</code> cannot * be successfully initialized */ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { this.servlet = servlet; this.moduleConfig = config; Object obj = null; Digester digester = this.initializeDigester(); if (this.push) { log.debug("push == true; pushing plugin onto digester stack"); digester.push(this); } try { log.debug("XML data file: [path: " + this.configPath + ", source: " + this.configSource + "]"); URL configURL = this.getConfigURL(this.configPath, this.configSource); if (configURL == null) throw new ServletException("Unable to locate XML data file at [path: " + this.configPath + ", source: " + this.configSource + "]"); obj = digester.parse(configURL.openStream()); } catch (IOException e) { // TODO Internationalize msg log.error("Exception processing config", e); throw new ServletException(e); } catch (SAXException e) { // TODO Internationalize msg log.error("Exception processing config", e); throw new ServletException(e); } this.storeGeneratedObject(obj); }
From source file:org.apache.struts.service.ServiceManager.java
/** Read self-contained config with help of digester. *//*from w w w . j a v a 2s .c o m*/ public void initConfig() throws Exception { String value = null; String configLocation = "service-manager.xml"; try { value = System.getProperty("org.apache.struts.service.Debug"); setDebug(Integer.parseInt(value)); } catch (Throwable t) { setDebug(0); } try { value = System.getProperty("org.apache.struts.service.ConfigLocation"); } catch (SecurityException e) { throw e; } catch (Exception e) { if (debug > 0) logHelper.log(internal.getMessage("configLocationProperty.emptyProperty", configLocation)); } if (value != null) configLocation = value; int detail; try { value = System.getProperty("org.apache.struts.service.ConfigDetail"); detail = Integer.parseInt(value); } catch (Throwable t) { detail = 0; } // Acquire an input stream to our configuration resource InputStream input = new FileInputStream(configLocation); // Build a digester to process our configuration resource Digester digester = initDigester(detail); // Parse the input stream to configure our mappings try { digester.parse(input); } catch (SAXException e) { throw e; } finally { input.close(); } }
From source file:org.apache.struts.webapp.example2.memory.MemoryUserDatabase.java
/** * <p>Initiate access to the underlying persistence layer.</p> * * @exception Exception if a database access error occurs *///from ww w .ja va 2s. co m public void open() throws Exception { FileInputStream fis = null; BufferedInputStream bis = null; try { // Acquire an input stream to our database file if (log.isDebugEnabled()) { log.debug("Loading database from '" + pathname + "'"); } fis = new FileInputStream(pathname); bis = new BufferedInputStream(fis); // Construct a digester to use for parsing Digester digester = new Digester(); digester.push(this); digester.setValidating(false); digester.addFactoryCreate("database/user", new MemoryUserCreationFactory(this)); digester.addFactoryCreate("database/user/subscription", new MemorySubscriptionCreationFactory(this)); // Parse the input stream to initialize our database digester.parse(bis); bis.close(); bis = null; fis = null; } catch (Exception e) { log.error("Loading database from '" + pathname + "':", e); throw e; } finally { if (bis != null) { try { bis.close(); } catch (Throwable t) { ; } bis = null; fis = null; } } }
From source file:org.apache.uima.alchemy.digester.categorization.JsonTextCategorizationDigester.java
public Results parseAlchemyXML(InputStream stream) throws IOException, SAXException, URISyntaxException { Digester digester = new JsonDigester(); digester.setValidating(false);//from w w w . j ava2 s . co m digester.addObjectCreate("$", CategorizationResults.class); digester.addBeanPropertySetter("$/status", "status"); digester.addBeanPropertySetter("$/url", "url"); digester.addBeanPropertySetter("$/language", "language"); digester.addBeanPropertySetter("$/category", "category"); digester.addBeanPropertySetter("$/score", "score"); return (Results) digester.parse(stream); }
From source file:org.apache.uima.alchemy.digester.categorization.XMLTextCategorizationDigester.java
public Results parseAlchemyXML(InputStream stream) throws IOException, SAXException, URISyntaxException { Digester digester = new Digester(); digester.setValidating(false);/*from ww w .j a va 2 s.co m*/ digester.addObjectCreate("results", CategorizationResults.class); digester.addBeanPropertySetter("results/status", "status"); digester.addBeanPropertySetter("results/url", "url"); digester.addBeanPropertySetter("results/category", "category"); digester.addBeanPropertySetter("results/score", "score"); return (Results) digester.parse(stream); }
From source file:org.apache.uima.alchemy.digester.entity.annotated.XMLAnnotatedEntityExtractionDigester.java
public Results parseAlchemyXML(InputStream stream) throws IOException, SAXException, URISyntaxException { Digester digester = new Digester(); digester.setValidating(false);//from ww w . ja v a2 s .co m digester.addObjectCreate("results", AnnotatedResults.class); digester.addBeanPropertySetter("results/status", "status"); digester.addBeanPropertySetter("results/language", "language"); digester.addBeanPropertySetter("results/text", "text"); digester.addBeanPropertySetter("results/url", "url"); digester.addBeanPropertySetter("results/annotatedText", "annotatedText"); return (Results) digester.parse(stream); }