use of com.adaptris.transform.validate.ContentValidation 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);
}
}
Aggregations