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

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

Introduction

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

Prototype

public void clear() 

Source Link

Document

Clear the current contents of the default object stack, the param stack, all named stacks, and other internal variables.

Usage

From source file:com.zyd.ztools.util.XmlUtil.java

public static Property parseXml(String content) {
    if (content == null || content.length() <= 0) {
        return null;
    }/*from  w  w w  . j a v  a2s . com*/
    Property property = null;
    try {
        Digester digester = new Digester();
        digester.clear();
        digester.setValidating(false);
        digester.setUseContextClassLoader(true);
        digester.addObjectCreate("property", Property.class);
        digester.addBeanPropertySetter("property/returncode", "returncode");
        digester.addBeanPropertySetter("property/key", "key");
        digester.addBeanPropertySetter("property/original", "original");
        InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
        property = (Property) digester.parse(in);
    } catch (Exception e) {
        System.out.println("?XML...");
        System.out.println(content);
    }
    return property;
}

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 v  a2 s .c o  m*/
    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:catalina.core.StandardHostDeployer.java

/**
 * <p>Install a new web application, whose context configuration file
 * (consisting of a <code>&lt;Context&gt;</code> element) and (optional)
 * web application archive are at the specified URLs.</p>
 *
 * If this application is successfully installed, a ContainerEvent of type
 * <code>PRE_INSTALL_EVENT</code> will be sent to registered listeners
 * before the associated Context is started, and a ContainerEvent of type
 * <code>INSTALL_EVENT</code> will be sent to all registered listeners
 * after the associated Context is started, with the newly created
 * <code>Context</code> as an argument.
 *
 * @param config A URL that points to the context configuration descriptor
 *  to be used for configuring the new Context
 * @param war A URL of type "jar:" that points to a WAR file, or type
 *  "file:" that points to an unpacked directory structure containing
 *  the web application to be installed, or <code>null</code> to use
 *  the <code>docBase</code> attribute from the configuration descriptor
 *
 * @exception IllegalArgumentException if one of the specified URLs is
 *  null/* ww w  .  j  a va2  s. c om*/
 * @exception IllegalStateException if the context path specified in the
 *  context configuration file is already attached to an existing web
 *  application
 * @exception IOException if an input/output error was encountered
 *  during installation
 */
public synchronized void install(URL config, URL war) throws IOException {

    // Validate the format and state of our arguments
    if (config == null)
        throw new IllegalArgumentException(sm.getString("standardHost.configRequired"));

    if (!host.isDeployXML())
        throw new IllegalArgumentException(sm.getString("standardHost.configNotAllowed"));

    // Calculate the document base for the new web application (if needed)
    String docBase = null; // Optional override for value in config file
    if (war != null) {
        String url = war.toString();
        host.log(sm.getString("standardHost.installingWAR", url));
        // Calculate the WAR file absolute pathname
        if (url.startsWith("jar:")) {
            url = url.substring(4, url.length() - 2);
        }
        if (url.startsWith("file://"))
            docBase = url.substring(7);
        else if (url.startsWith("file:"))
            docBase = url.substring(5);
        else
            throw new IllegalArgumentException(sm.getString("standardHost.warURL", url));

    }

    // Install the new web application
    this.context = null;
    this.overrideDocBase = docBase;
    InputStream stream = null;
    try {
        stream = config.openStream();
        Digester digester = createDigester();
        digester.setDebug(host.getDebug());
        digester.clear();
        digester.push(this);
        digester.parse(stream);
        stream.close();
        stream = null;
    } catch (Exception e) {
        host.log(sm.getString("standardHost.installError", docBase), e);
        throw new IOException(e.toString());
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (Throwable t) {
                ;
            }
        }
    }

}

From source file:com.alibaba.antx.config.descriptor.ConfigDescriptorLoader.java

/** ?descriptordigester */
protected Digester getDigester() {
    Digester digester = loadValidatorPlugins();

    // config/*from w w w .  ja  v  a  2  s  .c  o m*/
    digester.addSetProperties("config");

    // config/group
    digester.addObjectCreate("config/group", ConfigGroup.class);
    digester.addSetProperties("config/group");
    digester.addSetNext("config/group", "addGroup");

    // config/group/property
    digester.addObjectCreate("config/group/property", ConfigProperty.class);
    digester.addSetProperties("config/group/property");
    digester.addCallMethod("config/group/property", "afterPropertiesSet");
    digester.addSetNext("config/group/property", "addProperty");

    // config/group/property/validator
    PluginCreateRule pcr = new PluginCreateRule(ConfigValidator.class);

    pcr.setPluginIdAttribute(null, "name");

    digester.addRule("config/group/property/validator", pcr);
    digester.addSetNext("config/group/property/validator", "addValidator");

    // config/script/generate
    digester.addObjectCreate("config/script/generate", ConfigGenerate.class);
    digester.addSetProperties("config/script/generate");
    digester.addSetNext("config/script/generate", "addGenerate");

    digester.clear();

    return digester;
}

From source file:com.sun.faces.config.ConfigureListener.java

/**
 * <p>Parse the configuration resource at the specified URL, using
 * the specified <code>Digester</code> instance.</p>
 *
 * @param digester Digester to use for parsing
 * @param url      URL of the configuration resource to be parsed
 * @param fcb      FacesConfigBean to accumulate results
 *//* w w  w . jav a 2 s  . c om*/
protected void parse(Digester digester, URL url, FacesConfigBean fcb) {

    if (log.isDebugEnabled()) {
        log.debug("parse(" + url.toExternalForm() + ')');
    }

    URLConnection conn = null;
    InputStream stream = null;
    InputSource source = null;
    try {
        conn = url.openConnection();
        conn.setUseCaches(false);
        stream = conn.getInputStream();
        source = new InputSource(url.toExternalForm());
        source.setByteStream(stream);
        digester.clear();
        digester.push(fcb);
        digester.parse(source);
        stream.close();
        stream = null;
    } catch (Exception e) {
        String message = null;
        try {
            message = Util.getExceptionMessageString(Util.CANT_PARSE_FILE_ERROR_MESSAGE_ID,
                    new Object[] { url.toExternalForm() });
        } catch (Exception ee) {
            message = "Can't parse configuration file:" + url.toExternalForm();
        }
        if (log.isErrorEnabled()) {
            log.error(message, e);
        }
        throw new FacesException(message, e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (Exception e) {
                ;
            }
        }
        stream = null;
    }

}

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

/**
 * Extract the JHoveFileProperty from the String and returns a
 * {@link JHoveFileProperty} class.//from   ww w  . j  a  v  a2  s. c o  m
 * 
 * @param fileName
 * @return
 */
public JHoveFileProperty digestString(String stringToDigest) {
    Digester digester = null;
    try {

        digester = new Digester();
        digester.setValidating(false);

        StrictErrorHandler errorHandler = new StrictErrorHandler();
        digester.setErrorHandler(errorHandler);

        digester.setUseContextClassLoader(true);

        digester.addObjectCreate("jhove", JHoveFileProperty.class);
        // GENERAL INFOS
        digester.addBeanPropertySetter("jhove/date", "extractionDate");
        digester.addSetProperties("jhove/repInfo/uri", "fileURI", "uri");
        digester.addBeanPropertySetter("jhove/repInfo/size", "fileSize");
        digester.addBeanPropertySetter("jhove/repInfo/format", "format");
        digester.addBeanPropertySetter("jhove/repInfo/version", "version");
        digester.addBeanPropertySetter("jhove/repInfo/status", "status");
        digester.addBeanPropertySetter("jhove/repInfo/mimeType", "mimetype");
        digester.addBeanPropertySetter("jhove/repInfo/sigMatch/module", "jhoveModuleName");
        // OBJECT: MODULE - START
        digester.addObjectCreate("jhove/repInfo/reportingModule", Module.class);
        digester.addSetProperties("jhove/repInfo/reportingModule", "release", "release");
        digester.addSetProperties("jhove/repInfo/reportingModule", "date", "date");
        digester.addBeanPropertySetter("jhove/repInfo/reportingModule", "name");
        digester.addSetNext("jhove/repInfo/reportingModule", "setModule");
        // OBJECT: MODULE - END

        // OBJECT: PROFILES - START
        digester.addObjectCreate("jhove/repInfo/profiles", Vector.class);

        // OBJECT: PROFILE - START
        digester.addCallMethod("jhove/repInfo/profiles/profile", "add", 1);
        digester.addCallParam("jhove/repInfo/profiles/profile", 0);

        digester.addSetNext("jhove/repInfo/profiles", "setProfiles");
        // OBJECT: PROFILES- END

        // OBJECT: PROPERTIES - START
        digester.addObjectCreate("jhove/repInfo/properties", Vector.class);

        // OBJECT: PROPERTY - START
        digester.addObjectCreate("*/property/", Property.class);
        digester.addBeanPropertySetter("*/property/name", "name");
        digester.addSetProperties("*/property/values", "type", "type");

        digester.addObjectCreate("*/property/values", Vector.class);
        digester.addCallMethod("*/property/values/value", "add", 1);
        digester.addCallParam("*/property/values/value", 0);

        digester.addSetNext("*/property/values", "setValues");

        // OBJECT: PROPERTY - END
        digester.addSetNext("*/property/", "add");

        digester.addSetNext("jhove/repInfo/properties", "setProperties");

        Object jhoveFileProp = digester.parse(new StringReader(stringToDigest));

        if (jhoveFileProp instanceof JHoveFileProperty)
            return (JHoveFileProperty) jhoveFileProp;
        else
            return null;

    } catch (Exception exc) {
        log.error("error happened while digesting the following jhove string \n====================\n"
                + stringToDigest);
        log.error("could not digest jhove results. error: " + exc.getMessage(), exc);
        return null;
    } finally {
        digester.clear();
    }
}

From source file:org.ajax4jsf.tests.org.apache.shale.test.config.ConfigParser.java

/**
 * <p>Parse the specified JavaServer Faces configuration resource, causing
 * the appropriate JSF artifacts to be registered with the mock object
 * hierarchy.</p>//from  w  ww.ja v  a2 s. c o  m
 *
 * @param url <code>URL</code> of the configuration resource to parse
 *
 * @exception IOException if an input/output error occurs
 * @exception SAXException if a parsing error occurs
 */
public void parse(URL url) throws IOException, SAXException {

    // Acquire and configure the Digester instance we will use
    Digester digester = digester();
    ApplicationFactory factory = (ApplicationFactory) FactoryFinder
            .getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application application = factory.getApplication();

    digester.push(application);

    // Perform the required parsing
    try {
        digester.parse(new InputSource(url.openStream()));
    } finally {
        digester.clear();
    }
}

From source file:org.squale.jraf.bootstrap.config.AbstractProviderConfigReader.java

/**
 * Lis le fichier de configuration d'un provider
 * @param in_fileName chemin du fichier de configuration 
 * @return liste de configuration//  w ww  . j  av a  2s.com
 */
public List readConfig(InputStream in_stream) throws JrafConfigException {

    // liste de configuration
    List lc_config = new ArrayList();
    Digester lc_digester = new Digester();
    lc_digester.setEntityResolver(new DTDEntityResolver(_dtdRegistration));
    lc_digester.addRuleSet(this);
    lc_digester.push(lc_config);
    try {
        lc_digester.parse(in_stream);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new JrafConfigException("Impossible de lire le fichier de configuration", ioe);
    } catch (SAXException saxe) {
        saxe.printStackTrace();
        throw new JrafConfigException("Impossible de parser le fichier de configuration", saxe);
    } catch (FactoryConfigurationError e) {
        e.printStackTrace();
        throw new JrafConfigException("Impossible de charger le parser xml", e);

    } finally {
        if (in_stream != null) {
            try {
                in_stream.close();
                lc_digester.clear();
            } catch (IOException ie) {
                // nothing to do   
            }
        }
    }
    // retourne la liste de configuration
    return lc_config;
}

From source file:org.squale.jraf.provider.accessdelegate.config.AbstractApplicationComponentConfigReader.java

/**
 * Lis le fichier de configuration d'un plugin
 * @param in_stream stream pour la lecture du fichier de configuration 
 */// w  w w. jav a 2  s .c o m
public Map readConfig(InputStream in_stream) throws JrafConfigException {

    List configList = new ArrayList();
    Map configMap = new HashMap();

    Digester lc_digester = new Digester();
    lc_digester.setEntityResolver(new DTDEntityResolver(_dtdRegistration));
    lc_digester.addRuleSet(this);
    lc_digester.push(configList);
    try {
        lc_digester.parse(in_stream);
    } catch (IOException ioe) {
        log.fatal("Impossible de lire le fichier ", ioe);
        throw new JrafConfigException("Impossible de lire le fichier ", ioe);
    } catch (SAXException saxe) {
        log.fatal("Impossible de parser le fichier ", saxe);
        throw new JrafConfigException("Impossible de parser le fichier ", saxe);
    } finally {
        if (in_stream != null) {
            try {
                in_stream.close();
                lc_digester.clear();
            } catch (IOException ie) {
                // trace de niveau debug
                if (log.isDebugEnabled()) {
                    log.debug("Probleme lors de la fermeture du flux et du digester: ", ie);
                }
            }
        }
    }

    // transformation de la liste de configuration en map de configuration
    Iterator i = configList.iterator();
    while (i.hasNext()) {
        IApplicationComponentConfig conf = (IApplicationComponentConfig) i.next();

        configMap.put(conf.getName(), conf);
    }

    // on retourbe la map de configuration
    return configMap;

}

From source file:oscar.oscarEncounter.oscarMeasurements.util.EctFindMeasurementTypeUtil.java

static public EctFormProp getEctMeasurementsType(InputStream is) {
    EctFormProp ret = null;//from w  w w .j av  a 2  s  .  c  o  m
    try {
        Digester digester = new Digester();
        digester.setValidating(false);

        digester.addObjectCreate("formProp", EctFormProp.class);
        digester.addObjectCreate("formProp/measurement", EctMeasurementTypesBean.class);
        digester.addBeanPropertySetter("formProp/measurement/type", "type");
        digester.addBeanPropertySetter("formProp/measurement/typeDesc", "typeDesc");
        digester.addBeanPropertySetter("formProp/measurement/typeDisplayName", "typeDisplayName");
        digester.addBeanPropertySetter("formProp/measurement/measuringInstrc", "measuringInstrc");
        digester.addBeanPropertySetter("formProp/measurement/canPrefill", "canPrefill");

        digester.addObjectCreate("formProp/measurement/validationRule", EctValidationsBean.class);
        digester.addBeanPropertySetter("formProp/measurement/validationRule/name", "name");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/regularExp", "regularExp");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/minValue", "minValue");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/maxValue", "maxValue");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/minLength", "minLength");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/maxLength", "maxLength");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/isNumeric", "isNumeric");
        digester.addBeanPropertySetter("formProp/measurement/validationRule/isDate", "isDate");
        digester.addSetNext("formProp/measurement/validationRule", "addValidationRule");

        digester.addSetNext("formProp/measurement", "addMeasurementType");

        //File input = new File(xmlPath);
        ret = (EctFormProp) digester.parse(is);
        digester.clear();
    } catch (Exception exc) {
        MiscUtils.getLogger().error("Error", exc);
    }
    return ret;
}