Search in sources :

Example 36 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XpathDocumentCopier method resolveXpath.

private String resolveXpath(AdaptrisMessage msg) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
    NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
    if (ctx != null) {
        builder.setNamespaceAware(true);
    }
    Document d = createDocument(msg, builder);
    XPath xp = XPath.newXPathInstance(builder, ctx);
    return xp.selectSingleTextItem(d, getXpath());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) NamespaceContext(javax.xml.namespace.NamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) XmlHelper.createDocument(com.adaptris.core.util.XmlHelper.createDocument) Document(org.w3c.dom.Document)

Example 37 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XpathMessageSplitter method resolveXpath.

// Consider making this namespace aware; we could follow what XpathMetadataQuery does.
private NodeList resolveXpath(AdaptrisMessage msg, NamespaceContext namespaceCtx, DocumentBuilderFactoryBuilder builder) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
    Document d = createDocument(msg, builder);
    XPath xp = XPath.newXPathInstance(builder, namespaceCtx);
    return xp.selectNodeList(d, getXpath());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) XmlHelper.createDocument(com.adaptris.core.util.XmlHelper.createDocument) Document(org.w3c.dom.Document)

Example 38 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XPathService method doService.

// @Override
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    NamespaceContext namespaceContext = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    try {
        DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(namespaceContext);
        Document document = buildDocument(builder, this.getXmlSource().extract(msg));
        XPath xPathHandler = XPath.newXPathInstance(builder, namespaceContext);
        for (Execution execution : this.getExecutions()) {
            String result = this.serializeNode(xPathHandler.selectNodeList(document, execution.getSource().extract(msg)));
            execution.getTarget().insert(result, msg);
        }
    } catch (Exception ex) {
        throw new ServiceException(ex);
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) Execution(com.adaptris.core.common.Execution) ServiceException(com.adaptris.core.ServiceException) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 39 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XpathNodeIdentifier method isThisSyntax.

/**
 * @see SyntaxIdentifier#isThisSyntax(java.lang.String)
 */
@Override
public boolean isThisSyntax(String message) throws ServiceException {
    boolean rc = true;
    try {
        Document d = createDocument(message);
        if (d == null) {
            return false;
        }
        XPath xp = createXPath();
        for (String xpath : getPatterns()) {
            Object result = null;
            if (resolveAsNodeset()) {
                result = xp.selectNodeList(d, xpath);
            } else {
                result = xp.selectSingleNode(d, xpath);
            }
            if (result == null) {
                rc = false;
                break;
            }
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
    return rc;
}
Also used : XPath(com.adaptris.util.text.xml.XPath) ServiceException(com.adaptris.core.ServiceException) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException)

Example 40 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XpathObjectMetadataService method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    try {
        DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
        if (namespaceCtx != null) {
            builder.setNamespaceAware(true);
        }
        XPath xpathToUse = XPath.newXPathInstance(builder, namespaceCtx);
        Document doc = XmlHelper.createDocument(msg, builder);
        for (XpathObjectQuery query : queriesToExecute) {
            msg.getObjectHeaders().put(query.getMetadataKey(), query.resolveXpath(doc, xpathToUse, query.createXpathQuery(msg)));
            log.trace("Added object against [{}]", query.getMetadataKey());
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) ServiceException(com.adaptris.core.ServiceException) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) XpathObjectQuery(com.adaptris.core.services.metadata.xpath.XpathObjectQuery) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Aggregations

XPath (com.adaptris.util.text.xml.XPath)75 Document (org.w3c.dom.Document)64 Test (org.junit.Test)63 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)45 MetadataElement (com.adaptris.core.MetadataElement)23 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)21 CoreException (com.adaptris.core.CoreException)12 Node (org.w3c.dom.Node)11 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)9 NamespaceContext (javax.xml.namespace.NamespaceContext)9 ServiceException (com.adaptris.core.ServiceException)7 InsertNode (com.adaptris.util.text.xml.InsertNode)6 NodeList (org.w3c.dom.NodeList)6 NullService (com.adaptris.core.NullService)5 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)5 XpathMessageSplitter (com.adaptris.core.services.splitter.XpathMessageSplitter)5 TimeInterval (com.adaptris.util.TimeInterval)5 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)2