Example usage for javax.xml.transform.dom DOMSource getNode

List of usage examples for javax.xml.transform.dom DOMSource getNode

Introduction

In this page you can find the example usage for javax.xml.transform.dom DOMSource getNode.

Prototype

public Node getNode() 

Source Link

Document

Get the node that represents a Source DOM tree.

Usage

From source file:Main.java

public static Set<Node> getRootNodes(DOMSource request) {
    return populateNodes(request.getNode(), new HashSet<Node>());
}

From source file:com.apress.prospringintegration.webservice.web.TicketIssuerEndpoint.java

@ServiceActivator
public Source handleRequest(DOMSource source) throws Exception {

    NodeList nodeList = source.getNode().getChildNodes();
    String description = "";
    String priority = "";

    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeName().equals("priority")) {
            priority = node.getFirstChild().getNodeValue();
        } else if (node.getNodeName().equals("description")) {
            description = node.getFirstChild().getNodeValue();
        }/*from   w  ww. j  a  v  a 2 s  .  c  o m*/
    }

    // Transfer properties to an XML document
    String xml = String.format(replyTemplate, description, priority, new Random().nextLong() * 1000,
            new Date());

    return new DomSourceFactory().createSource(xml);
}

From source file:edu.mayo.cts2.framework.core.xml.PatchedCastorMarshaller.java

protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {

    Node node = domSource.getNode();
    if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;

        Node parent = node.getParentNode();
        while (parent != null) {
            NamedNodeMap atts = parent.getAttributes();
            if (atts != null) {
                for (int i = 0, j = atts.getLength(); i < j; i++) {

                    Attr att = (Attr) atts.item(i);
                    if (XMLNS_NS.equals(att.getNamespaceURI())) {
                        String name = att.getName();
                        String value = att.getValue();
                        if (!element.hasAttributeNS(XMLNS_NS, name)) {
                            element.setAttributeNS(XMLNS_NS, name, value);
                        }/*from w w w.j  a  v a  2s .c  om*/
                    }

                }
            }
            parent = parent.getParentNode();
        }
    }

    return super.unmarshalDomSource(domSource);
}

From source file:com.nebhale.gpxconverter.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "", consumes = MediaType.APPLICATION_XML_VALUE, produces = APPLICATION_GPX_VALUE)
DOMSource gpx(@RequestBody DOMSource source) {
    this.logger.info("Augmenting existing GPX file");
    Document document = (Document) source.getNode();
    String name = this.parser.parseName(document);
    List<Point> points = this.parser.parsePoints(document);
    List<Point> augmentedPoints = this.augmenter.augment(points);

    return new DOMSource(this.routeBuilder.build(name, augmentedPoints));
}

From source file:ru.lanit.bpm.avatar.webservice.SimpleEchoResponder.java

public Source issueResponseFor(DOMSource request) {
    return new DomSourceFactory()
            .createSource("<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">"
                    + request.getNode().getTextContent() + "</echoResponse>");
}

From source file:org.brekka.phalanx.webservices.SoapExceptionResolver.java

private void resolveDetail(final MessageContext messageContext, final Throwable ex, final SoapFault soapFault) {
    SoapMessage request = (SoapMessage) messageContext.getRequest();
    DOMSource payloadSource = (DOMSource) request.getPayloadSource();
    Node node = payloadSource.getNode();
    String localName = node.getLocalName();
    String namespace = node.getNamespaceURI();
    String faultName = StringUtils.removeEnd(localName, "Request") + "Fault";
    QName faultQName = new QName(namespace, faultName);

    SchemaType schemaType = XmlBeans.getContextTypeLoader().findDocumentType(faultQName);
    if (schemaType != null) {
        try {/*  w w  w  . ja  va2  s.  co  m*/
            XmlObject faultDocument = prepareFaultDetail(messageContext, faultName, schemaType, ex);
            if (faultDocument != null) {
                // Add detailed
                StringWriter writer = new StringWriter();
                faultDocument.save(writer, SAVE_OPTIONS);
                Transformer transformer = transformerFactory.newTransformer();

                SoapFaultDetail faultDetail = soapFault.addFaultDetail();
                Result result = faultDetail.getResult();
                transformer.transform(new StreamSource(new StringReader(writer.toString())), result);
            }
        } catch (Exception e) {
            if (log.isWarnEnabled()) {
                log.warn(format("Failed to create custom fault message of type '%s'", schemaType), e);
            }
        }
    }
}

From source file:edu.colorado.orcid.impl.OrcidServicePublicImpl.java

private Document fetchDocument(String url) {
    DOMSource orcidInput = orcidRestTemplate.getForObject(url, DOMSource.class);
    return (Document) orcidInput.getNode();
}

From source file:org.cleverbus.core.common.exception.AbstractSoapExceptionFilter.java

/**
 * Gets exception from fault detail.// w w  w.j  a  v a 2s .  c  o m
 * <p/>
 * If there is no fault detail then no exception is returned.
 * If there is no supported exception in fault detail then {@link IntegrationException} is returned.
 *
 * @param faultDetail the fault detail
 * @return exception
 */
@Nullable
private Exception getFaultException(@Nullable SoapFaultDetail faultDetail) {
    if (faultDetail != null) {
        DOMSource detailSource = (DOMSource) faultDetail.getSource();
        Node detailNode = detailSource.getNode();

        QName exName = getExceptionName(detailNode);

        Exception exception = createException(exName, detailNode);
        if (exception == null) {
            // throws common exception with specified exception
            exception = new IntegrationException(getErrorCodeForException(null), exName.getLocalPart());
        }

        return exception;
    }

    return null;
}

From source file:edu.colorado.orcid.impl.OrcidServicePublicImpl.java

protected Document fetchOrcidDocument(String url) throws OrcidHttpException {

    try {/*from  www  . ja  v  a 2s .  co m*/
        ResponseEntity<DOMSource> responseEntity = orcidRestTemplate.getForEntity(url, DOMSource.class);
        HttpStatus statusCode = responseEntity.getStatusCode();
        DOMSource orcidInput = responseEntity.getBody();
        Document orcidDocument = (Document) orcidInput.getNode();

        // Handle deprecated ORCID iD, which returns HTTP 301 status code
        if (statusCode == HttpStatus.MOVED_PERMANENTLY) {
            OrcidHttpException e = new OrcidHttpException("ORCID iD Deprecated");
            e.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
            try {
                e.setDocument(OrcidUtil.documentXml(orcidDocument));
            } catch (TransformerException te) {
                String msg = "Error setting XML document: " + te.getMessage();
                e.setDocument(msg);
            }
            String errorDesc = orcidDocument.getElementsByTagName("error-desc").item(0).getTextContent();
            e.setOrcidPrimaryRecord(extractOrcid(errorDesc)); //Set ORCID primary record value in exception
            throw e;
        } else if (!(statusCode == HttpStatus.OK)) {
            OrcidHttpException e = new OrcidHttpException("Error fetching URL: " + url);
            e.getStatusCode();
            try {
                e.setDocument(OrcidUtil.documentXml(orcidDocument));
            } catch (TransformerException te) {
                String msg = "Error setting XML document: " + te.getMessage();
                e.setDocument(msg);
            }
            throw e;
        }

        return orcidDocument;

    } catch (HttpClientErrorException e) {
        OrcidHttpException ohe = new OrcidHttpException(e);
        ohe.setStatusCode(e.getStatusCode());
        throw ohe;
    }
}

From source file:be.e_contract.mycarenet.ehbox.EHealthBoxConsultationClient.java

private Element toElement(Source source) {
    if (source instanceof DOMSource) {
        DOMSource domSource = (DOMSource) source;
        return (Element) domSource.getNode();
    }/*from www .j a  va2 s .  c  o m*/
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = transformerFactory.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException(e);
    }
    DOMResult domResult = new DOMResult();
    try {
        transformer.transform(source, domResult);
    } catch (TransformerException e) {
        throw new RuntimeException(e);
    }
    Document document = (Document) domResult.getNode();
    return (Element) document.getDocumentElement();
}