Package org.springframework.xml.namespace

Examples of org.springframework.xml.namespace.SimpleNamespaceContext


    }

    private synchronized XPath createXPath() {
        XPath xpath = xpathFactory.newXPath();
        if (namespaces != null) {
            SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
            namespaceContext.setBindings(namespaces);
            xpath.setNamespaceContext(namespaceContext);
        }
        return xpath;
    }
View Full Code Here


     * @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);
        }
View Full Code Here

     * @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);
        }
        catch (XPathExpressionException ex) {
View Full Code Here

    }

    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);
View Full Code Here

                        "Can not set null values in XML document - path expression is " + pathExpression);
            }

            Node node;
            if (XPathUtils.isXPathExpression(pathExpression)) {
                SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
                nsContext.setBindings(XMLUtils.lookupNamespaces(message.getPayload().toString()));
                node = XPathUtils.evaluateAsNode(doc, pathExpression, nsContext);
            } else {
                node = XMLUtils.findNodeByName(doc, pathExpression);
            }
View Full Code Here

     * @param receivedMessage the actual message received.
     * @param namespaces explicit namespace mappings for this construction.
     * @return the constructed namespace context.
     */
    public NamespaceContext buildContext(Message receivedMessage, Map<String, String> namespaces) {
        SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
       
        //first add default namespace definitions
        if (namespaceMappings.size() > 0) {
            simpleNamespaceContext.setBindings(namespaceMappings);
        }
       
        Map<String, String> dynamicBindings = XMLUtils.lookupNamespaces(receivedMessage.getPayload().toString());
        if (!CollectionUtils.isEmpty(namespaces)) {
            //dynamic binding of namespaces declarations in root element of received message
            for (Entry<String, String> binding : dynamicBindings.entrySet()) {
                //only bind namespace that is not present in explicit namespace bindings
                if (!namespaces.containsValue(binding.getValue())) {
                    simpleNamespaceContext.bindNamespaceUri(binding.getKey(), binding.getValue());
                }
            }
            //add explicit namespace bindings
            simpleNamespaceContext.setBindings(namespaces);
        } else {
            simpleNamespaceContext.setBindings(dynamicBindings);
        }
       
        return simpleNamespaceContext;
    }
View Full Code Here

     * 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;
    }
View Full Code Here

TOP

Related Classes of org.springframework.xml.namespace.SimpleNamespaceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.