Java Code Examples for com.sun.xml.internal.ws.util.xml.XmlUtil#newTransformer()

The following examples show how to use com.sun.xml.internal.ws.util.xml.XmlUtil#newTransformer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSchemaValidationTube.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example 2
Source File: AbstractSchemaValidationTube.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example 3
Source File: EPRHeader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
Example 4
Source File: MexEntityResolver.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example 5
Source File: MexEntityResolver.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example 6
Source File: MexEntityResolver.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example 7
Source File: MexEntityResolver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
    Transformer transformer = XmlUtil.newTransformer();
    for (Source source : wsdls) {
        XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
        try {
            transformer.transform(source, xsbr);
        } catch (TransformerException e) {
            throw new WebServiceException(e);
        }
        String systemId = source.getSystemId();

        //TODO: can we do anything if the given mex Source has no systemId?
        if(systemId != null){
            SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
            this.wsdls.put(systemId, doc);
        }
    }
}
 
Example 8
Source File: AbstractSchemaValidationTube.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example 9
Source File: AbstractSchemaValidationTube.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }

    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch(TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document)result.getNode();
}
 
Example 10
Source File: EPRHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
Example 11
Source File: LogicalMessageImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Source getPayload() {
    assert (!(payloadSrc instanceof DOMSource));
    try {
        Transformer transformer = XmlUtil.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(payloadSrc, domResult);
        DOMSource dom = new DOMSource(domResult.getNode());
        lm = new DOMLogicalMessageImpl((DOMSource) dom);
        payloadSrc = null;
        return dom;
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
}
 
Example 12
Source File: LogicalMessageImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Source getPayload() {
    assert (!(payloadSrc instanceof DOMSource));
    try {
        Transformer transformer = XmlUtil.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(payloadSrc, domResult);
        DOMSource dom = new DOMSource(domResult.getNode());
        lm = new DOMLogicalMessageImpl((DOMSource) dom);
        payloadSrc = null;
        return dom;
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
}
 
Example 13
Source File: LogicalMessageImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Source getPayload() {
    assert (!(payloadSrc instanceof DOMSource));
    try {
        Transformer transformer = XmlUtil.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(payloadSrc, domResult);
        DOMSource dom = new DOMSource(domResult.getNode());
        lm = new DOMLogicalMessageImpl((DOMSource) dom);
        payloadSrc = null;
        return dom;
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
}
 
Example 14
Source File: LogicalMessageImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Source getPayload() {
    assert (!(payloadSrc instanceof DOMSource));
    try {
        Transformer transformer = XmlUtil.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(payloadSrc, domResult);
        DOMSource dom = new DOMSource(domResult.getNode());
        lm = new DOMLogicalMessageImpl((DOMSource) dom);
        payloadSrc = null;
        return dom;
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
}
 
Example 15
Source File: LogicalMessageImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Source getPayload() {
    assert (!(payloadSrc instanceof DOMSource));
    try {
        Transformer transformer = XmlUtil.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(payloadSrc, domResult);
        DOMSource dom = new DOMSource(domResult.getNode());
        lm = new DOMLogicalMessageImpl((DOMSource) dom);
        payloadSrc = null;
        return dom;
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
}
 
Example 16
Source File: SourceReaderFactory.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static XMLStreamReader createSourceReader(Source source, boolean rejectDTDs, String charsetName) {
    try {
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            InputStream is = streamSource.getInputStream();

            if (is != null) {
                // Wrap input stream in Reader if charset is specified
                if (charsetName != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new InputStreamReader(is, charsetName), rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), is, rejectDTDs);
                }
            }
            else {
                Reader reader = streamSource.getReader();
                if (reader != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), reader, rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new URL(source.getSystemId()).openStream(), rejectDTDs );
                }
            }
        }
        else if (source.getClass() == fastInfosetSourceClass) {
            return FastInfosetUtil.createFIStreamReader((InputStream)
                fastInfosetSource_getInputStream.invoke(source));
        }
        else if (source instanceof DOMSource) {
            DOMStreamReader dsr =  new DOMStreamReader();
            dsr.setCurrentNode(((DOMSource) source).getNode());
            return dsr;
        }
        else if (source instanceof SAXSource) {
            // TODO: need SAX to StAX adapter here -- Use transformer for now
            Transformer tx =  XmlUtil.newTransformer();
            DOMResult domResult = new DOMResult();
            tx.transform(source, domResult);
            return createSourceReader(
                new DOMSource(domResult.getNode()),
                rejectDTDs);
        }
        else {
            throw new XMLReaderException("sourceReader.invalidSource",
                    source.getClass().getName());
        }
    }
    catch (Exception e) {
        throw new XMLReaderException(e);
    }
}
 
Example 17
Source File: XmlDataContentHandler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the object to a byte stream
 */
public void writeTo(Object obj, String mimeType, OutputStream os)
    throws IOException {

    if (!(obj instanceof DataSource || obj instanceof Source || obj instanceof String)) {
         throw new IOException("Invalid Object type = "+obj.getClass()+
            ". XmlDataContentHandler can only convert DataSource|Source|String to XML.");
    }

    ContentType ct = new ContentType(mimeType);
    if (!isXml(ct)) {
        throw new IOException(
            "Invalid content type \"" + mimeType + "\" for XmlDataContentHandler");
    }

    String charset = ct.getParameter("charset");
    if (obj instanceof String) {
        String s = (String) obj;
        if (charset == null) {
            charset = "utf-8";
        }
        OutputStreamWriter osw = new OutputStreamWriter(os, charset);
        osw.write(s, 0, s.length());
        osw.flush();
        return;
    }

    Source source = (obj instanceof DataSource)
            ? (Source)getContent((DataSource)obj) : (Source)obj;
    try {
        Transformer transformer = XmlUtil.newTransformer();
        if (charset != null) {
            transformer.setOutputProperty(OutputKeys.ENCODING, charset);
        }
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);
    } catch (Exception ex) {
        throw new IOException(
            "Unable to run the JAXP transformer in XmlDataContentHandler "
                + ex.getMessage());
    }
}
 
Example 18
Source File: SourceReaderFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static XMLStreamReader createSourceReader(Source source, boolean rejectDTDs, String charsetName) {
    try {
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            InputStream is = streamSource.getInputStream();

            if (is != null) {
                // Wrap input stream in Reader if charset is specified
                if (charsetName != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new InputStreamReader(is, charsetName), rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), is, rejectDTDs);
                }
            }
            else {
                Reader reader = streamSource.getReader();
                if (reader != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), reader, rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new URL(source.getSystemId()).openStream(), rejectDTDs );
                }
            }
        }
        else if (source.getClass() == fastInfosetSourceClass) {
            return FastInfosetUtil.createFIStreamReader((InputStream)
                fastInfosetSource_getInputStream.invoke(source));
        }
        else if (source instanceof DOMSource) {
            DOMStreamReader dsr =  new DOMStreamReader();
            dsr.setCurrentNode(((DOMSource) source).getNode());
            return dsr;
        }
        else if (source instanceof SAXSource) {
            // TODO: need SAX to StAX adapter here -- Use transformer for now
            Transformer tx =  XmlUtil.newTransformer();
            DOMResult domResult = new DOMResult();
            tx.transform(source, domResult);
            return createSourceReader(
                new DOMSource(domResult.getNode()),
                rejectDTDs);
        }
        else {
            throw new XMLReaderException("sourceReader.invalidSource",
                    source.getClass().getName());
        }
    }
    catch (Exception e) {
        throw new XMLReaderException(e);
    }
}
 
Example 19
Source File: XmlDataContentHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the object to a byte stream
 */
public void writeTo(Object obj, String mimeType, OutputStream os)
    throws IOException {

    if (!(obj instanceof DataSource || obj instanceof Source || obj instanceof String)) {
         throw new IOException("Invalid Object type = "+obj.getClass()+
            ". XmlDataContentHandler can only convert DataSource|Source|String to XML.");
    }

    ContentType ct = new ContentType(mimeType);
    if (!isXml(ct)) {
        throw new IOException(
            "Invalid content type \"" + mimeType + "\" for XmlDataContentHandler");
    }

    String charset = ct.getParameter("charset");
    if (obj instanceof String) {
        String s = (String) obj;
        if (charset == null) {
            charset = "utf-8";
        }
        OutputStreamWriter osw = new OutputStreamWriter(os, charset);
        osw.write(s, 0, s.length());
        osw.flush();
        return;
    }

    Source source = (obj instanceof DataSource)
            ? (Source)getContent((DataSource)obj) : (Source)obj;
    try {
        Transformer transformer = XmlUtil.newTransformer();
        if (charset != null) {
            transformer.setOutputProperty(OutputKeys.ENCODING, charset);
        }
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);
    } catch (Exception ex) {
        throw new IOException(
            "Unable to run the JAXP transformer in XmlDataContentHandler "
                + ex.getMessage());
    }
}
 
Example 20
Source File: XmlDataContentHandler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the object to a byte stream
 */
public void writeTo(Object obj, String mimeType, OutputStream os)
    throws IOException {

    if (!(obj instanceof DataSource || obj instanceof Source || obj instanceof String)) {
         throw new IOException("Invalid Object type = "+obj.getClass()+
            ". XmlDataContentHandler can only convert DataSource|Source|String to XML.");
    }

    ContentType ct = new ContentType(mimeType);
    if (!isXml(ct)) {
        throw new IOException(
            "Invalid content type \"" + mimeType + "\" for XmlDataContentHandler");
    }

    String charset = ct.getParameter("charset");
    if (obj instanceof String) {
        String s = (String) obj;
        if (charset == null) {
            charset = "utf-8";
        }
        OutputStreamWriter osw = new OutputStreamWriter(os, charset);
        osw.write(s, 0, s.length());
        osw.flush();
        return;
    }

    Source source = (obj instanceof DataSource)
            ? (Source)getContent((DataSource)obj) : (Source)obj;
    try {
        Transformer transformer = XmlUtil.newTransformer();
        if (charset != null) {
            transformer.setOutputProperty(OutputKeys.ENCODING, charset);
        }
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);
    } catch (Exception ex) {
        throw new IOException(
            "Unable to run the JAXP transformer in XmlDataContentHandler "
                + ex.getMessage());
    }
}