if (null != dumpFileName)
{
dumpWriter = new PrintWriter(new FileWriter(dumpFileName));
}
Templates stylesheet = null;
if (null != xslFileName)
{
if (flavor.equals("d2d"))
{
// Parse in the xml data into a DOM
DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
if (isSecureProcessing)
{
try
{
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
}
catch (ParserConfigurationException pce) {}
}
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
Node xslDOM = docBuilder.parse(new InputSource(xslFileName));
stylesheet = tfactory.newTemplates(new DOMSource(xslDOM,
xslFileName));
}
else
{
// System.out.println("Calling newTemplates: "+xslFileName);
stylesheet = tfactory.newTemplates(new StreamSource(xslFileName));
// System.out.println("Done calling newTemplates: "+xslFileName);
}
}
PrintWriter resultWriter;
StreamResult strResult;
if (null != outFileName)
{
strResult = new StreamResult(new FileOutputStream(outFileName));
// One possible improvement might be to ensure this is
// a valid URI before setting the systemId, but that
// might have subtle changes that pre-existing users
// might notice; we can think about that later -sc r1.46
strResult.setSystemId(outFileName);
}
else
{
strResult = new StreamResult(System.out);
// We used to default to incremental mode in this case.
// We've since decided that since the -INCREMENTAL switch is
// available, that default is probably not necessary nor
// necessarily a good idea.
}
SAXTransformerFactory stf = (SAXTransformerFactory) tfactory;
// This is currently controlled via TransformerFactoryImpl.
if (!useXSLTC && useSourceLocation)
stf.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
// Did they pass in a stylesheet, or should we get it from the
// document?
if (null == stylesheet)
{
Source source =
stf.getAssociatedStylesheet(new StreamSource(inFileName), media,
null, null);
if (null != source)
stylesheet = tfactory.newTemplates(source);
else
{
if (null != media)
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_IN_MEDIA, new Object[]{inFileName, media})); //"No stylesheet found in: "
// + inFileName + ", media="
// + media);
else
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_PI, new Object[]{inFileName})); //"No xml-stylesheet PI found in: "
//+ inFileName);
}
}
if (null != stylesheet)
{
Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer();
transformer.setErrorListener(new DefaultErrorHandler(false));
// Override the output format?
if (null != outputType)
{
transformer.setOutputProperty(OutputKeys.METHOD, outputType);
}
if (transformer instanceof org.apache.xalan.transformer.TransformerImpl)
{
org.apache.xalan.transformer.TransformerImpl impl = (org.apache.xalan.transformer.TransformerImpl)transformer;
TraceManager tm = impl.getTraceManager();
if (null != tracer)
tm.addTraceListener(tracer);
impl.setQuietConflictWarnings(quietConflictWarnings);
// This is currently controlled via TransformerFactoryImpl.
if (useSourceLocation)
impl.setProperty(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
if(recursionLimit>0)
impl.setRecursionLimit(recursionLimit);
// sc 28-Feb-01 if we re-implement this, please uncomment helpmsg in printArgOptions
// impl.setDiagnosticsOutput( setQuietMode ? null : diagnosticsWriter );
}
int nParams = params.size();
for (int i = 0; i < nParams; i += 2)
{
transformer.setParameter((String) params.elementAt(i),
(String) params.elementAt(i + 1));
}
if (uriResolver != null)
transformer.setURIResolver(uriResolver);
if (null != inFileName)
{
if (flavor.equals("d2d"))
{
// Parse in the xml data into a DOM
DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
dfactory.setCoalescing(true);
dfactory.setNamespaceAware(true);
if (isSecureProcessing)
{
try
{
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
}
catch (ParserConfigurationException pce) {}
}
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
if (entityResolver != null)
docBuilder.setEntityResolver(entityResolver);
Node xmlDoc = docBuilder.parse(new InputSource(inFileName));
Document doc = docBuilder.newDocument();
org.w3c.dom.DocumentFragment outNode =
doc.createDocumentFragment();
transformer.transform(new DOMSource(xmlDoc, inFileName),
new DOMResult(outNode));
// Now serialize output to disk with identity transformer
Transformer serializer = stf.newTransformer();
serializer.setErrorListener(new DefaultErrorHandler(false));
Properties serializationProps =
stylesheet.getOutputProperties();
serializer.setOutputProperties(serializationProps);
if (contentHandler != null)
{