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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations