Java Code Examples for org.apache.commons.digester.Digester#push()
The following examples show how to use
org.apache.commons.digester.Digester#push() .
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: ManifestFactory.java From uyuni with GNU General Public License v2.0 | 6 votes |
private void parseURL(URL u) { Digester d = new Digester(); d.setValidating(false); d.push(this); d.addObjectCreate("factory/template", HashMap.class); d.addRule("factory/template", new AttributeCopyRule()); d.addSetNext("factory/template", "addFactoryTemplate"); try { d.parse(u.openStream()); } catch (Exception e) { throw new ManifestFactoryParseException("Unable to parse " + builder.getManifestFilename(), e); } }
Example 2
Source File: DigesterLoader.java From lams with GNU General Public License v2.0 | 6 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 * @param rootObject an Object to push onto the digester's stack, prior * to parsing the input * @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, Object rootObject) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); digester.push(rootObject); 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 3
Source File: DigesterLoader.java From lams with GNU General Public License v2.0 | 6 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 Reader over the XML file to parse into Java objects * @param rootObject an Object to push onto the digester's stack, prior * to parsing the input * @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, Reader input, Object rootObject) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); digester.push(rootObject); 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 4
Source File: DigesterRuleParser.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Creates another DigesterRuleParser, and uses it to extract the rules * out of the give XML file. The contents of the current pattern stack * will be prepended to all of the pattern strings parsed from the file. */ private void includeXMLRules(String fileName) throws IOException, SAXException, CircularIncludeException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = DigesterRuleParser.this.getClass().getClassLoader(); } URL fileURL = cl.getResource(fileName); if (fileURL == null) { throw new FileNotFoundException("File \"" + fileName + "\" not found."); } fileName = fileURL.toExternalForm(); if (includedFiles.add(fileName) == false) { // circular include detected throw new CircularIncludeException(fileName); } // parse the included xml file DigesterRuleParser includedSet = new DigesterRuleParser(targetDigester, patternStack, includedFiles); includedSet.setDigesterRulesDTD(getDigesterRulesDTD()); Digester digester = new Digester(); digester.addRuleSet(includedSet); digester.push(DigesterRuleParser.this); digester.parse(fileName); includedFiles.remove(fileName); }
Example 5
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 6
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 7
Source File: ManifestFactory.java From spacewalk with GNU General Public License v2.0 | 6 votes |
private void parseURL(URL u) { Digester d = new Digester(); d.setValidating(false); d.push(this); d.addObjectCreate("factory/template", HashMap.class); d.addRule("factory/template", new AttributeCopyRule()); d.addSetNext("factory/template", "addFactoryTemplate"); try { d.parse(u.openStream()); } catch (Exception e) { throw new ManifestFactoryParseException("Unable to parse " + builder.getManifestFilename(), e); } }
Example 8
Source File: ValidatorResources.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Create a ValidatorResources object from several uris * * @param uris An array of uris 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.2 */ public ValidatorResources(String[] uris) throws IOException, SAXException { super(); Digester digester = initDigester(); for (int i = 0; i < uris.length; i++) { digester.push(this); digester.parse(uris[i]); } this.process(); }
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: 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 13
Source File: ConnectionDescriptorManager.java From jsqsh with Apache License 2.0 | 4 votes |
private boolean load(InputStream in, String filename) { String path; Digester digester = new Digester(); digester.setValidating(false); path = "connections/connection"; digester.addObjectCreate(path, ConnectionDescriptor.class.getName()); digester.addSetNext(path, "put", ConnectionDescriptor.class.getName()); digester.addSetProperties(path); path = "connections/connection/username"; digester.addCallMethod(path, "setUsername", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); path = "connections/connection/password"; digester.addCallMethod(path, "setPassword", 2, new Class[] { java.lang.String.class, java.lang.Boolean.class }); digester.addCallParam(path, 0); digester.addCallParam(path, 1, "encrypted"); path = "connections/connection/catalog"; digester.addCallMethod(path, "setCatalog", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); path = "connections/connection/jdbc-url"; digester.addCallMethod(path, "setUrl", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); digester.addCallMethod(path, "setJdbcClass", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "class"); path = "connections/connection/properties/property"; digester.addCallMethod(path, "setProperty", 2, new Class[] { java.lang.String.class, java.lang.String.class }); digester.addCallParam(path, 0, "name"); digester.addCallParam(path, 1); path = "connections/connection/url-variables/variable"; digester.addCallMethod(path, "setUrlVariable", 2, new Class[] { java.lang.String.class, java.lang.String.class }); digester.addCallParam(path, 0, "name"); digester.addCallParam(path, 1); digester.push(this); try { digester.parse(in); } catch (Exception e) { LOG.severe("Failed to load connection descriptor from '" + filename + ": " + e.getMessage()); return false; } return true; }
Example 14
Source File: BufferManager.java From jsqsh with Apache License 2.0 | 4 votes |
/** * Attempts to load a buffer history. * @param file The file to read. */ public void load(File file) { /* * Clear out the current history. */ clear(); /* * Historically, the history.xml file was stored newest entry to * oldest yet the BufferManager stores them internally oldest to * newest. To deal with this, we read our file into a list, then * we'll go back and put them into the buffer manager in the * proper order. */ List<Buffer> bufferList = new ArrayList<Buffer>(); String path; Digester digester = new Digester(); digester.setValidating(false); path = "Buffers/Buffer"; digester.addObjectCreate(path, "org.sqsh.Buffer"); digester.addSetNext(path, "add", "java.lang.Object"); digester.addCallMethod(path, "add", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); digester.push(bufferList); try { digester.parse(file); } catch (Exception e) { System.err.println("Failed to load buffer history file '" + file.toString() + "': " + e.getMessage()); } /* * Now, blast back through our bufferList and put them into * the manager in the proper order (oldest to newest). */ for (int i = bufferList.size() - 1; i >= 0; --i) { addBuffer(bufferList.get(i)); } /* * Create an empty entry for "current". */ newBuffer(); }
Example 15
Source File: VariableManager.java From jsqsh with Apache License 2.0 | 4 votes |
/** * Initializes the variable manager with variables as described by * the XML file pointed to by URL. */ public void load(ClassLoader loader, String location, InputStream in) { String path; Digester digester = new Digester(); digester.setValidating(false); if (loader != null) { digester.setClassLoader(loader); } path = "Variables/String"; digester.addObjectCreate(path, "org.sqsh.variables.StringVariable"); digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable"); digester.addCallMethod(path, "setName", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "name"); digester.addCallMethod(path, "setValue", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "value"); path = "Variables/Integer"; digester.addObjectCreate(path, "org.sqsh.variables.IntegerVariable"); digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable"); digester.addCallMethod(path, "setName", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "name"); digester.addCallMethod(path, "setMinValue", 1, new Class[] { java.lang.Integer.class }); digester.addCallParam(path, 0, "min"); digester.addCallMethod(path, "setMaxValue", 1, new Class[] { java.lang.Integer.class }); digester.addCallParam(path, 0, "max"); digester.addCallMethod(path, "setValue", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); path = "Variables/Dynamic"; digester.addObjectCreate(path, "org.sqsh.Variable", "class"); digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable"); digester.addCallMethod(path, "setName", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "name"); digester.addCallMethod(path, "setValue", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "value"); path = "Variables/Property"; digester.addObjectCreate(path, "org.sqsh.variables.PropertyVariable"); digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable"); digester.addCallMethod(path, "setName", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "name"); digester.addCallMethod(path, "setBean", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "bean"); digester.addCallMethod(path, "setProperty", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0, "property"); digester.addCallMethod(path, "setSettable", 1, new Class[] { java.lang.Boolean.class }); digester.addCallParam(path, 0, "settable"); digester.addCallMethod(path, "setQuiet", 1, new Class[] { java.lang.Boolean.class }); digester.addCallParam(path, 0, "quiet"); path = "*/Description"; digester.addCallMethod(path, "setDescription", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); path = "*/HelpLocation"; digester.addCallMethod(path, "setHelpLocation", 1, new Class[] { java.lang.String.class }); digester.addCallParam(path, 0); digester.push(this); try { digester.parse(in); } catch (Exception e) { LOG.severe("Failed to parse variable definition file '" + location + "': " + e.getMessage()); } }