/** * Construct an instance based on the provided xpath expression, namespaces and * {@link TransformerFactory}. * @param expression the xpath expression for splitting. * @param namespaces the XML namespace for parsing. * @param transformerFactory the {@link TransformerFactory} * for parsing and building documents. * @since 4.3.19 */ public XPathMessageSplitter(String expression, Map<String, String> namespaces, TransformerFactory transformerFactory) { this(XPathExpressionFactory.createXPathExpression(expression, namespaces), transformerFactory); XPath xpath = XPathFactory.newInstance().newXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); try { this.jaxpExpression = xpath.compile(expression); } catch (XPathExpressionException e) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + e.getMessage(), e); } }
private synchronized XPath createXPath() { XPath xpath = xpathFactory.newXPath(); if (namespaces != null) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); } return xpath; }
private synchronized XPath createXPath() { XPath xpath = xpathFactory.newXPath(); if (namespaces != null) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); } return xpath; }
/** * Sets namespace mapping for all XPath validations like {@link #assertXPath(String)} * @param namespaceMapping * @return */ public MessageValidator useNamespaceMapping(Map<String, String> namespaceMapping) { namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaceMapping); return this; }
private synchronized XPath createXPath() { XPath xpath = xpathFactory.newXPath(); if (namespaces != null) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); } return xpath; }
private synchronized XPath createXPath() { XPath xpath = xpathFactory.newXPath(); if (namespaces != null) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); } return xpath; }
private synchronized XPath createXPath() { XPath xpath = xpathFactory.newXPath(); if (namespaces != null) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); } return xpath; }
public void setNamespaceMap(Map<String, String> namespaceMap) { SimpleNamespaceContext context = new SimpleNamespaceContext(); context.setBindings(namespaceMap); setNamespaceContext(context); }
/** * Builds namespace context with dynamic lookup on received node document and global namespace mappings from * namespace context builder. * @param node the element node from message * @return */ private NamespaceContext buildNamespaceContext(Node node) { SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext(); Map<String, String> namespaces = XMLUtils.lookupNamespaces(node.getOwnerDocument()); // add default namespace mappings namespaces.putAll(namespaceContextBuilder.getNamespaceMappings()); simpleNamespaceContext.setBindings(namespaces); return simpleNamespaceContext; }
/** * Creates a {@code NamespaceContext} for the specified method, based on {@link Namespaces @Namespaces} and {@link * Namespace @Namespace} annotations. * * <p>This method will search for {@link Namespaces @Namespaces} and {@link Namespace @Namespace} annotation in the * given method, its class, and its package, in reverse order. That is: package-level annotations are overridden by * class-level annotations, which again are overridden by method-level annotations. * * @param method the method to create the namespace context for * @return the namespace context */ public static NamespaceContext getNamespaceContext(Method method) { Assert.notNull(method, "'method' must not be null"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); Class<?> endpointClass = method.getDeclaringClass(); Package endpointPackage = endpointClass.getPackage(); if (endpointPackage != null) { addNamespaceAnnotations(endpointPackage, namespaceContext); } addNamespaceAnnotations(endpointClass, namespaceContext); addNamespaceAnnotations(method, namespaceContext); return namespaceContext; }
/** * Creates a {@code NamespaceContext} for the specified method, based on {@link Namespaces @Namespaces} and {@link * Namespace @Namespace} annotations. * <p/> * This method will search for {@link Namespaces @Namespaces} and {@link Namespace @Namespace} annotation in the * given method, its class, and its package, in reverse order. That is: package-level annotations are overridden by * class-level annotations, which again are overridden by method-level annotations. * * @param method the method to create the namespace context for * @return the namespace context */ public static NamespaceContext getNamespaceContext(Method method) { Assert.notNull(method, "'method' must not be null"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); Class<?> endpointClass = method.getDeclaringClass(); Package endpointPackage = endpointClass.getPackage(); if (endpointPackage != null) { addNamespaceAnnotations(endpointPackage, namespaceContext); } addNamespaceAnnotations(endpointClass, namespaceContext); addNamespaceAnnotations(method, namespaceContext); return namespaceContext; }
/** * Creates a {@code NamespaceContext} for the specified method, based on {@link Namespaces @Namespaces} and {@link * Namespace @Namespace} annotations. * * <p>This method will search for {@link Namespaces @Namespaces} and {@link Namespace @Namespace} annotation in the * given method, its class, and its package, in reverse order. That is: package-level annotations are overridden by * class-level annotations, which again are overridden by method-level annotations. * * @param method the method to create the namespace context for * @return the namespace context */ public static NamespaceContext getNamespaceContext(Method method) { Assert.notNull(method, "'method' must not be null"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); Class<?> endpointClass = method.getDeclaringClass(); Package endpointPackage = endpointClass.getPackage(); if (endpointPackage != null) { addNamespaceAnnotations(endpointPackage, namespaceContext); } addNamespaceAnnotations(endpointClass, namespaceContext); addNamespaceAnnotations(method, namespaceContext); return namespaceContext; }
/** * Creates a {@code NamespaceContext} for the specified method, based on {@link Namespaces @Namespaces} and {@link * Namespace @Namespace} annotations. * * <p>This method will search for {@link Namespaces @Namespaces} and {@link Namespace @Namespace} annotation in the * given method, its class, and its package, in reverse order. That is: package-level annotations are overridden by * class-level annotations, which again are overridden by method-level annotations. * * @param method the method to create the namespace context for * @return the namespace context */ public static NamespaceContext getNamespaceContext(Method method) { Assert.notNull(method, "'method' must not be null"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); Class<?> endpointClass = method.getDeclaringClass(); Package endpointPackage = endpointClass.getPackage(); if (endpointPackage != null) { addNamespaceAnnotations(endpointPackage, namespaceContext); } addNamespaceAnnotations(endpointClass, namespaceContext); addNamespaceAnnotations(method, namespaceContext); return namespaceContext; }
/** * Creates a JAXP 1.3 <code>XPathExpression</code> from the given string expression and namespaces. * * @param expression the XPath expression * @param namespaces the namespaces * @return the compiled <code>XPathExpression</code> * @throws XPathParseException when the given expression cannot be parsed */ public static XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) { try { XPath xpath = xpathFactory.newXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
/** * Creates a JAXP 1.3 {@code XPathExpression} from the given string expression and namespaces. * * @param expression the XPath expression * @param namespaces the namespaces * @return the compiled {@code XPathExpression} * @throws XPathParseException when the given expression cannot be parsed */ public static XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) { try { XPath xpath = createXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression, expression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
/** * Creates a JAXP 1.3 {@code XPathExpression} from the given string expression and namespaces. * * @param expression the XPath expression * @param namespaces the namespaces * @return the compiled {@code XPathExpression} * @throws XPathParseException when the given expression cannot be parsed */ public static XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) { try { XPath xpath = createXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression, expression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
@Override public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Function parameters must not be empty"); } if (parameterList.size() < 2) { throw new InvalidFunctionUsageException("Missing parameter for function - usage xpath('xmlSource', 'expression')"); } String xmlSource = parameterList.get(0); String xpathExpression = parameterList.get(1); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(context.getNamespaceContextBuilder().getNamespaceMappings()); return XPathUtils.evaluateAsString(XMLUtils.parseMessagePayload(context.replaceDynamicContentInString(xmlSource)), context.replaceDynamicContentInString(xpathExpression), namespaceContext); } }
private Object evaluate(String expression, Source context, QName returnType) throws XPathException { XPath xpath = createXPath(); if (getNamespaces() != null && !getNamespaces().isEmpty()) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(getNamespaces()); xpath.setNamespaceContext(namespaceContext); } try { EvaluationCallback callback = new EvaluationCallback(xpath, expression, returnType); TraxUtils.doWithSource(context, callback); return callback.result; } catch (javax.xml.xpath.XPathException ex) { throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex); } catch (TransformerException ex) { throw new XPathException("Could not transform context to DOM Node", ex); } catch (Exception ex) { throw new XPathException(ex.getMessage(), ex); } }
private Object evaluate(String expression, Source context, QName returnType) throws XPathException { XPath xpath = createXPath(); if (getNamespaces() != null && !getNamespaces().isEmpty()) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(getNamespaces()); xpath.setNamespaceContext(namespaceContext); } try { EvaluationCallback callback = new EvaluationCallback(xpath, expression, returnType); TraxUtils.doWithSource(context, callback); return callback.result; } catch (javax.xml.xpath.XPathException ex) { throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex); } catch (TransformerException ex) { throw new XPathException("Could not transform context to DOM Node", ex); } catch (Exception ex) { throw new XPathException(ex.getMessage(), ex); } }