Search in sources :

Example 1 with DataWriter

use of org.glassfish.jaxb.core.marshaller.DataWriter in project metro-jax-ws by eclipse-ee4j.

the class DOMForest method dump.

/**
 * Dumps the contents of the forest to the specified stream.
 * <br>
 * This is a debug method. As such, error handling is sloppy.
 */
public void dump(OutputStream out) throws IOException {
    try {
        // create identity transformer
        // secure xml processing can be switched off if input requires it
        boolean secureProcessingEnabled = options == null || !options.disableXmlSecurity;
        TransformerFactory tf = XmlUtil.newTransformerFactory(secureProcessingEnabled);
        Transformer it = tf.newTransformer();
        for (Map.Entry<String, Document> e : core.entrySet()) {
            out.write(("---<< " + e.getKey() + '\n').getBytes());
            DataWriter dw = new DataWriter(new OutputStreamWriter(out), null);
            dw.setIndentStep("  ");
            it.transform(new DOMSource(e.getValue()), new SAXResult(dw));
            out.write("\n\n\n".getBytes());
        }
    } catch (TransformerException e) {
        e.printStackTrace();
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) SAXResult(javax.xml.transform.sax.SAXResult) OutputStreamWriter(java.io.OutputStreamWriter) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) DataWriter(org.glassfish.jaxb.core.marshaller.DataWriter)

Example 2 with DataWriter

use of org.glassfish.jaxb.core.marshaller.DataWriter in project eclipselink by eclipse-ee4j.

the class MapNamespaceTestCases method testObjectToXMLWithContentHandler.

public void testObjectToXMLWithContentHandler() throws Exception {
    Object objectToWrite = getWriteControlObject();
    StringWriter writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", new DummyCharacterEscapeHandler());
    XMLDescriptor desc = null;
    if (objectToWrite instanceof XMLRoot) {
        desc = (XMLDescriptor) xmlContext.getSession(0).getProject().getDescriptor(((XMLRoot) objectToWrite).getObject().getClass());
    } else {
        desc = (XMLDescriptor) xmlContext.getSession(0).getProject().getDescriptor(objectToWrite.getClass());
    }
    int sizeBefore = getNamespaceResolverSize(desc);
    jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml");
    jaxbMarshaller.setProperty("org.glassfish.jaxb.xmlDeclaration", Boolean.FALSE);
    try {
        jaxbMarshaller.marshal(objectToWrite, dataWriter);
    } catch (Exception e) {
        assertMarshalException(e);
        return;
    }
    if (expectsMarshalException) {
        fail("An exception should have occurred but didn't.");
        return;
    }
    int sizeAfter = getNamespaceResolverSize(desc);
    assertEquals(sizeBefore, sizeAfter);
    Document testDocument = getTestDocument(writer.toString());
    writer.close();
    objectToXMLDocumentTest(testDocument);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) StringWriter(java.io.StringWriter) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) Document(org.w3c.dom.Document) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) DataWriter(org.glassfish.jaxb.core.marshaller.DataWriter)

Example 3 with DataWriter

use of org.glassfish.jaxb.core.marshaller.DataWriter in project jaxb-ri by eclipse-ee4j.

the class DOMForest method dump.

/**
 * Dumps the contents of the forest to the specified stream.
 *
 * This is a debug method. As such, error handling is sloppy.
 */
public void dump(OutputStream out) throws IOException {
    try {
        // create identity transformer
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        TransformerFactory tf = XmlFactory.createTransformerFactory(disableXmlSecurity);
        Transformer it = tf.newTransformer();
        for (Map.Entry<String, Document> e : core.entrySet()) {
            out.write(("---<< " + e.getKey() + '\n').getBytes());
            DataWriter dw = new DataWriter(new OutputStreamWriter(out), null);
            dw.setIndentStep("  ");
            it.transform(new DOMSource(e.getValue()), new SAXResult(dw));
            out.write("\n\n\n".getBytes());
        }
    } catch (TransformerException e) {
        e.printStackTrace();
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) SAXResult(javax.xml.transform.sax.SAXResult) OutputStreamWriter(java.io.OutputStreamWriter) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) DataWriter(org.glassfish.jaxb.core.marshaller.DataWriter)

Aggregations

DataWriter (org.glassfish.jaxb.core.marshaller.DataWriter)3 Document (org.w3c.dom.Document)3 OutputStreamWriter (java.io.OutputStreamWriter)2 Transformer (javax.xml.transform.Transformer)2 TransformerException (javax.xml.transform.TransformerException)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 DOMSource (javax.xml.transform.dom.DOMSource)2 SAXResult (javax.xml.transform.sax.SAXResult)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)1