transformParameters.put(key, value);
}
}
}
SAXEventBufferImpl seb = new SAXEventBufferImpl ();
try {
SAXResult saxResult = new SAXResult (new BodyCleaner(seb));
Templates tmplts = templates ();
TransformerHandler th = null;
if (tmplts == null) {
th = saxTransFact().newTransformerHandler();
} else {
th = saxTransFact().newTransformerHandler(tmplts);
}
setTransformerParameters(th.getTransformer(), transformParameters);
th.setResult(saxResult);
if (newRootTag == null) {
// simple input tree
((SAXEventBuffer)contentParameters.get(0)).emit(th);
} else {
// create new start element
th.startDocument();
th.startElement
("", newRootTag, newRootTag, new AttributesImpl());
// content
Iterator it = contentParameters.iterator();
while (it.hasNext()) {
SAXEventBuffer c = (SAXEventBuffer)it.next();
c.emit(new BodyFilter(th));
}
th.endElement("", newRootTag, newRootTag);
th.endDocument();
}
seb.pack();
} catch (TransformerConfigurationException e) {
String msg = "Error creating TransformerHandler: " + e.getMessage();
logger.error(msg, e);
throw new CannotExecuteException (msg);
} catch (SAXException se) {
String msg = "Error during transformation: " + se.getMessage();
logger.error (msg, se);
throw new CannotExecuteException (msg);
}
if (logger.isDebugEnabled()) {
logTransformationResult (seb);
}
// assemble the result, do additional mapping
Map resData = new HashMap ();
Document jdomRes = null;
for (int i = 0; i < formPars.length; i++) {
if (logger.isDebugEnabled()) {
logger.debug("formPars[i].id() = " + formPars[i].id());
logger.debug("formPars[i].type() = " + formPars[i].type());
logger.debug("formPars[i].mode() = " + formPars[i].mode());
}
if (formPars[i].mode() == FormalParameter.Mode.IN) {
continue;
}
XPath path = (XPath)returnParamInfo.get(formPars[i].id());
if (logger.isDebugEnabled()) {
logger.debug("path = " + path);
}
if (path == null) {
resData.put(formPars[i].id(), seb);
continue;
}
// Handle path expression
if (jdomRes == null) {
try {
SAXHandler hdlr = new SAXHandler ();
seb.emit (hdlr);
jdomRes = hdlr.getDocument();
} catch (SAXException e) {
String msg = "Problem converting SAX to JDOM: "
+ e.getMessage ();
logger.error (msg, e);