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

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

Introduction

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

Prototype

public <T> T parse(URL url) throws IOException, SAXException 

Source Link

Document

Parse the content of the specified URL using this Digester.

Usage

From source file:com.zaradai.bloodstone.model.digester.DigesterBloodstoneLoader.java

@Override
public Bloodstone load(String sourceUri) throws ModelException {
    Bloodstone res;/*from  ww  w  . j a va2  s  .  co m*/
    InputStream inputStream = getStream(sourceUri);
    Digester digester = getDigester();

    try {
        res = digester.parse(inputStream);
    } catch (SAXException e) {
        throw new ModelException("Unable to load config file", e);
    } catch (IOException e) {
        throw new ModelException("Unable to parse config file", e);
    }
    // do validation if provided
    if (validator != null) {
        validator.validate(res);
    } else {
        LOGGER.info("Configuration not validated");
    }

    return res;
}

From source file:edu.wustl.bulkoperator.BulkOperator.java

public BulkOperator(InputSource xmlTemplate, String mappingFile) throws BulkOperationException {
    try {/*ww  w .  j a va  2 s .c  o m*/
        DigesterLoader digesterLoader = DigesterLoader.newLoader(new XmlRulesModule(mappingFile));
        Digester digester = digesterLoader.newDigester();
        this.metadata = digester.parse(xmlTemplate);
    } catch (IOException e) {
        logger.debug(e.getMessage(), e);
        throw new BulkOperationException(e.getMessage());
    } catch (SAXException e) {
        logger.debug(e.getMessage(), e);
        throw new BulkOperationException(e.getMessage());
    }
}

From source file:architecture.ee.web.navigator.XmlMenuHolder.java

public void reload() {
    menus.clear();//from   w  ww  .j a va  2  s  .com
    StringReader reader = new StringReader(content);
    Digester digester = initDigester();
    try {
        digester.parse(reader);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
}

From source file:net.revelc.code.formatter.model.ConfigReader.java

/**
 * Read from the <code>input</code> and return it's configuration settings
 * as a {@link Map}./*from   w w  w.  java 2s. c o m*/
 *
 * @param input the input
 * @return return {@link Map} with all the configurations read from the
 *         config file, or throws an exception if there's a problem reading
 *         the input, e.g.: invalid XML.
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws SAXException the SAX exception
 * @throws ConfigReadException the config read exception
 */
public Map<String, String> read(InputStream input) throws IOException, SAXException, ConfigReadException {
    Digester digester = new Digester();
    digester.addRuleSet(new RuleSet());

    Object result = digester.parse(input);
    if (result == null || !(result instanceof Profiles)) {
        throw new ConfigReadException("No profiles found in config file");
    }

    Profiles profiles = (Profiles) result;
    List<Map<String, String>> list = profiles.getProfiles();
    if (list.isEmpty()) {
        throw new ConfigReadException("No profile in config file of kind: " + Profiles.PROFILE_KIND);
    }

    return list.get(0);
}

From source file:com.relativitas.maven.plugins.formatter.ConfigReader.java

/**
 * Read from the <code>input</code> and return it's configuration settings
 * as a {@link Map}./*from  ww w .  j a  v  a2 s.  c  o  m*/
 *
 * @param input the input
 * @return return {@link Map} with all the configurations read from the
 *         config file, or throws an exception if there's a problem reading
 *         the input, e.g.: invalid XML.
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws SAXException the SAX exception
 * @throws ConfigReadException the config read exception
 */
public Map<String, String> read(InputStream input) throws IOException, SAXException, ConfigReadException {
    Digester digester = new Digester();
    digester.addRuleSet(new RuleSet());

    Object result = digester.parse(input);
    if (result == null && !(result instanceof Profiles)) {
        throw new ConfigReadException("No profiles found in config file");
    }

    Profiles profiles = (Profiles) result;
    List<Map<String, String>> list = profiles.getProfiles();
    if (list.size() == 0) {
        throw new ConfigReadException("No profile in config file of kind: " + Profiles.PROFILE_KIND);
    }

    return (Map<String, String>) list.get(0);
}

From source file:net.sf.mcf2pdf.mcfelements.FotobookBuilder.java

/**
 * Reads the given MCF input file and creates an MCF DOM reflecting the
 * relevant parts of the content./*from   w  ww. ja  v  a 2s .  co  m*/
 *  
 * @param file MCF input file.
 * 
 * @return A Fotobook object reflecting the contents of the file.
 * 
 * @throws IOException If any I/O related problem occurs reading the file.
 * @throws SAXException If any XML related problem occurs reading the file.
 */
public McfFotobook readFotobook(File file) throws IOException, SAXException {
    Digester digester = new Digester();
    configurator.configureDigester(digester, file);
    McfFotobook fb = digester.parse(file);

    // try to set file on it
    try {
        BeanUtils.setProperty(fb, "file", file);
    } catch (Exception e) {
        // ignore - digester configurator will (hopefully) do it anyhow
    }

    // if this is thrown, your McfFotobook implementation has no setFile(),
    // and your configurator has also not set it. 
    if (!file.equals(fb.getFile()))
        throw new IllegalStateException(
                "File could not be set on photobook. Please check used DigesterConfigurator.");

    return fb;
}

From source file:com.web.services.ExecutorServicesConstruct.java

/**
 * This method removes the configuration of the War file
 * @param servicesMap/*w w  w . ja va 2s  . c o  m*/
 * @param exectorServicesXml
 * @param customClassLoader
 * @throws Exception
 */
public void removeExecutorServices(Hashtable servicesMap, File exectorServicesXml,
        WebClassLoader customClassLoader) throws Exception {
    DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {
            // TODO Auto-generated method stub
            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/executorservices-config.xml")));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    Digester serverdigester = serverdigesterLoader.newDigester();
    ExecutorServices executorServices = (ExecutorServices) serverdigester
            .parse(new InputSource(new FileInputStream(exectorServicesXml)));
    CopyOnWriteArrayList<ExecutorService> executorServicesList = executorServices.getExecutorServices();
    ExecutorServiceAnnot executorServiceAnnot;
    for (ExecutorService executorService : executorServicesList) {
        Class executorServiceClass = customClassLoader
                .loadClass(executorService.getExecutorserviceclass().toString());
        //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
        //System.out.println();
        Method[] methods = executorServiceClass.getDeclaredMethods();
        for (Method method : methods) {
            Annotation[] annotations = method.getDeclaredAnnotations();
            for (Annotation annotation : annotations) {
                if (annotation instanceof ExecutorServiceAnnot) {
                    executorServiceAnnot = (ExecutorServiceAnnot) annotation;
                    //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception();
                    servicesMap.remove(executorServiceAnnot.servicename());
                }
            }
        }
    }
}

From source file:com.app.services.ExecutorServicesConstruct.java

/**
 * This method removes the configuration of the War file
 * @param servicesMap//w  w w .ja v  a  2  s . co m
 * @param exectorServicesXml
 * @param customClassLoader
 * @throws Exception
 */
public void removeExecutorServices(Hashtable servicesMap, File exectorServicesXml,
        WebClassLoader customClassLoader) throws Exception {
    DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {
            // TODO Auto-generated method stub
            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/executorservices-config.xml")));
            } catch (Exception e) {
                log.error("Could not able to load xml rules ./config/executorservices-config.xml", e);
                // TODO Auto-generated catch block
                //e.printStackTrace();
            }

        }
    });
    Digester serverdigester = serverdigesterLoader.newDigester();
    ExecutorServices executorServices = (ExecutorServices) serverdigester
            .parse(new InputSource(new FileInputStream(exectorServicesXml)));
    CopyOnWriteArrayList<ExecutorService> executorServicesList = executorServices.getExecutorServices();
    ExecutorServiceAnnot executorServiceAnnot;
    for (ExecutorService executorService : executorServicesList) {
        Class executorServiceClass = customClassLoader
                .loadClass(executorService.getExecutorserviceclass().toString());
        //log.info("executor class in ExecutorServicesConstruct"+executorServiceClass);
        //log.info();
        Method[] methods = executorServiceClass.getDeclaredMethods();
        for (Method method : methods) {
            Annotation[] annotations = method.getDeclaredAnnotations();
            for (Annotation annotation : annotations) {
                if (annotation instanceof ExecutorServiceAnnot) {
                    executorServiceAnnot = (ExecutorServiceAnnot) annotation;
                    //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception();
                    servicesMap.remove(executorServiceAnnot.servicename());
                }
            }
        }
    }
}

From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorParser.java

public static GoPluginDescriptor parseXML(InputStream pluginXML, String pluginJarFileLocation,
        File pluginBundleLocation, boolean isBundledPlugin) throws IOException, SAXException {
    Digester digester = initDigester();
    GoPluginDescriptorParser parserForThisXML = new GoPluginDescriptorParser(pluginJarFileLocation,
            pluginBundleLocation, isBundledPlugin);
    digester.push(parserForThisXML);/*from  w w  w.  ja  v  a2s. com*/

    digester.addCallMethod("go-plugin", "createPlugin", 2);
    digester.addCallParam("go-plugin", 0, "id");
    digester.addCallParam("go-plugin", 1, "version");

    digester.addCallMethod("go-plugin/about", "createAbout", 4);
    digester.addCallParam("go-plugin/about/name", 0);
    digester.addCallParam("go-plugin/about/version", 1);
    digester.addCallParam("go-plugin/about/target-go-version", 2);
    digester.addCallParam("go-plugin/about/description", 3);

    digester.addCallMethod("go-plugin/about/vendor", "createVendor", 2);
    digester.addCallParam("go-plugin/about/vendor/name", 0);
    digester.addCallParam("go-plugin/about/vendor/url", 1);

    digester.addCallMethod("go-plugin/about/target-os/value", "addTargetOS", 1);
    digester.addCallParam("go-plugin/about/target-os/value", 0);

    digester.parse(pluginXML);

    return parserForThisXML.descriptor;
}

From source file:com.dotosoft.dot4command.config.xml.XmlConfigParser.java

/**
 * <p>Parse the XML document at the specified URL using the configured
 * <code>RuleSet</code>, registering catalogs with nested chains and
 * commands as they are encountered.  Use this method <strong>only</strong>
 * if you have included one or more <code>factory</code> elements in your
 * configuration resource.</p>//from   w  ww.  j  a v a  2s  .  co m
 *
 * @param <K> the type of keys maintained by the context associated with this command
 * @param <V> the type of mapped values
 * @param <C> Type of the context associated with this command
 * @param url <code>URL</code> of the XML document to be parsed
 * @return a CatalogFactory instance parsed from the given location
 * @exception ChainConfigurationException if a parsing error occurs
 */
public <K extends String, V extends Object, C extends Map<K, V>> CatalogFactory<K, V, C> parse(URL url) {
    // Prepare our Digester instance
    Digester digester = getDigester();
    digester.clear();

    // Parse the configuration document
    try {
        digester.parse(url);
    } catch (Exception e) {
        String msg = String.format("Error parsing digester configuration at url: %s", url);
        throw new ChainConfigurationException(msg, e);
    }
    // FIXME get rid of singleton pattern and create a new instance here
    return CatalogFactoryBase.getInstance();
}