Search in sources :

Example 1 with InvalidExpression

use of org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression in project cxf by apache.

the class FragmentDialect method modifyRepresentationModeAdd.

/**
 * Process Put requests for Add mode.
 * @param value Value defined in the Value element.
 * @return Representation element, which is returned as response.
 */
private Representation modifyRepresentationModeAdd(List<Node> nodeList, ValueType value) {
    if (nodeList.isEmpty()) {
        throw new InvalidExpression();
    }
    Node firstNode = nodeList.get(0);
    Document ownerDocument = firstNode.getOwnerDocument();
    // if firstNode.getOwnerDocument == null the firstNode is ownerDocument
    ownerDocument = ownerDocument == null ? (Document) firstNode : ownerDocument;
    for (Node node : nodeList) {
        addNode(ownerDocument, node, null, value);
    }
    Representation representation = new Representation();
    representation.setAny(ownerDocument.getDocumentElement());
    return representation;
}
Also used : Node(org.w3c.dom.Node) Representation(org.apache.cxf.ws.transfer.Representation) InvalidRepresentation(org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation) Document(org.w3c.dom.Document) InvalidExpression(org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)

Example 2 with InvalidExpression

use of org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression in project cxf by apache.

the class FragmentDialect method modifyRepresentation.

/**
 * Process Put requests.
 * @param resourceFragment Result of the XPath evaluation. It can be Node or NodeList.
 * @param mode Mode defined in the Mode attribute.
 * @param value Value defined in the Value element.
 * @return Representation element, which is returned as response.
 */
private Representation modifyRepresentation(Object resourceFragment, String mode, ValueType value) {
    if (resourceFragment instanceof Node) {
        List<Node> nodeList = new ArrayList<>();
        nodeList.add((Node) resourceFragment);
        return modifyRepresentationMode(nodeList, mode, value);
    } else if (resourceFragment instanceof NodeList) {
        NodeList rfNodeList = (NodeList) resourceFragment;
        List<Node> nodeList = new ArrayList<>();
        for (int i = 0; i < rfNodeList.getLength(); i++) {
            nodeList.add(rfNodeList.item(i));
        }
        return modifyRepresentationMode(nodeList, mode, value);
    } else {
        throw new InvalidExpression();
    }
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) InvalidExpression(org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)

Example 3 with InvalidExpression

use of org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression in project cxf by apache.

the class FragmentDialect method insertAfter.

private void insertAfter(Document ownerDocument, Node parent, Node refChild, ValueType value) {
    for (Object o : value.getContent()) {
        if (o instanceof Node) {
            Node node = (Node) o;
            if (FragmentDialectConstants.FRAGMENT_2011_03_IRI.equals(node.getNamespaceURI()) && FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME.equals(node.getLocalName())) {
                throw new InvalidRepresentation();
            }
            Node importedNode = ownerDocument.importNode(node, true);
            if (parent.getNodeType() == Node.DOCUMENT_NODE) {
                parent.appendChild(importedNode);
            } else {
                Node nextSibling = refChild.getNextSibling();
                if (nextSibling == null) {
                    parent.appendChild(importedNode);
                } else {
                    parent.insertBefore(importedNode, nextSibling);
                }
            }
        } else {
            throw new InvalidExpression();
        }
    }
}
Also used : InvalidRepresentation(org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation) Node(org.w3c.dom.Node) InvalidExpression(org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)

Example 4 with InvalidExpression

use of org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression in project cxf by apache.

the class FragmentDialectLanguageQName method getXPathFromQNameExpression.

/**
 * Converts expression in QName language to XPath expression.
 * @param expression Expression in QName language.
 * @return Expression in XPath language.
 */
private String getXPathFromQNameExpression(ExpressionType expression) {
    if (expression.getContent().size() == 1) {
        String expressionValue = (String) expression.getContent().get(0);
        Matcher m = qNamePattern.matcher(expressionValue);
        if (m.matches()) {
            return "/node()/" + expressionValue;
        }
        throw new InvalidExpression();
    }
    throw new InvalidExpression();
}
Also used : Matcher(java.util.regex.Matcher) InvalidExpression(org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)

Example 5 with InvalidExpression

use of org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression in project cxf by apache.

the class FragmentDialect method modifyRepresentationModeReplace.

/**
 * Process Put requests for Replace mode.
 * @param value Value defined in the Value element.
 * @return Representation element, which is returned as response.
 */
private Representation modifyRepresentationModeReplace(List<Node> nodeList, ValueType value) {
    if (nodeList.isEmpty()) {
        throw new InvalidExpression();
    }
    Node firstNode = nodeList.get(0);
    Document ownerDocument = firstNode.getOwnerDocument();
    // if firstNode.getOwnerDocument == null the firstNode is ownerDocument
    ownerDocument = ownerDocument == null ? (Document) firstNode : ownerDocument;
    Node nextSibling = null;
    Node parent = null;
    for (Node node : nodeList) {
        nextSibling = node.getNextSibling();
        parent = removeNode(node);
    }
    addNode(ownerDocument, parent, nextSibling, value);
    Representation representation = new Representation();
    representation.setAny(ownerDocument.getDocumentElement());
    return representation;
}
Also used : Node(org.w3c.dom.Node) Representation(org.apache.cxf.ws.transfer.Representation) InvalidRepresentation(org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation) Document(org.w3c.dom.Document) InvalidExpression(org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)

Aggregations

InvalidExpression (org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)10 Node (org.w3c.dom.Node)8 InvalidRepresentation (org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation)7 Representation (org.apache.cxf.ws.transfer.Representation)5 Document (org.w3c.dom.Document)5 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 XPath (javax.xml.xpath.XPath)1 XPathException (javax.xml.xpath.XPathException)1 Element (org.w3c.dom.Element)1