Java Code Examples for org.apache.commons.digester.Digester#parse()
The following examples show how to use
org.apache.commons.digester.Digester#parse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtractChangeLogParser.java From jenkins-test-harness with MIT License | 6 votes |
@SuppressWarnings("rawtypes") public ExtractChangeLogSet parse(AbstractBuild build, InputStream changeLogStream) throws IOException, SAXException { ArrayList<ExtractChangeLogEntry> changeLog = new ArrayList<ExtractChangeLogEntry>(); Digester digester = new Digester(); digester.setClassLoader(ExtractChangeLogSet.class.getClassLoader()); digester.push(changeLog); digester.addObjectCreate("*/extractChanges/entry", ExtractChangeLogEntry.class); digester.addBeanPropertySetter("*/extractChanges/entry/zipFile"); digester.addObjectCreate("*/extractChanges/entry/file", FileInZip.class); digester.addBeanPropertySetter("*/extractChanges/entry/file/fileName"); digester.addSetNext("*/extractChanges/entry/file", "addFile"); digester.addSetNext("*/extractChanges/entry", "add"); digester.parse(changeLogStream); return new ExtractChangeLogSet(build, changeLog); }
Example 2
Source File: ValidatorResources.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Create a ValidatorResources object from an InputStream. * * @param streams An array of InputStreams to several validation.xml * configuration files that will be read in order and merged into this object. * It's the client's responsibility to close these streams. * @throws SAXException if the validation XML files are not valid or well * formed. * @throws IOException if an I/O error occurs processing the XML files * @since Validator 1.1 */ public ValidatorResources(InputStream[] streams) throws IOException, SAXException { super(); Digester digester = initDigester(); for (int i = 0; i < streams.length; i++) { if (streams[i] == null) { throw new IllegalArgumentException("Stream[" + i + "] is null"); } digester.push(this); digester.parse(streams[i]); } this.process(); }
Example 3
Source File: DigesterPipe.java From iaf with Apache License 2.0 | 5 votes |
@Override public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException { //Multi threading: instantiate digester for each request as the digester is NOT thread-safe. //TODO: make a pool of digesters Digester digester = DigesterLoader.createDigester(rulesURL); try { return new PipeRunResult(getForward(), digester.parse(message.asReader())); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session)+"exception in digesting", e); } }
Example 4
Source File: ClientCertificateDigester.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * @param rdr to client certificate * @return a ClientCertificate * @throws IOException thrown if there is a problem reading the certificate. * @throws SAXException thrown if there is a problem reading the certificate. */ public static ClientCertificate buildCertificate(Reader rdr) throws IOException, SAXException { Digester digester = new Digester(); configureDigester(digester); return (ClientCertificate)digester.parse(rdr); }
Example 5
Source File: XmlBatchInputFileTypeBase.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * @see org.kuali.kfs.sys.batch.BatchInputFileType#parse(byte[]) */ public Object parse(byte[] fileByteContent) throws ParseException { if (fileByteContent == null) { LOG.error("an invalid(null) argument was given"); throw new IllegalArgumentException("an invalid(null) argument was given"); } // handle zero byte contents, xml parsers don't deal with them well if (fileByteContent.length == 0) { LOG.error("an invalid argument was given, empty input stream"); throw new IllegalArgumentException("an invalid argument was given, empty input stream"); } // validate contents against schema ByteArrayInputStream validateFileContents = new ByteArrayInputStream(fileByteContent); validateContentsAgainstSchema(getSchemaLocation(), validateFileContents); // setup digester for parsing the xml file Digester digester = buildDigester(getSchemaLocation(), getDigestorRulesFileName()); Object parsedContents = null; try { ByteArrayInputStream parseFileContents = new ByteArrayInputStream(fileByteContent); parsedContents = digester.parse(parseFileContents); } catch (Exception e) { LOG.error("Error parsing xml contents", e); throw new ParseException("Error parsing xml contents: " + e.getMessage(), e); } return parsedContents; }
Example 6
Source File: CustomerInvoiceWriteoffBatchDigesterTest.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
public void NORUN_testCustomerInvoiceWriteoffBatchDigesterRules() throws Exception { Digester digester = buildDigester(SCHEMA_DIRECTORY + SCHEMA_FILE, DIGESTER_RULE_DIRECTORY + DIGESTER_RULE_FILE); // get the right kind of input stream expected for the sample batch file InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_SAMPLE_DIRECTORY + XML_SAMPLE_FILE); byte[] byteArray = IOUtils.toByteArray(inputStream); ByteArrayInputStream sampleCustomerBatchFile = new ByteArrayInputStream(byteArray); Object parsedObject = null; try { parsedObject = digester.parse(sampleCustomerBatchFile); } catch (Exception e) { throw new RuntimeException("Error parsing xml contents: " + e.getMessage(), e); } assertNotNull("Parsed object should not be null.", parsedObject); assertTrue("Parsed object class [" + parsedObject.getClass().toString() + "] should be assignable to a List.", parsedObject instanceof CustomerInvoiceWriteoffBatchVO); parsedBatchVO = (CustomerInvoiceWriteoffBatchVO) parsedObject; assertTrue("SubmittedBy PersonUserID should not be blank.", StringUtils.isNotBlank(parsedBatchVO.getSubmittedByPrincipalName())); assertTrue("SubmittedOn should not be blank.", StringUtils.isNotBlank(parsedBatchVO.getSubmittedOn())); assertNotNull("InvoiceNumbers should not be null.", parsedBatchVO.getInvoiceNumbers()); assertFalse("InvoiceNumbers should not be empty.", parsedBatchVO.getInvoiceNumbers().isEmpty()); assertTrue("InvoiceNumbers should have 3 elements in the set.", (parsedBatchVO.getInvoiceNumbers().size() == 3)); return; }
Example 7
Source File: StatsManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
private PrefsData parseSitePrefs(InputStream input) throws Exception{ Digester digester = new Digester(); digester.setValidating(false); digester = DigesterUtil.configurePrefsDigester(digester); return (PrefsData) digester.parse( input ); }
Example 8
Source File: StatisticsParser.java From iaf with Apache License 2.0 | 5 votes |
public void digestStatistics(Reader reader, String sysid) throws ConfigurationException { Reader fileReader = new EncapsulatingReader(reader, "<"+ROOT_ELEM_NAME+">", "</"+ROOT_ELEM_NAME+">", false); Digester digester = new Digester(); digester.setUseContextClassLoader(true); // push config on the stack digester.push(this); try { // String prefix="/"+ROOT_ELEM_NAME+"/"; String prefix="*/"; digester.addSetProperties(prefix+"statisticsCollection"); // timestamp info digester.addSetProperties(prefix+"statisticsCollection/statgroup"); // instance info digester.addObjectCreate (prefix+"statisticsCollection/statgroup/statgroup",SummaryRecord.class); // adapterinfo digester.addSetProperties(prefix+"statisticsCollection/statgroup/statgroup"); digester.addSetNext (prefix+"statisticsCollection/statgroup/statgroup","registerRecord"); digester.addObjectCreate (prefix+"statisticsCollection/statgroup/statgroup/stat/interval/item",Item.class); // adapterinfo digester.addSetProperties(prefix+"statisticsCollection/statgroup/statgroup/stat/interval/item"); digester.addSetNext (prefix+"statisticsCollection/statgroup/statgroup/stat/interval/item","registerItem"); InputSource is= new InputSource(fileReader); digester.parse(is); } catch (Exception e) { // wrap exception to be sure it gets rendered via the IbisException-renderer throw new ConfigurationException("error during parsing of file ["+sysid +"]", e); } }
Example 9
Source File: ValidatorResources.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Create a ValidatorResources object from several URL. * * @param urls An array of URL to several validation.xml * configuration files that will be read in order and merged into this object. * @throws SAXException if the validation XML files are not valid or well * formed. * @throws IOException if an I/O error occurs processing the XML files * @since Validator 1.3.1 */ public ValidatorResources(URL[] urls) throws IOException, SAXException { super(); Digester digester = initDigester(); for (int i = 0; i < urls.length; i++) { digester.push(this); digester.parse(urls[i]); } this.process(); }
Example 10
Source File: StemmerFactory.java From bluima with Apache License 2.0 | 5 votes |
private StemmerFactory() { initParams = new Properties(); try { Digester digester = new Digester(); digester.push(this); digester.addCallMethod("jsre-config/stemmer-list/stemmer", "addStemmer", 2); digester.addCallParam( "jsre-config/stemmer-list/stemmer/stemmer-name", 0); digester.addCallParam( "jsre-config/stemmer-list/stemmer/stemmer-class", 1); String configFile = System.getProperty("config.file"); if (configFile == null) { logger.debug("StemmerFactory uses the default config file: jsre-config.xml"); checkFileExists(JSRE_HOME + RESOURCES_PATH + "jsre-config.xml"); digester.parse(JSRE_HOME + RESOURCES_PATH + "jsre-config.xml"); } else { logger.debug("StemmerFactory uses the config file: " + configFile); digester.parse(configFile); } } catch (Exception e) { logger.error("", e); } }
Example 11
Source File: DirectoryScanningAdapterServiceImpl.java From iaf with Apache License 2.0 | 5 votes |
synchronized Map<String, IAdapter> read(URL url) throws IOException, SAXException, InterruptedException { try { AdapterService catcher = new AdapterServiceImpl(); Configuration configuration = new Configuration(catcher); ConfigurationDigester configurationDigester = new ConfigurationDigester(); Digester digester = configurationDigester.getDigester(configuration); digester.push(catcher); digester.parse(url.openStream()); // Does'nt work. I probably don't know how it is supposed to work. return catcher.getAdapters(); } catch (Throwable t) { LOG.error("For " + url + ": " + t.getMessage(), t); return null; } }
Example 12
Source File: DigesterLoader.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Given the digester rules XML file, a class loader, and an input stream, * this method parses the input into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param input InputStream over the XML file to parse into Java objects * @return an Object which is the root of the network of Java objects * created by digesting fileURL */ public static Object load(URL digesterRules, ClassLoader classLoader, InputStream input) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); try { return digester.parse(input); } catch (XmlLoadException ex) { // This is a runtime exception that can be thrown by // FromXmlRuleSet#addRuleInstances, which is called by the Digester // before it parses the file. throw new DigesterLoadingException(ex.getMessage(), ex); } }
Example 13
Source File: DigesterUtil.java From sakai with Educational Community License v2.0 | 5 votes |
public static List<ToolInfo> parseToolEventsDefinition(InputStream input) throws Exception{ Digester digester = new Digester(); digester.setValidating(false); digester = configureToolEventsDefDigester("", digester); // eventParserTip tag EventParserTipFactoryImpl eventParserTipFactoryImpl = new EventParserTipFactoryImpl(); digester.addFactoryCreate("toolEventsDef/tool/eventParserTip", eventParserTipFactoryImpl); digester.addSetNestedProperties("toolEventsDef/tool/eventParserTip"); digester.addSetNext("toolEventsDef/tool/eventParserTip", "addEventParserTip" ); return (List<ToolInfo>) digester.parse( input ); }
Example 14
Source File: ClientCertificateDigester.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * @param rdr to client certificate * @return a ClientCertificate * @throws IOException thrown if there is a problem reading the certificate. * @throws SAXException thrown if there is a problem reading the certificate. */ public static ClientCertificate buildCertificate(Reader rdr) throws IOException, SAXException { Digester digester = new Digester(); configureDigester(digester); return (ClientCertificate)digester.parse(rdr); }
Example 15
Source File: ClientCertificateDigester.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Creates a ClientCertificate from the given inputstream. * @param is to client certificate * @return a ClientCertificate * @throws IOException thrown if there is a problem reading the certificate. * @throws SAXException thrown if there is a problem reading the certificate. */ public static ClientCertificate buildCertificate(InputStream is) throws IOException, SAXException { Digester digester = new Digester(); configureDigester(digester); return (ClientCertificate)digester.parse(is); }
Example 16
Source File: NavDigester.java From spacewalk with GNU General Public License v2.0 | 4 votes |
/** * buildTree, method to take a url and parse the contents * into a NavTree * @param url the file to parse * @return NavTree the tree represented by the file * @throws Exception if something breaks. XXX: fix to be tighter */ public static NavTree buildTree(URL url) throws Exception { if (url == null) { throw new IllegalArgumentException("URL is null, your definition tag " + "probably points to a non existing file."); } Digester digester = new Digester(); digester.setValidating(false); digester.addObjectCreate("rhn-navi-tree", NavTree.class); digester.addSetProperties("rhn-navi-tree"); digester.addSetProperties("rhn-navi-tree", "acl_mixins", "aclMixins"); digester.addObjectCreate("*/rhn-tab", NavNode.class); digester.addSetProperties("*/rhn-tab", "active-image", "activeImage"); digester.addSetProperties("*/rhn-tab", "inactive-image", "inactiveImage"); digester.addSetProperties("*/rhn-tab", "target", "target"); digester.addCallMethod("*/rhn-tab", "addPrimaryURL", 1); digester.addCallParam("*/rhn-tab", 0, "url"); digester.addCallMethod("*/rhn-tab/rhn-tab-url", "addURL", 0); digester.addCallMethod("*/rhn-tab/rhn-tab-directory", "addDirectory", 0); digester.addSetNext("*/rhn-tab", "addNode"); return (NavTree)digester.parse(url.openStream()); }
Example 17
Source File: ContextMappingFactory.java From bluima with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private ContextMappingFactory() { // defaultParameters = new Properties(); try { Digester digester = new Digester(); digester.setValidating(false); digester.addObjectCreate("jsre-config/mapping-list", ArrayList.class); digester.addObjectCreate("jsre-config/mapping-list/mapping", MappingParameters.class); digester.addBeanPropertySetter( "jsre-config/mapping-list/mapping/mapping-name", "name"); digester.addBeanPropertySetter( "jsre-config/mapping-list/mapping/mapping-class", "className"); digester.addCallMethod( "jsre-config/mapping-list/mapping/init-param", "setParameters", 2); digester.addCallParam( "jsre-config/mapping-list/mapping/init-param/param-name", 0); digester.addCallParam( "jsre-config/mapping-list/mapping/init-param/param-value", 1); digester.addSetNext("jsre-config/mapping-list/mapping", "add"); String configFile = System.getProperty("config.file"); if (configFile == null) { LOG.debug("ContextMappingFactory uses the default config file: jsre-config.xml"); checkFileExists(JSRE_HOME + RESOURCES_PATH + "jsre-config.xml"); mappingList = (List<MappingParameters>) digester .parse(new File(JSRE_HOME + RESOURCES_PATH + "jsre-config.xml")); } else { LOG.debug("ContextMappingFactory uses the config file: " + configFile); mappingList = (List<MappingParameters>) digester .parse(new File(configFile)); } LOG.debug("mapping-list size: " + mappingList.size()); for (MappingParameters mp : mappingList) LOG.debug("{}", mp); } catch (Exception e) { LOG.error("woops", e); } }
Example 18
Source File: ConfigurationDigester.java From iaf with Apache License 2.0 | 4 votes |
public void digestConfiguration(ClassLoader classLoader, Configuration configuration, boolean configLogAppend) throws ConfigurationException { String configurationFile = ConfigurationUtils.getConfigurationFile(classLoader, configuration.getName()); Digester digester = null; try { digester = getDigester(configuration); URL digesterRulesURL = ClassUtils.getResourceURL(classLoader, getDigesterRules()); if (digesterRulesURL == null) { throw new ConfigurationException("Digester rules file not found: " + getDigesterRules()); } Resource configurationResource = Resource.getResource(classLoader, configurationFile); if (configurationResource == null) { throw new ConfigurationException("Configuration file not found: " + configurationFile); } if (log.isDebugEnabled()) log.debug("digesting configuration ["+configuration.getName()+"] configurationFile ["+configurationFile+"] configLogAppend ["+configLogAppend+"]"); String original = XmlUtils.identityTransform(configurationResource); fillConfigWarnDefaultValueExceptions(XmlUtils.stringToSource(original)); // must use 'original', cannot use configurationResource, because EntityResolver will not be properly set configuration.setOriginalConfiguration(original); List<String> propsToHide = new ArrayList<String>(); String propertiesHideString = AppConstants.getInstance(Thread.currentThread().getContextClassLoader()).getString("properties.hide", null); if (propertiesHideString != null) { propsToHide.addAll(Arrays.asList(propertiesHideString.split("[,\\s]+"))); } String loaded = StringResolver.substVars(original, AppConstants.getInstance(Thread.currentThread().getContextClassLoader())); String loadedHide = StringResolver.substVars(original, AppConstants.getInstance(Thread.currentThread().getContextClassLoader()), null, propsToHide); loaded = ConfigurationUtils.getCanonicalizedConfiguration(configuration, loaded); loadedHide = ConfigurationUtils.getCanonicalizedConfiguration(configuration, loadedHide); loaded = ConfigurationUtils.getActivatedConfiguration(configuration, loaded); loadedHide = ConfigurationUtils.getActivatedConfiguration(configuration, loadedHide); if (ConfigurationUtils.isConfigurationStubbed(classLoader)) { loaded = ConfigurationUtils.getStubbedConfiguration(configuration, loaded); loadedHide = ConfigurationUtils.getStubbedConfiguration(configuration, loadedHide); } configuration.setLoadedConfiguration(loadedHide); saveConfig(loadedHide, configLogAppend); digester.parse(new StringReader(loaded)); } catch (Throwable t) { // wrap exception to be sure it gets rendered via the IbisException-renderer String currentElementName = null; if (digester != null ) { currentElementName = digester.getCurrentElementName(); } ConfigurationException e = new ConfigurationException("error during unmarshalling configuration from file [" + configurationFile + "] with digester-rules-file ["+getDigesterRules()+"] in element ["+currentElementName+"]"+(StringUtils.isEmpty(lastResolvedEntity)?"":" last resolved entity ["+lastResolvedEntity+"]"), t); throw e; } if (MonitorManager.getInstance().isEnabled()) { MonitorManager.getInstance().configure(configuration); } }
Example 19
Source File: CustomerLoadDigesterTest.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
public void NORUN_testCustomerLoadDigesterRules() throws Exception { Digester digester = buildDigester(SCHEMA_DIRECTORY + SCHEMA_FILE, DIGESTER_RULE_DIRECTORY + DIGESTER_RULE_FILE); // get the right kind of input stream expected for the sample batch file InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_SAMPLE_DIRECTORY + XML_SAMPLE_FILE); byte[] byteArray = IOUtils.toByteArray(inputStream); ByteArrayInputStream sampleCustomerBatchFile = new ByteArrayInputStream(byteArray); Object parsedCustomers = null; try { parsedCustomers = digester.parse(sampleCustomerBatchFile); } catch (Exception e) { throw new ParseException("Error parsing xml contents: " + e.getMessage(), e); } assertNotNull("Parsed object should not be null.", parsedCustomers); assertTrue("Parsed object class [" + parsedCustomers.getClass().toString() + "] should be assignable to a List.", parsedCustomers instanceof List); List parsedObjects = (List) parsedCustomers; assertTrue("Parsed object List should contain at least one item.", (parsedObjects.size() >= 1)); parsedCustomerList = new ArrayList<CustomerDigesterVO>(); // look at every item, make sure its of type Customer Integer i = 0; for (Iterator iterator = parsedObjects.iterator(); iterator.hasNext();) { Object item = (Object) iterator.next(); assertNotNull("List item [" + i.toString() + "] should not be null.", item); assertTrue("List item [" + i.toString() + "] class [" + item.getClass().toString() + "] should be a Customer object.", item.getClass().equals(CustomerDigesterVO.class)); parsedCustomerList.add((CustomerDigesterVO) item); i++; } return; }
Example 20
Source File: LdapSender.java From iaf with Apache License 2.0 | 3 votes |
/** * Digests the input message and creates a <code>BasicAttributes</code> object, containing <code>BasicAttribute</code> objects, * which represent the attributes of the specified entry. * * <pre> * BasicAttributes implements Attributes * contains * BasicAttribute implements Attribute * </pre> * * @see Attributes * @see BasicAttributes * @see Attribute * @see BasicAttribute */ private Attributes parseAttributesFromMessage(Message message) throws SenderException { Digester digester = new Digester(); digester.addObjectCreate("*/attributes",BasicAttributes.class); digester.addFactoryCreate("*/attributes/attribute",BasicAttributeFactory.class); digester.addSetNext("*/attributes/attribute","put"); digester.addCallMethod("*/attributes/attribute/value","add",0); try { return (Attributes) digester.parse(message.asReader()); } catch (Exception e) { throw new SenderException("[" + this.getClass().getName() + "] exception in digesting", e); } }