use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XmlRuleValidator method validate.
@Override
public void validate(AdaptrisMessage msg) throws CoreException {
try {
NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(namespaceCtx);
Document doc = createDocument(msg, builder);
XPath xp = XPath.newXPathInstance(builder, namespaceCtx);
for (int stageIndex = 0; stageIndex < validationStages.size(); stageIndex++) {
ValidationStage v = validationStages.get(stageIndex);
NodeList n = xp.selectNodeList(doc, v.getIterationXpath());
validate(n, v.getIterationXpath(), v.failOnIteratorFailure());
for (int i = 0; i < n.getLength(); i++) {
Node node = n.item(i);
String contents = xp.selectSingleTextItem(node, v.getElementXpath());
for (ContentValidation cv : v.getRules()) {
if (!cv.isValid(contents)) {
throw new ServiceException(ERR_MSG.replaceAll(I_COUNT, "" + i).replaceAll(I_XP, Matcher.quoteReplacement(v.getIterationXpath())).replaceAll(E_XP, Matcher.quoteReplacement(v.getElementXpath())).replaceAll(CONTENTS, Matcher.quoteReplacement(contents)).replaceAll(VALIDATION_MSG, Matcher.quoteReplacement(cv.getMessage())));
}
}
}
}
} catch (Exception e) {
ExceptionHelper.rethrowCoreException(e);
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder 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.core.util.DocumentBuilderFactoryBuilder 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.core.util.DocumentBuilderFactoryBuilder 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);
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathMergeImpl method create.
protected XmlUtils create(Document doc) throws Exception {
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
XmlUtils xml = new XmlUtils(builder.getEntityResolver(), SimpleNamespaceContext.create(getNamespaceContext()), builder.build());
xml.setSource(doc);
return xml;
}
Aggregations