Search in sources :

Example 1 with NodeSetFilter

use of nl.nn.adapterframework.xml.NodeSetFilter in project iaf by ibissource.

the class ForEachChildElementPipe method createHandler.

protected void createHandler(HandlerRecord result, ThreadConnector threadConnector, PipeLineSession session, ItemCallback callback) throws TransformerConfigurationException {
    result.itemHandler = new ItemCallbackCallingHandler(callback);
    result.inputHandler = result.itemHandler;
    if (getXmlDebugger() != null && (StringUtils.isNotEmpty(getContainerElement()) || StringUtils.isNotEmpty(getTargetElement()) || getExtractElementsTp() != null)) {
        String containerElementString = StringUtils.isNotEmpty(getContainerElement()) ? "filter to containerElement '" + getContainerElement() + "'" : null;
        String targetElementString = StringUtils.isNotEmpty(getTargetElement()) ? "filter to targetElement '" + getTargetElement() + "'" : null;
        String xpathString = getExtractElementsTp() != null ? "filter XPath '" + getElementXPathExpression() + "'" : null;
        String label = "XML after preprocessing: " + Misc.concat(", ", containerElementString, targetElementString, xpathString);
        result.inputHandler = getXmlDebugger().inspectXml(session, label, result.inputHandler);
    }
    if (isRemoveNamespaces()) {
        result.inputHandler = new NamespaceRemovingFilter(result.inputHandler);
    }
    if (getExtractElementsTp() != null) {
        if (log.isDebugEnabled())
            log.debug("transforming input to obtain list of elements using xpath [" + getElementXPathExpression() + "]");
        TransformerFilter transformerFilter = getExtractElementsTp().getTransformerFilter(threadConnector, result.inputHandler);
        result.inputHandler = transformerFilter;
        result.transformerErrorListener = (TransformerErrorListener) transformerFilter.getErrorListener();
        result.errorMessage = "Could not process list of elements using xpath [" + getElementXPathExpression() + "]";
    }
    if (StringUtils.isNotEmpty(getTargetElement())) {
        result.inputHandler = new NodeSetFilter(XmlUtils.getNamespaceMap(getNamespaceDefs()), getTargetElement(), true, true, result.inputHandler);
    }
    if (StringUtils.isNotEmpty(getContainerElement())) {
        result.inputHandler = new NodeSetFilter(XmlUtils.getNamespaceMap(getNamespaceDefs()), getContainerElement(), false, true, result.inputHandler);
    }
    result.inputHandler = new StopSensor(result.itemHandler, result.inputHandler);
    result.inputHandler = new ExceptionCatchingFilter(result.inputHandler) {

        @Override
        protected void handleException(Exception e) throws SAXException {
            if (e instanceof SaxTimeoutException) {
                throw (SaxTimeoutException) e;
            }
            if (result.itemHandler.isStopRequested()) {
                if (e instanceof SaxAbortException) {
                    throw (SaxAbortException) e;
                }
                throw new SaxAbortException(e);
            }
            // For improved diagnosability of error situations, rethrow the original exception, where applicable.
            if (result.transformerErrorListener != null) {
                TransformerException tex = result.transformerErrorListener.getFatalTransformerException();
                if (tex != null) {
                    throw new SaxException(result.errorMessage, tex);
                }
                IOException iox = result.transformerErrorListener.getFatalIOException();
                if (iox != null) {
                    throw new SaxException(result.errorMessage, iox);
                }
            }
            throw new SaxException(result.errorMessage, e);
        }
    };
}
Also used : TransformerFilter(nl.nn.adapterframework.xml.TransformerFilter) SaxException(nl.nn.adapterframework.xml.SaxException) IOException(java.io.IOException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) ExceptionCatchingFilter(nl.nn.adapterframework.xml.ExceptionCatchingFilter) TransformerException(javax.xml.transform.TransformerException) SaxException(nl.nn.adapterframework.xml.SaxException) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) StreamingException(nl.nn.adapterframework.stream.StreamingException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) NamespaceRemovingFilter(nl.nn.adapterframework.xml.NamespaceRemovingFilter) SAXException(org.xml.sax.SAXException) NodeSetFilter(nl.nn.adapterframework.xml.NodeSetFilter) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 PipeStartException (nl.nn.adapterframework.core.PipeStartException)1 SenderException (nl.nn.adapterframework.core.SenderException)1 TimeoutException (nl.nn.adapterframework.core.TimeoutException)1 SaxAbortException (nl.nn.adapterframework.stream.SaxAbortException)1 SaxTimeoutException (nl.nn.adapterframework.stream.SaxTimeoutException)1 StreamingException (nl.nn.adapterframework.stream.StreamingException)1 ExceptionCatchingFilter (nl.nn.adapterframework.xml.ExceptionCatchingFilter)1 NamespaceRemovingFilter (nl.nn.adapterframework.xml.NamespaceRemovingFilter)1 NodeSetFilter (nl.nn.adapterframework.xml.NodeSetFilter)1 SaxException (nl.nn.adapterframework.xml.SaxException)1 TransformerFilter (nl.nn.adapterframework.xml.TransformerFilter)1 SAXException (org.xml.sax.SAXException)1