private void doTransform() {
try {
final Class clazz = loadTranslet(_className);
final Translet translet = (Translet)clazz.newInstance();
// Create a SAX parser and get the XMLReader object it uses
final SAXParserFactory factory = SAXParserFactory.newInstance();
try {
factory.setFeature(Constants.NAMESPACE_FEATURE,true);
}
catch (Exception e) {
factory.setNamespaceAware(true);
}
final SAXParser parser = factory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
// Set the DOM's DOM builder as the XMLReader's SAX2 content handler
final DOMImpl dom = new DOMImpl();
DOMBuilder builder = dom.getBuilder();
reader.setContentHandler(builder);
try {
String prop = "http://xml.org/sax/properties/lexical-handler";
reader.setProperty(prop, builder);
}
catch (SAXException e) {
// quitely ignored
}
// Create a DTD monitor and pass it to the XMLReader object
final DTDMonitor dtdMonitor = new DTDMonitor(reader);
AbstractTranslet _translet = (AbstractTranslet)translet;
dom.setDocumentURI(_fileName);
if (_uri)
reader.parse(_fileName);
else
reader.parse(new File(_fileName).toURL().toExternalForm());
builder = null;
// If there are any elements with ID attributes, build an index
dtdMonitor.buildIdIndex(dom, 0, _translet);
// Pass unparsed entity descriptions to the translet
_translet.setDTDMonitor(dtdMonitor);
// Pass global parameters
int n = _params.size();
for (int i = 0; i < n; i++) {
Parameter param = (Parameter) _params.elementAt(i);
translet.addParameter(param._name, param._value);
}
// Transform the document
TransletOutputHandlerFactory tohFactory =
TransletOutputHandlerFactory.newInstance();
tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
tohFactory.setEncoding(_translet._encoding);
tohFactory.setOutputMethod(_translet._method);
if (_iterations == -1) {
translet.transform(dom, _useOldOutputSystem ?
tohFactory.getOldTransletOutputHandler() :
tohFactory.getTransletOutputHandler());
}
else if (_iterations > 0) {
long mm = System.currentTimeMillis();
for (int i = 0; i < _iterations; i++) {
translet.transform(dom, _useOldOutputSystem ?
tohFactory.getOldTransletOutputHandler() :
tohFactory.getTransletOutputHandler());
}
mm = System.currentTimeMillis() - mm;