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());
}
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());
}
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);
}
}
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;
}
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);
}
}
Aggregations