Example usage for org.apache.commons.digester Digester parse

List of usage examples for org.apache.commons.digester Digester parse

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester parse.

Prototype

public Object parse(URL url) throws IOException, SAXException 

Source Link

Document

Parse the content of the specified URL using this Digester.

Usage

From source file:eu.planets_project.pp.plato.services.characterisation.jhove.JHoveAdaptor.java

/**
 * Process any kind of XML String and returns a {@link JHoveTreeNode}
 * this seemingly absurd method stems from the fact that jhove might include ENCODED xml in a response,
 * so that within the xml tag we have another encoded, embedded, XML string.
 * For example, XMP info is embedded in that way.
 * (see data/testfiles-characterisation/jhove-output-with-xmpinfo.xml and sample-pdf-including-xmp.pdf)
 * So we create another xml root node, copy the encoded stuff in and send it to an XML extraction method.
 * /*from  w  w w.j  a  v  a2  s  .c  o  m*/
 * @param XMPasString
 * @param name
 * @return
 * @see #getJHoveTreeNodeFromXPathNode(Node)
 */
private JHoveTreeNode getJHoveTreeNodeFromXML(String XMPasString, String name) {
    try {
        //tested with digester: XML displayed as a jhoveTreeNode 
        XMPasString = XMPasString.substring(1, XMPasString.length() - 1);

        Digester digester = new Digester();
        digester.addRule("XMPInfo", new NodeCreateRule());

        Node rootNode = (Node) digester.parse(new StringReader("<XMPInfo>" + XMPasString + "</XMPInfo>"));

        return getJHoveTreeNodeFromXPathNode(rootNode);
    } catch (Exception e) {
        log.warn("Error in JHove identification: " + e.getMessage(), e);
        return new JHoveTreeNode("Error in Processing XMP", "leaf");
    }
}

From source file:com.agiletec.aps.system.services.baseconfig.BaseConfigManager.java

/**
 * Esegue il parsing della voce di configurazione "params" per
 * estrarre i parametri. I parametri sono caricati sul Map passato
 * come argomento. I parametri corrispondono a tag del tipo:<br>
 * &lt;Param name="nome_parametro"&gt;valore_parametro&lt;/Param&gt;<br> 
 * qualunque sia la loro posizione relativa nel testo XML.<br>
 * ATTENZIONE: non viene controllata l'univocit del nome, in caso
 * di doppioni il precedente valore perso.
 * @throws ApsSystemException In caso di errori IO e Sax
 *//*from   w  ww.j a  v  a2  s  .  c o  m*/
private void parseParams() throws ApsSystemException {
    String xml = this.getConfigItem(SystemConstants.CONFIG_ITEM_PARAMS);
    Digester dig = new Digester();
    Rule rule = new MapSupportRule("name");
    dig.addRule("*/Param", rule);
    dig.push(this._params);
    try {
        dig.parse(new StringReader(xml));
    } catch (Exception e) {
        _logger.error(
                "Error detected while parsing the \"params\" item in the \"sysconfig\" table: verify the \"sysconfig\" table",
                e);
        //ApsSystemUtils.logThrowable(e, this, "parseParams");
        throw new ApsSystemException(
                "Error detected while parsing the \"params\" item in the \"sysconfig\" table:"
                        + " verify the \"sysconfig\" table",
                e);
    }
}

From source file:com.redhat.rhn.common.util.test.AttributeCopyRuleTest.java

public void testCopy() throws Exception {
    Digester digester = new Digester();
    digester.setValidating(false);//from   www .  j  av a2 s.  c  om

    digester.addObjectCreate("dummy", DummyObject.class);
    digester.addRule("dummy", new AttributeCopyRule());

    URL url = TestUtils.findTestData("dummy-test.xml");
    DummyObject result = (DummyObject) digester.parse(url.openStream());

    Map expected = new HashMap();
    expected.put("foo", "1");
    expected.put("bar", "baz");

    Iterator i;
    i = expected.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry me = (Map.Entry) i.next();

        assertNotNull(result.getValues().get(me.getKey()));
        assertEquals(result.getValues().get(me.getKey()), me.getValue());
    }

    i = result.getValues().entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry me = (Map.Entry) i.next();

        assertNotNull(expected.get(me.getKey()));
        assertEquals(expected.get(me.getKey()), me.getValue());
    }
}

From source file:com.redhat.rhn.common.util.manifestfactory.ManifestFactory.java

private void parseURL(URL u) {
    Digester d = new Digester();
    d.setValidating(false);/* ww w .ja  v a2s .  c  om*/

    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);
    }
}

From source file:com.germinus.easyconf.DigesterLearningTest.java

private Object readConfig(Digester digester) throws IOException, SAXException {
    Object configuration;//from  w  w w  .j  ava  2  s  .  c o  m
    digester.setUseContextClassLoader(true);
    digester.setValidating(false);
    URL confFile = ClasspathUtil.locateResource(null, "test_module.xml");
    assertNotNull("Configuration file not found", confFile);
    configuration = digester.parse(confFile.openStream());
    return configuration;
}

From source file:net.jakubholy.jeeutils.jsfelcheck.beanfinder.jsf11.Jsf11FacesConfigXmlBeanFinder.java

protected void parse(Digester digester, InputStream stream, FacesConfigBean fcb) {

    InputSource source = null;/*from  w  ww. j a  va  2  s  .com*/
    try {
        source = new InputSource(stream);
        source.setByteStream(stream);
        digester.clear();
        digester.push(fcb);
        digester.parse(source);
        stream.close();
        stream = null;
    } catch (Exception e) {
        String message = "Can't parse configuration file from " + stream;
        LOG.log(Level.SEVERE, message, e);
        throw new FacesException(message, e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (Exception e) {
            } // SUPPRESS CHECKSTYLE
            stream = null;
        }
    }
}

From source file:com.npower.dm.setup.task.DMTask.java

protected List<SoftwareItem> loadSoftwareItems(String filename) throws SetupException {
    List<SoftwareItem> result = new ArrayList<SoftwareItem>();
    try {/*from   ww w .ja v a  2 s.  c o  m*/
        Digester digester = this.createSoftwareDigester();
        digester.push(result);
        digester.parse(new FileInputStream(filename));
        return result;
    } catch (Exception e) {
        throw new SetupException(e);
    }
}

From source file:com.npower.dm.setup.task.DMTask.java

protected List<SoftwareVenderItem> loadSoftwareVenderImporter(String filename) throws SetupException {
    List<SoftwareVenderItem> result = new ArrayList<SoftwareVenderItem>();
    try {//w w  w .  j a va2s .  c  om
        Digester digester = this.createSoftwareVenderDigester();
        digester.push(result);
        digester.parse(new FileInputStream(filename));
        return result;
    } catch (Exception e) {
        throw new SetupException(e);
    }
}

From source file:com.npower.cp.xmlinventory.OTAInventoryImpl.java

/**
 * Set include file/*from w ww  .  j av  a 2 s  .  c o m*/
 * @param filename 
 * @throws OTAException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
public void setInclude(String filename)
        throws OTAException, ParserConfigurationException, SAXException, IOException {
    File file = new File(this.getResourceBaseDir(), filename);
    if (!file.exists()) {
        throw new OTAException("Could not found file: " + file.getAbsolutePath());
    }
    Digester digester = this.createDigester();
    digester.push(this);
    digester.parse(file);

}

From source file:com.npower.dm.setup.task.DMTask.java

protected List<SoftwareCategoryItem> loadSoftwareCategoryItems(String filename) throws SetupException {
    List<SoftwareCategoryItem> result = new ArrayList<SoftwareCategoryItem>();
    try {//  w w  w  .  j ava 2s. c o m
        Digester digester = this.createSoftwareCategoryDigester();
        digester.push(result);
        digester.parse(new FileInputStream(filename));
        return result;
    } catch (Exception e) {
        throw new SetupException(e);
    }
}