/** * Walk the XML tree and validate all nodes. * * @param received * @param source * @param validationContext */ private void validateXmlTree( Node received, Node source, XmlMessageValidationContext validationContext, NamespaceContext namespaceContext, TestContext context) { switch (received.getNodeType()) { case Node.DOCUMENT_TYPE_NODE: doDocumentTypeDefinition(received, source, validationContext, namespaceContext, context); break; case Node.DOCUMENT_NODE: validateXmlTree( received.getFirstChild(), source.getFirstChild(), validationContext, namespaceContext, context); break; case Node.ELEMENT_NODE: doElement(received, source, validationContext, namespaceContext, context); break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: doText(received, source); break; case Node.ATTRIBUTE_NODE: throw new IllegalStateException(); case Node.COMMENT_NODE: doComment(received); break; case Node.PROCESSING_INSTRUCTION_NODE: doPI(received); break; } }
/** * Checks whether the given node contains a validation matcher * * @param node * @return true if node value contains validation matcher, false if not */ private boolean isValidationMatcherExpression(Node node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: return node.getFirstChild() != null && StringUtils.hasText(node.getFirstChild().getNodeValue()) && ValidationMatcherUtils.isValidationMatcherExpression( node.getFirstChild().getNodeValue().trim()); case Node.ATTRIBUTE_NODE: return StringUtils.hasText(node.getNodeValue()) && ValidationMatcherUtils.isValidationMatcherExpression(node.getNodeValue().trim()); default: return false; // validation matchers makes no sense } }