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();
}
}
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);
}
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();
}
}
Aggregations