PR: 6852 Make XalanExecutor independent of Xalan2 so one can compile Xalan1Executor without Xalan2. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272185 13f79535-47bb-0310-9956-ffa450edef68master
@@ -188,8 +188,6 @@ | |||||
unless="xalan2.present" /> | unless="xalan2.present" /> | ||||
<exclude name="${optional.package}/junit/AggregateTransformer.java" | <exclude name="${optional.package}/junit/AggregateTransformer.java" | ||||
unless="xalan2.present" /> | unless="xalan2.present" /> | ||||
<exclude name="${optional.package}/junit/XalanExecutor.java" | |||||
unless="xalan2.present" /> | |||||
<exclude name="${optional.package}/junit/Xalan2Executor.java" | <exclude name="${optional.package}/junit/Xalan2Executor.java" | ||||
unless="xalan2.present" /> | unless="xalan2.present" /> | ||||
</patternset> | </patternset> | ||||
@@ -226,15 +226,26 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||||
* @throws IOException thrown if there is an error while writing the content. | * @throws IOException thrown if there is an error while writing the content. | ||||
*/ | */ | ||||
protected void writeDOMTree(Document doc, File file) throws IOException { | protected void writeDOMTree(Document doc, File file) throws IOException { | ||||
OutputStream out = new FileOutputStream( file ); | |||||
PrintWriter wri = new PrintWriter(new OutputStreamWriter(out, "UTF8")); | |||||
wri.write("<?xml version=\"1.0\"?>\n"); | |||||
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); | |||||
wri.flush(); | |||||
wri.close(); | |||||
// writers do not throw exceptions, so check for them. | |||||
if (wri.checkError()){ | |||||
throw new IOException("Error while writing DOM content"); | |||||
OutputStream out = null; | |||||
PrintWriter wri = null; | |||||
try { | |||||
out = new FileOutputStream( file ); | |||||
wri = new PrintWriter(new OutputStreamWriter(out, "UTF8")); | |||||
wri.write("<?xml version=\"1.0\"?>\n"); | |||||
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); | |||||
wri.flush(); | |||||
// writers do not throw exceptions, so check for them. | |||||
if (wri.checkError()){ | |||||
throw new IOException("Error while writing DOM content"); | |||||
} | |||||
} finally { | |||||
if (wri != null) { | |||||
wri.close(); | |||||
out = null; | |||||
} | |||||
if (out != null) { | |||||
out.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -76,7 +76,11 @@ public class Xalan1Executor extends XalanExecutor { | |||||
String system_id = caller.getStylesheetSystemId(); | String system_id = caller.getStylesheetSystemId(); | ||||
XSLTInputSource xsl_src = new XSLTInputSource(system_id); | XSLTInputSource xsl_src = new XSLTInputSource(system_id); | ||||
OutputStream os = getOutputStream(); | OutputStream os = getOutputStream(); | ||||
XSLTResultTarget target = new XSLTResultTarget(os); | |||||
processor.process( xml_src, xsl_src, target); | |||||
try { | |||||
XSLTResultTarget target = new XSLTResultTarget(os); | |||||
processor.process( xml_src, xsl_src, target); | |||||
} finally { | |||||
os.close(); | |||||
} | |||||
} | } | ||||
} | } |
@@ -77,8 +77,12 @@ public class Xalan2Executor extends XalanExecutor { | |||||
Transformer tformer = tfactory.newTransformer(xsl_src); | Transformer tformer = tfactory.newTransformer(xsl_src); | ||||
Source xml_src = new DOMSource(caller.document); | Source xml_src = new DOMSource(caller.document); | ||||
OutputStream os = getOutputStream(); | OutputStream os = getOutputStream(); | ||||
tformer.setParameter("output.dir", caller.toDir.getAbsolutePath()); | |||||
Result result = new StreamResult(os); | |||||
tformer.transform(xml_src, result); | |||||
try { | |||||
tformer.setParameter("output.dir", caller.toDir.getAbsolutePath()); | |||||
Result result = new StreamResult(os); | |||||
tformer.transform(xml_src, result); | |||||
} finally { | |||||
os.close(); | |||||
} | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights | |||||
* reserved. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -105,7 +105,8 @@ abstract class XalanExecutor { | |||||
XalanExecutor executor = null; | XalanExecutor executor = null; | ||||
try { | try { | ||||
procVersion = Class.forName("org.apache.xalan.processor.XSLProcessorVersion"); | procVersion = Class.forName("org.apache.xalan.processor.XSLProcessorVersion"); | ||||
executor = new Xalan2Executor(); | |||||
executor = (XalanExecutor) Class.forName( | |||||
"org.apache.tools.ant.taskdefs.optional.junit.Xalan2Executor").newInstance(); | |||||
} catch (Exception xalan2missing){ | } catch (Exception xalan2missing){ | ||||
try { | try { | ||||
procVersion = Class.forName("org.apache.xalan.xslt.XSLProcessorVersion"); | procVersion = Class.forName("org.apache.xalan.xslt.XSLProcessorVersion"); | ||||