com.sun.xml.internal.bind.v2.runtime.output.XmlOutput Java Examples

The following examples show how to use com.sun.xml.internal.bind.v2.runtime.output.XmlOutput. 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: MarshallerImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #2
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #3
Source File: MarshallerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #4
Source File: MarshallerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #5
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #6
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #7
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #8
Source File: MarshallerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #9
Source File: MarshallerImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #10
Source File: MarshallerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #11
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #12
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #13
Source File: MarshallerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #14
Source File: MarshallerImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public XmlOutput createWriter( Writer w, String encoding ) {
    // XMLWriter doesn't do buffering, so do it here if it looks like a good idea
    if(!(w instanceof BufferedWriter))
        w = new BufferedWriter(w);

    assert toBeFlushed==null;
    toBeFlushed = w;

    CharacterEscapeHandler ceh = createEscapeHandler(encoding);
    XMLWriter xw;

    if(isFormattedOutput()) {
        DataWriter d = new DataWriter(w,encoding,ceh);
        d.setIndentStep(indent);
        xw=d;
    } else
        xw = new XMLWriter(w,encoding,ceh);

    xw.setXmlDecl(!isFragment());
    xw.setHeader(header);
    return new SAXOutput(xw);   // TODO: don't we need a better writer?
}
 
Example #15
Source File: MarshallerImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #16
Source File: MarshallerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
    serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
    if(postInitAction!=null)    postInitAction.run();
    if(prefixMapper!=null) {
        // be defensive as we work with the user's code
        String[] decls = prefixMapper.getContextualNamespaceDecls();
        if(decls!=null) { // defensive check
            for( int i=0; i<decls.length; i+=2 ) {
                String prefix = decls[i];
                String nsUri = decls[i+1];
                if(nsUri!=null && prefix!=null) // defensive check
                    serializer.addInscopeBinding(nsUri,prefix);
            }
        }
    }
    serializer.setPrefixMapper(prefixMapper);
}
 
Example #17
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates {@link XmlOutput} from the given {@link Result} object.
 */
final XmlOutput createXmlOutput(Result result) throws JAXBException {
    if (result instanceof SAXResult)
        return new SAXOutput(((SAXResult) result).getHandler());

    if (result instanceof DOMResult) {
        final Node node = ((DOMResult) result).getNode();

        if (node == null) {
            Document doc = JAXBContextImpl.createDom(getContext().disableSecurityProcessing);
            ((DOMResult) result).setNode(doc);
            return new SAXOutput(new SAX2DOMEx(doc));
        } else {
            return new SAXOutput(new SAX2DOMEx(node));
        }
    }
    if (result instanceof StreamResult) {
        StreamResult sr = (StreamResult) result;

        if (sr.getWriter() != null)
            return createWriter(sr.getWriter());
        else if (sr.getOutputStream() != null)
            return createWriter(sr.getOutputStream());
        else if (sr.getSystemId() != null) {
            String fileURL = sr.getSystemId();

            try {
                fileURL = new URI(fileURL).getPath();
            } catch (URISyntaxException use) {
                // otherwise assume that it's a file name
            }

            try {
                FileOutputStream fos = new FileOutputStream(fileURL);
                assert toBeClosed==null;
                toBeClosed = fos;
                return createWriter(fos);
            } catch (IOException e) {
                throw new MarshalException(e);
            }
        }
    }

    // unsupported parameter type
    throw new MarshalException(Messages.UNSUPPORTED_RESULT.format());
}
 
Example #18
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter(Writer w) {
    return createWriter(w, getEncoding());
}
 
Example #19
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void marshal(Object obj, XmlOutput output) throws JAXBException {
    write(obj, output, null );
}
 
Example #20
Source File: MarshallerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void marshal(Object obj, XmlOutput output) throws JAXBException {
    write(obj, output, null );
}
 
Example #21
Source File: MarshallerImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter( OutputStream os ) throws JAXBException {
    return createWriter(os, getEncoding());
}
 
Example #22
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void marshal(Object obj, XmlOutput output) throws JAXBException {
    write(obj, output, null );
}
 
Example #23
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates {@link XmlOutput} from the given {@link Result} object.
 */
final XmlOutput createXmlOutput(Result result) throws JAXBException {
    if (result instanceof SAXResult)
        return new SAXOutput(((SAXResult) result).getHandler());

    if (result instanceof DOMResult) {
        final Node node = ((DOMResult) result).getNode();

        if (node == null) {
            Document doc = JAXBContextImpl.createDom(getContext().disableSecurityProcessing);
            ((DOMResult) result).setNode(doc);
            return new SAXOutput(new SAX2DOMEx(doc));
        } else {
            return new SAXOutput(new SAX2DOMEx(node));
        }
    }
    if (result instanceof StreamResult) {
        StreamResult sr = (StreamResult) result;

        if (sr.getWriter() != null)
            return createWriter(sr.getWriter());
        else if (sr.getOutputStream() != null)
            return createWriter(sr.getOutputStream());
        else if (sr.getSystemId() != null) {
            String fileURL = sr.getSystemId();

            try {
                fileURL = new URI(fileURL).getPath();
            } catch (URISyntaxException use) {
                // otherwise assume that it's a file name
            }

            try {
                FileOutputStream fos = new FileOutputStream(fileURL);
                assert toBeClosed==null;
                toBeClosed = fos;
                return createWriter(fos);
            } catch (IOException e) {
                throw new MarshalException(e);
            }
        }
    }

    // unsupported parameter type
    throw new MarshalException(Messages.UNSUPPORTED_RESULT.format());
}
 
Example #24
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter(Writer w) {
    return createWriter(w, getEncoding());
}
 
Example #25
Source File: MarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter( OutputStream os ) throws JAXBException {
    return createWriter(os, getEncoding());
}
 
Example #26
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void marshal(Object obj, XmlOutput output) throws JAXBException {
    write(obj, output, null );
}
 
Example #27
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates {@link XmlOutput} from the given {@link Result} object.
 */
final XmlOutput createXmlOutput(Result result) throws JAXBException {
    if (result instanceof SAXResult)
        return new SAXOutput(((SAXResult) result).getHandler());

    if (result instanceof DOMResult) {
        final Node node = ((DOMResult) result).getNode();

        if (node == null) {
            Document doc = JAXBContextImpl.createDom(getContext().disableSecurityProcessing);
            ((DOMResult) result).setNode(doc);
            return new SAXOutput(new SAX2DOMEx(doc));
        } else {
            return new SAXOutput(new SAX2DOMEx(node));
        }
    }
    if (result instanceof StreamResult) {
        StreamResult sr = (StreamResult) result;

        if (sr.getWriter() != null)
            return createWriter(sr.getWriter());
        else if (sr.getOutputStream() != null)
            return createWriter(sr.getOutputStream());
        else if (sr.getSystemId() != null) {
            String fileURL = sr.getSystemId();

            try {
                fileURL = new URI(fileURL).getPath();
            } catch (URISyntaxException use) {
                // otherwise assume that it's a file name
            }

            try {
                FileOutputStream fos = new FileOutputStream(fileURL);
                assert toBeClosed==null;
                toBeClosed = fos;
                return createWriter(fos);
            } catch (IOException e) {
                throw new MarshalException(e);
            }
        }
    }

    // unsupported parameter type
    throw new MarshalException(Messages.UNSUPPORTED_RESULT.format());
}
 
Example #28
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter(Writer w) {
    return createWriter(w, getEncoding());
}
 
Example #29
Source File: MarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter( OutputStream os ) throws JAXBException {
    return createWriter(os, getEncoding());
}
 
Example #30
Source File: MarshallerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public XmlOutput createWriter(Writer w) {
    return createWriter(w, getEncoding());
}