boolean reCreate = false;
OMNode sourceNode = getTransformSource(synCtx);
OutputStream osForTarget = null;
InputStream isForSource = null;
ByteArrayOutputStream baosForTarget = new FixedByteArrayOutputStream(BYTE_ARRAY_SIZE);
File tempTargetFile = null;
File tempSourceFile = null;
boolean isSoapEnvelope = (sourceNode == synCtx.getEnvelope());
boolean isSoapBody = (sourceNode == synCtx.getEnvelope().getBody());
if (traceOrDebugOn) {
trace.trace("Transformation source : " + sourceNode.toString());
}
Source transformSrc = null;
Result transformTgt = null;
if (useDOMSourceAndResults) {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Using a DOMSource for transformation");
}
// for fast transformations create a DOMSource - ** may not work always though **
transformSrc = new DOMSource(
((Element) ElementHelper.importOMElement((OMElement) sourceNode,
DOOMAbstractFactory.getOMFactory())).getOwnerDocument());
DocumentBuilderFactoryImpl.setDOOMRequired(true);
try {
transformTgt = new DOMResult(
DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder().newDocument());
} catch (ParserConfigurationException e) {
handleException("Error creating a DOMResult for the transformation," +
" Consider setting optimization feature : " + USE_DOM_SOURCE_AND_RESULTS +
" off", e, synCtx);
}
} else {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Using byte array serialization for transformation");
}
try {
// create a byte array output stream and serialize the source node into it
ByteArrayOutputStream baosForSource = new FixedByteArrayOutputStream(BYTE_ARRAY_SIZE);
XMLStreamWriter xsWriterForSource = XMLOutputFactory.newInstance().
createXMLStreamWriter(baosForSource);
sourceNode.serialize(xsWriterForSource);
isForSource = new ByteArrayInputStream(baosForSource.toByteArray());
transformSrc = new StreamSource(isForSource);
transformTgt = new StreamResult(baosForTarget);
} catch (XMLStreamException e) {
handleException("Error creating a StreamResult for the transformation", e, synCtx);