Example usage for org.dom4j.io DocumentResult getDocument

List of usage examples for org.dom4j.io DocumentResult getDocument

Introduction

In this page you can find the example usage for org.dom4j.io DocumentResult getDocument.

Prototype

public Document getDocument() 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.springframework.ws.server.endpoint.AbstractDom4jPayloadEndpoint.java

License:Apache License

@Override
public final Source invoke(Source request) throws Exception {
    Element requestElement = null;
    if (request != null) {
        DocumentResult dom4jResult = new DocumentResult();
        transform(request, dom4jResult);
        requestElement = dom4jResult.getDocument().getRootElement();
    }/*from w  w  w  .ja  va2s  .c  om*/
    Document responseDocument = DocumentHelper.createDocument();
    Element responseElement = invokeInternal(requestElement, responseDocument);
    return responseElement != null ? new DocumentSource(responseElement) : null;
}

From source file:org.springframework.ws.server.endpoint.AbstractDom4jPayloadEndpoint.java

License:Apache License

/**
 * Returns the payload element of the given source.
 *
 * <p>Default implementation checks whether the source is a {@link javax.xml.transform.dom.DOMSource}, and uses a
 * {@link org.dom4j.io.DOMReader} to create a JDOM {@link org.dom4j.Element}. In all other cases, or when
 * {@linkplain #setAlwaysTransform(boolean) alwaysTransform} is {@code true}, the source is transformed into a
 * {@link org.dom4j.io.DocumentResult}, which is more expensive. If the passed source is {@code null}, {@code
 * null} is returned.//  w ww  .jav a2  s  .com
 *
 * @param source the source to return the root element of; can be {@code null}
 * @return the document element
 * @throws javax.xml.transform.TransformerException
 *         in case of errors
 */
protected Element getDocumentElement(Source source) throws TransformerException {
    if (source == null) {
        return null;
    }
    if (!alwaysTransform && source instanceof DOMSource) {
        Node node = ((DOMSource) source).getNode();
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            DOMReader domReader = new DOMReader();
            Document document = domReader.read((org.w3c.dom.Document) node);
            return document.getRootElement();
        }
    }
    // we have no other option than to transform
    DocumentResult dom4jResult = new DocumentResult();
    transform(source, dom4jResult);
    return dom4jResult.getDocument().getRootElement();
}

From source file:org.springframework.ws.server.endpoint.adapter.method.dom.Dom4jPayloadMethodProcessor.java

License:Apache License

@Override
protected Element resolveRequestPayloadArgument(MethodParameter parameter, Source requestPayload)
        throws TransformerException {
    if (requestPayload instanceof DOMSource) {
        org.w3c.dom.Node node = ((DOMSource) requestPayload).getNode();
        if (node.getNodeType() == org.w3c.dom.Node.DOCUMENT_NODE) {
            DOMReader domReader = new DOMReader();
            Document document = domReader.read((org.w3c.dom.Document) node);
            return document.getRootElement();
        }//from w ww.j a v a  2 s . c  o  m
    }
    // we have no other option than to transform
    DocumentResult dom4jResult = new DocumentResult();
    transform(requestPayload, dom4jResult);
    return dom4jResult.getDocument().getRootElement();
}