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

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

Introduction

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

Prototype

public String getCurrentElementName() 

Source Link

Document

Return the name of the XML element that is currently being processed.

Usage

From source file:nl.nn.adapterframework.configuration.ConfigurationDigester.java

public void digestConfiguration(ClassLoader classLoader, Configuration configuration, String configurationFile,
        boolean configLogAppend) throws ConfigurationException {
    Digester digester = null;
    try {// w w w.j  a  v a2s . c om
        digester = getDigester(configuration);
        URL digesterRulesURL = ClassUtils.getResourceURL(this, getDigesterRules());
        if (digesterRulesURL == null) {
            throw new ConfigurationException("Digester rules file not found: " + getDigesterRules());
        }
        URL configurationFileURL = ClassUtils.getResourceURL(classLoader, configurationFile);
        if (configurationFileURL == null) {
            throw new ConfigurationException("Configuration file not found: " + configurationFile);
        }
        configuration.setDigesterRulesURL(digesterRulesURL);
        configuration.setConfigurationURL(configurationFileURL);
        fillConfigWarnDefaultValueExceptions(configuration);
        String lineSeparator = SystemUtils.LINE_SEPARATOR;
        if (null == lineSeparator)
            lineSeparator = "\n";
        String original = Misc.resourceToString(configurationFileURL, lineSeparator, false);
        original = XmlUtils.identityTransform(classLoader, original);
        configuration.setOriginalConfiguration(original);
        List<String> propsToHide = new ArrayList<String>();
        String propertiesHideString = AppConstants.getInstance(Thread.currentThread().getContextClassLoader())
                .getString("properties.hide", null);
        if (propertiesHideString != null) {
            propsToHide.addAll(Arrays.asList(propertiesHideString.split("[,\\s]+")));
        }
        String loaded = StringResolver.substVars(original,
                AppConstants.getInstance(Thread.currentThread().getContextClassLoader()));
        String loadedHide = StringResolver.substVars(original,
                AppConstants.getInstance(Thread.currentThread().getContextClassLoader()), null, propsToHide);
        loaded = ConfigurationUtils.getActivatedConfiguration(configuration, loaded);
        loadedHide = ConfigurationUtils.getActivatedConfiguration(configuration, loadedHide);
        if (ConfigurationUtils.stubConfiguration()) {
            loaded = ConfigurationUtils.getStubbedConfiguration(configuration, loaded);
            loadedHide = ConfigurationUtils.getStubbedConfiguration(configuration, loadedHide);
        }
        configuration.setLoadedConfiguration(loadedHide);
        saveConfig(loadedHide, configLogAppend);
        digester.parse(new StringReader(loaded));
    } catch (Throwable t) {
        // wrap exception to be sure it gets rendered via the IbisException-renderer
        String currentElementName = null;
        if (digester != null) {
            currentElementName = digester.getCurrentElementName();
        }
        ConfigurationException e = new ConfigurationException(
                "error during unmarshalling configuration from file [" + configurationFile
                        + "] with digester-rules-file [" + getDigesterRules() + "] in element ["
                        + currentElementName + "]" + (StringUtils.isEmpty(lastResolvedEntity) ? ""
                                : " last resolved entity [" + lastResolvedEntity + "]"),
                t);
        throw e;
    }
    if (MonitorManager.getInstance().isEnabled()) {
        MonitorManager.getInstance().configure(configuration);
    }
}

From source file:org.xchain.framework.digester.SerializationRule.java

public void begin(String namespaceUri, String name, Attributes attributes) throws Exception {
    // get the digester.
    Digester digester = getDigester();

    // store the old content handlers.
    oldCustomContentHandler = digester.getCustomContentHandler();
    if (digester instanceof ExtendedDigester) {
        oldCustomLexicalHandler = ((ExtendedDigester) digester).getCustomLexicalHandler();
    }/*  w w  w. j a  va 2  s  .c  o m*/

    // create the handler.
    handler = new RuleSerializationHandler();

    // set up the handlers that will do the serialization.
    handler.setWrappedHandler(newHandler());

    // set the new handlers.
    digester.setCustomContentHandler(handler);
    if (digester instanceof ExtendedDigester) {
        ((ExtendedDigester) digester).setCustomLexicalHandler(handler);
    }

    // push the buffer onto the stack.
    digester.push(buffer);

    // start the document.
    handler.startDocument();

    // set all of the namespaces that are defined on the digester.
    Iterator currentNamespaceIterator = digester.getCurrentNamespaces().entrySet().iterator();
    while (currentNamespaceIterator.hasNext()) {
        Map.Entry currentNamespace = (Map.Entry) currentNamespaceIterator.next();
        handler.startPrefixMapping((String) currentNamespace.getKey(), (String) currentNamespace.getValue());
    }

    // send the current element to the handler.
    if (digester.getNamespaceAware()) {
        handler.startElement(namespaceUri, name, digester.getCurrentElementName(), attributes);
    } else {
        handler.startElement(namespaceUri, name, name, attributes);
    }
}