List of usage examples for org.apache.commons.digester Digester getRules
public Rules getRules()
Rules implementation object containing our rules collection and associated matching policy. From source file:com.discursive.jccook.xml.bean.ProgrammaticDigesterExample.java
public void testDigest() throws Exception { List plays = new ArrayList(); Digester digester = new Digester(); Rules rules = digester.getRules(); rules.add("plays/play", new ObjectCreateRule("com.discursive.jccook.xml.bean.Play")); rules.add("plays/play", new SetNextRule("add", "java.lang.Object")); rules.add("plays/play", new SetPropertiesRule()); rules.add("plays/play/name", new BeanPropertySetterRule("name")); rules.add("plays/play/summary", new BeanPropertySetterRule("summary")); rules.add("plays/play/author", new BeanPropertySetterRule("author")); rules.add("plays/play/characters/character", new ObjectCreateRule("com.discursive.jccook.xml.bean.Character")); rules.add("plays/play/characters/character", new SetNextRule("addCharacter", "com.discursive.jccook.xml.bean.Character")); rules.add("plays/play/characters/character", new SetPropertiesRule()); rules.add("plays/play/characters/character/name", new BeanPropertySetterRule("name")); rules.add("plays/play/characters/character/description", new BeanPropertySetterRule("description")); digester.push(plays);//from w w w . j a va 2 s . co m InputStream input = getClass().getResourceAsStream("./plays.xml"); digester.parse(input); System.out.println("Number of plays: " + plays.size()); }
From source file:com.alibaba.antx.config.descriptor.ConfigDescriptorLoader.java
/** ?validators.xmlvalidator */ private Digester loadValidatorPlugins() { Digester digester = new Digester(); digester.setRules(new PluginRules()); digester.addObjectCreate("config-property-validators", HashMap.class); digester.addCallMethod("config-property-validators/validator", "put", 2); digester.addCallParam("config-property-validators/validator", 0, "id"); digester.addCallParam("config-property-validators/validator", 1, "class"); digester.addRule("config-property-validators/validator", new PluginDeclarationRule()); InputStream istream = getClass().getResourceAsStream("validators.xml"); try {//from w w w .j a va 2 s . c o m digester.push(digester.parse(istream)); } catch (Exception e) { throw new ConfigException("Failed to load validators", e); } finally { if (istream != null) { try { istream.close(); } catch (IOException e) { } } } digester.getRules().clear(); return digester; }
From source file:org.kuali.kfs.module.ar.batch.CustomerInvoiceWriteoffBatchDigesterTest.java
/** * @return Rules loaded from the appropriate XML file *///from w w w . ja v a2s . c o m private Rules loadRules(String digestorRulesFileName) { // locate Digester rules ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL rulesUrl = classLoader.getResource(digestorRulesFileName); if (rulesUrl == null) { throw new RuntimeException("unable to locate digester rules file " + digestorRulesFileName); } // create and init digester Digester digester = DigesterLoader.createDigester(rulesUrl); return digester.getRules(); }
From source file:org.kuali.kfs.sys.batch.XmlBatchInputFileTypeBase.java
/** * @return Rules loaded from the appropriate XML file *//*from w ww . j ava2 s.com*/ protected Rules loadRules(String digestorRulesFileName) { // locate Digester rules ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL rulesUrl = classLoader.getResource(digestorRulesFileName); if (rulesUrl == null) { throw new RuntimeException("unable to locate digester rules file " + digestorRulesFileName); } // create and init digester Digester digester = DigesterLoader.createDigester(rulesUrl); return digester.getRules(); }
From source file:org.xchain.framework.digester.AnnotationRuleSet.java
public void addRuleInstances(Digester digester) { // log what we are attempting to do. // set up the namespace in the digester. digester.setNamespaceAware(true);/*w ww.j a va 2 s .co m*/ // add the place holder rule used to pass mappings when there is not an element to pass them on... // TODO: add code for the place holder command. LifecycleContext lifecycleContext = Lifecycle.getLifecycleContext(); for (NamespaceContext namespaceContext : lifecycleContext.getNamespaceContextMap().values()) { digester.setRuleNamespaceURI(namespaceContext.getNamespaceUri()); for (Class classObject : namespaceContext.getCatalogList()) { // for catalogs that we find, we need to add a create rule, a properties rule, a set next rule, and a registration rule. addRulesForCatalog(digester, classObject, lifecycleContext); } for (Class classObject : namespaceContext.getCommandList()) { // for commands that we find, we need to add a create rule, a properties rule, a set next rule, and a registration rule. addRulesForCommand(digester, lifecycleContext, systemId, classObject); } } WithDefaultsRulesWrapper defaults = new WithDefaultsRulesWrapper(digester.getRules()); defaults.addDefault(new UnknownElementRule()); digester.setRules(defaults); }
From source file:org.xchain.tools.monitoring.MonitoringMojo.java
private void mergeWarMonitoringInfo(MonitoringInfo monitoringInfo, File file) throws MojoExecutionException { JarFile artifactJar = null;/*from w w w . j av a 2s . c om*/ JarEntry monitoringInfoEntry = null; InputStream in = null; try { getLog().info("Getting monitoring info from file " + file.toString()); artifactJar = new JarFile(file); monitoringInfoEntry = artifactJar.getJarEntry("WEB-INF/classes/META-INF/monitoring-info.xml"); if (monitoringInfoEntry != null) { in = artifactJar.getInputStream(monitoringInfoEntry); // digest the xml file and get all of the entries. Digester digester = new Digester(); digester.push(monitoringInfo); digester.addRuleSet(new MonitoringInfoRuleSet()); WithDefaultsRulesWrapper wrapper = new WithDefaultsRulesWrapper(digester.getRules()); wrapper.addDefault(new LoggingRule()); digester.setRules(wrapper); digester.parse(in); } else { getLog().info("Monitoring info file not found in " + file.toString()); } } catch (SAXException se) { throw new MojoExecutionException("Could not parse a monitoring-info.xml file.", se); } catch (IOException ioe) { throw new MojoExecutionException("Could not open jar file.", ioe); } finally { if (in != null) { try { in.close(); } catch (IOException ioe) { getLog().warn("Could not close a jar entry input stream.", ioe); } } try { artifactJar.close(); } catch (IOException ioe) { getLog().warn("Could not close a jar.", ioe); } } }