Search in sources :

Example 41 with Representation

use of org.apache.cxf.ws.transfer.Representation in project cxf by apache.

the class XSLTResourceTransformerTest method transformTest.

@Test
public void transformTest() throws XMLStreamException {
    ResourceTransformer transformer = new XSLTResourceTransformer(new StreamSource(getClass().getResourceAsStream("/xml/xsltresourcetransformer/stylesheet.xsl")));
    Representation representation = loadRepresentation(getClass().getResourceAsStream("/xml/xsltresourcetransformer/representation.xml"));
    transformer.transform(representation, null);
    Element representationEl = (Element) representation.getAny();
    Assert.assertEquals("Expected root element with name \"person\".", "person", representationEl.getLocalName());
    Assert.assertTrue("Expected one element \"firstname\".", representationEl.getElementsByTagName("firstname").getLength() == 1);
    Assert.assertTrue("Expected one element \"lastname\".", representationEl.getElementsByTagName("lastname").getLength() == 1);
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) Element(org.w3c.dom.Element) XSLTResourceTransformer(org.apache.cxf.ws.transfer.validationtransformation.XSLTResourceTransformer) Representation(org.apache.cxf.ws.transfer.Representation) XSLTResourceTransformer(org.apache.cxf.ws.transfer.validationtransformation.XSLTResourceTransformer) ResourceTransformer(org.apache.cxf.ws.transfer.validationtransformation.ResourceTransformer) Test(org.junit.Test)

Example 42 with Representation

use of org.apache.cxf.ws.transfer.Representation 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)

Example 43 with Representation

use of org.apache.cxf.ws.transfer.Representation in project cxf by apache.

the class FragmentDialect method modifyRepresentationModeRemove.

/**
 * Process Put requests for Remove mode.
 * @param value Value defined in the Value element.
 * @return Representation element, which is returned as response.
 */
private Representation modifyRepresentationModeRemove(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) {
        removeNode(node);
    }
    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 44 with Representation

use of org.apache.cxf.ws.transfer.Representation in project cxf by apache.

the class FragmentDialect method modifyRepresentationModeInsertAfter.

/**
 * Process Put requests for InsertAfter mode.
 * @param value Value defined in the Value element.
 * @return Representation element, which is returned as response.
 */
private Representation modifyRepresentationModeInsertAfter(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 parent = firstNode.getParentNode();
    if (parent == null && firstNode.getNodeType() != Node.DOCUMENT_NODE) {
        throw new InvalidExpression();
    }
    if (parent == null) {
        parent = firstNode;
        if (((Document) parent).getDocumentElement() != null) {
            throw new InvalidExpression();
        }
    }
    for (Node node : nodeList) {
        if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
            throw new InvalidRepresentation();
        }
        insertAfter(ownerDocument, parent, node, value);
    }
    Representation representation = new Representation();
    representation.setAny(ownerDocument.getDocumentElement());
    return representation;
}
Also used : InvalidRepresentation(org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation) 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 45 with Representation

use of org.apache.cxf.ws.transfer.Representation in project cxf by apache.

the class FragmentDialect method modifyRepresentationModeInsertBefore.

/**
 * Process Put requests for InsertBefore mode.
 * @param value Value defined in the Value element.
 * @return Representation element, which is returned as response.
 */
private Representation modifyRepresentationModeInsertBefore(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 parent = firstNode.getParentNode();
    if (parent == null && firstNode.getNodeType() != Node.DOCUMENT_NODE) {
        throw new InvalidExpression();
    }
    if (parent == null) {
        parent = firstNode;
        if (((Document) parent).getDocumentElement() != null) {
            throw new InvalidExpression();
        }
    }
    for (Node node : nodeList) {
        if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
            throw new InvalidRepresentation();
        }
        insertBefore(ownerDocument, parent, node, value);
    }
    Representation representation = new Representation();
    representation.setAny(ownerDocument.getDocumentElement());
    return representation;
}
Also used : InvalidRepresentation(org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation) 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

Representation (org.apache.cxf.ws.transfer.Representation)48 Test (org.junit.Test)29 Document (org.w3c.dom.Document)25 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)21 Element (org.w3c.dom.Element)15 Create (org.apache.cxf.ws.transfer.Create)14 ResourceFactory (org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory)14 CreateResponse (org.apache.cxf.ws.transfer.CreateResponse)12 Resource (org.apache.cxf.ws.transfer.resource.Resource)11 Put (org.apache.cxf.ws.transfer.Put)10 Server (org.apache.cxf.endpoint.Server)9 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)9 PutResponse (org.apache.cxf.ws.transfer.PutResponse)7 MemoryResourceManager (org.apache.cxf.ws.transfer.manager.MemoryResourceManager)7 ExpressionType (org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType)5 Fragment (org.apache.cxf.ws.transfer.dialect.fragment.Fragment)5 ValueType (org.apache.cxf.ws.transfer.dialect.fragment.ValueType)5 InvalidExpression (org.apache.cxf.ws.transfer.dialect.fragment.faults.InvalidExpression)5 InvalidRepresentation (org.apache.cxf.ws.transfer.shared.faults.InvalidRepresentation)5 Node (org.w3c.dom.Node)5