Example usage for org.apache.commons.digester.xmlrules DigesterLoader createDigester

List of usage examples for org.apache.commons.digester.xmlrules DigesterLoader createDigester

Introduction

In this page you can find the example usage for org.apache.commons.digester.xmlrules DigesterLoader createDigester.

Prototype

public static Digester createDigester(URL rulesXml) 

Source Link

Document

Creates a new digester and initializes it from the specified XML file

Usage

From source file:it.jnrpe.plugins.factory.CPluginFactory.java

private void parsePluginXmlFile(InputStream in) throws IOException, SAXException {
    CStreamManager streamMgr = new CStreamManager();

    m_Logger.trace("PARSING FILE plugin.xml IN JAR FILE.");

    Digester digester = DigesterLoader.createDigester(new InputSource(
            streamMgr.handle(this.getClass().getClassLoader().getResourceAsStream("plugin-digester.xml"))));
    CPluginFactoryConfiguration oConf = (CPluginFactoryConfiguration) digester.parse(in);

    List vPluginDefs = oConf.getPluginDefinitions();

    //for (CPluginDefinition pluginDef : vPluginDefs)
    for (Iterator iter = vPluginDefs.iterator(); iter.hasNext();) {
        CPluginDefinition pluginDef = (CPluginDefinition) iter.next();
        m_Logger.debug(//  w  ww.java2s . c  o  m
                "FOUND PLUGIN " + pluginDef.getName() + " IMPLEMENTED BY CLASS " + pluginDef.getPluginClass());
        m_mPlugins.put(pluginDef.getName(), new CPluginData(pluginDef.getName(), pluginDef.getDescription(),
                pluginDef.getPluginClass(), pluginDef.getOptions()));
    }
}

From source file:it.jnrpe.server.CJNRPEServer.java

private static CommandLine parseCommandLine(String[] vsArgs) {
    Digester d = DigesterLoader.createDigester(new InputSource(
            CJNRPEServer.class.getResourceAsStream("/it/jnrpe/server/command-line-digester.xml")));

    try {//from  ww w  .j  a v  a 2  s  .c o  m
        COptions opts = (COptions) d
                .parse(CJNRPEServer.class.getResourceAsStream("/it/jnrpe/server/jnrpe-command-line.xml"));
        m_Options = opts.toOptions();
        CommandLineParser clp = new PosixParser();
        return clp.parse(m_Options, vsArgs);
    } catch (IOException e) {
        // Should never happen...         
    } catch (SAXException e) {
        // Should never happen...         

    } catch (ParseException e) {
        printUsage();
    }
    return null;
}

From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugIn.java

/**
 * Zbg????B/*from w w  w  . j a v a 2s  .c o m*/
 * 
 * tH?[Zbg`t@C(reset.xml)?A
 * tH?[Zbg?[`t@C(reset-rules.xml)p?A
 * ??
 * {@link 
 *   jp.terasoluna.fw.web.struts.reset.ResetterResources}
 * ??B
 *
 * @param servlet vOCNT?[ubg?B
 * @param config W?[RtBO
 * @exception ServletException \?[Xt@C
 * ?O
 */
protected void initResources(ActionServlet servlet, ModuleConfig config) throws ServletException {

    if (this.resourcesPath == null || "".equals(this.resourcesPath)) {
        log.error("resources file location is not specified");
        throw new ServletException("resources file location is not specified");
    }
    StringTokenizer st = new StringTokenizer(resourcesPath, ",");
    List<String> pathList = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String path = st.nextToken();
        path = path.trim();
        if (log.isDebugEnabled()) {
            log.debug("reset file=" + path);
        }
        pathList.add(path);
    }
    if (digester == null) {
        if (digesterRules == null) {
            // ?[t@C??AftHg?[t@C
            // ??B
            digesterRules = DIGESTER_RULES_PATH;
        }
        // Digester??
        try {
            digester = DigesterLoader.createDigester(servlet.getServletContext().getResource(digesterRules));
            digester.setValidating(true);
        } catch (MalformedURLException e) {
            log.error("", e);
            throw new ServletException(e);
        } catch (XmlLoadException e) {
            log.error("", e);
            throw new ServletException(e);
        }
    }
    ResetterResources resetterResources = new ResetterResources();
    try {
        for (int i = 0; i < pathList.size(); i++) {
            digester.push(resetterResources);
            URL url = this.getClass().getResource(getDtdUrl());
            if (url != null) {
                digester.register(getPublicIdentifier(), url.toString());
            }
            digester.parse(servlet.getServletContext().getResourceAsStream(pathList.get(i)));
        }
    } catch (IOException e) {
        log.error("", e);
        throw new ServletException(e);
    } catch (SAXException e) {
        log.error("", e);
        throw new ServletException(e);
    }
    // ResetterResourcesT?[ubgReLXg
    servlet.getServletContext().setAttribute(ResetterResources.RESETTER_RESOURCES_KEY + config.getPrefix(),
            resetterResources);
}

From source file:jp.terasoluna.fw.web.struts.plugins.BLogicIOPlugIn.java

/**
 * rWlX?WbN?o?????B/*  w  w w .  j a va 2  s  . c om*/
 *
 * <p>blogic-io.xml?Ablogic-io-rules.xml
 * p?A??Bean??B</p>
 *
 * <p>XML?t@C`s??AIOO??A
 * ServletExceptionbvX??[?B</p>
 *
 * @exception ServletException rWlX?WbN?o????
 * ?O
 */
private void initResources() throws ServletException {
    if (resources == null || "".equals(resources)) {
        if (log.isDebugEnabled()) {
            log.debug("resources file location is not specified");
        }
        return;
    }
    StringTokenizer st = new StringTokenizer(resources, ",");
    List<String> pathList = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String path = st.nextToken();
        path = path.trim();
        if (log.isDebugEnabled()) {
            log.debug("blogic io file=" + path);
        }
        pathList.add(path);
    }
    try {
        if (digester == null) {
            if (digesterRules == null) {
                // ?[t@C??AftHg?[t@C
                // gp?B
                digesterRules = DIGESTER_RULES_PATH;
            }
            digester = DigesterLoader.createDigester(servlet.getServletContext().getResource(digesterRules));
            digester.setValidating(true);
        }
        blogicResources = new BLogicResources();
        for (int i = 0; i < pathList.size(); i++) {
            digester.push(blogicResources);
            URL url = this.getClass().getResource(getDtdUrl());
            if (url != null) {
                digester.register(getPublicIdentifier(), url.toString());
            }
            digester.parse(servlet.getServletContext().getResourceAsStream(pathList.get(i)));
        }
    } catch (MalformedURLException e) {
        log.error("", e);
        throw new ServletException(e);
    } catch (IOException e) {
        log.error("", e);
        throw new ServletException(e);
    } catch (SAXException e) {
        log.error("", e);
        throw new ServletException(e);
    } catch (XmlLoadException e) {
        log.error("", e);
        throw new ServletException(e);
    }

}

From source file:com.npower.common.plugins.DaemonControllerPlugIn.java

/**
 * <p>/*from  w w  w . j  a v  a  2 s . c o m*/
 * Instantiate a Digester from an XML input stream using the Commons
 * <code>DigesterLoader</code>.
 * </p>
 * 
 * @param path
 *            the path to the digester rules XML to be found using
 *            <code>source</code>
 * @param source
 *            a string indicating the lookup method to be used with
 *            <code>path</code>
 * @return a configured Digester
 * @throws FileNotFoundException
 * @throws MalformedURLException
 * @see #getConfigURL(String, String)
 */
protected Digester digesterFromXml(String path, String source) throws IOException {

    URL configURL = this.getConfigURL(path, source);
    if (configURL == null) {
        throw new NullPointerException("No resource '" + path + "' found in '" + source + "'");
    }
    return DigesterLoader.createDigester(configURL);
}

From source file:fr.paris.lutece.plugins.document.modules.metadatadublincore.business.DublinCoreMetadata.java

/**
 * Load dublin core metadata from an XML stream
 * @param strXmlData The XML content to get the attributes from
 *///from ww  w  .  j a v a 2  s . c  o  m
public void load(String strXmlData) {
    // Configure Digester from XML ruleset
    URL rules = getClass().getResource(FILE_RULES);
    Digester digester = DigesterLoader.createDigester(rules);

    // Push empty List onto Digester's Stack
    digester.push(this);

    try {
        if (strXmlData != null) {
            StringReader sr = new StringReader(strXmlData);
            digester.parse(sr);
        }
    } catch (FileNotFoundException e) {
        AppLogService.error(e.getMessage(), e);
    } catch (SAXException e) {
        AppLogService.error(e.getMessage(), e);
    } catch (IOException e) {
        AppLogService.error(e.getMessage(), e);
    }
}

From source file:nl.nn.adapterframework.pipes.DigesterPipe.java

@Override
public void configure() throws ConfigurationException {
    super.configure();

    try {//from  www . java 2 s  .  c  om
        rulesURL = ClassUtils.getResourceURL(classLoader, digesterRulesFile);
        DigesterLoader.createDigester(rulesURL); // load rules to check if they can be loaded when needed
    } catch (Exception e) {
        throw new ConfigurationException(
                getLogPrefix(null) + "Digester rules file [" + digesterRulesFile + "] not found", e);
    }
    log.debug(getLogPrefix(null) + "End of configuration");
}

From source file:nl.nn.adapterframework.pipes.DigesterPipe.java

@Override
public PipeRunResult doPipe(Object input, 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 {//from ww w.j av a  2 s.  com
        ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(input.toString().getBytes());

        return new PipeRunResult(getForward(), digester.parse(xmlInputStream));

    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "exception in digesting", e);
    }
}

From source file:org.ajax4jsf.bean.tree.TreeBuilder.java

public static void main(String[] args) {
    URL rulesUrl = TreeBuilder.class.getResource("/digester-rules.xml");
    Digester digester = DigesterLoader.createDigester(rulesUrl);
    AudioLibrary library = new AudioLibrary();
    digester.push(library);//from  w ww  . jav a 2  s  . c  om

    try {
        digester.parse(TreeBuilder.class.getResourceAsStream("/audio-library.xml"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.ajax4jsf.bean.tree.TreeTestBean.java

public synchronized TreeNode<Object> getRichTreeNode() {
    if (null == richRootNode) {
        Digester digester = DigesterLoader.createDigester(getClass().getResource("/rich-digester-rules.xml"));
        AudioLibrary library = new AudioLibrary();
        digester.push(library);//  www .  j  av  a 2  s  .  c o  m
        try {
            digester.parse(getClass().getResourceAsStream("/audio-library.xml"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        richRootNode = library;
    }

    return richRootNode;
}