1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.woopi.ant.taskdefs.junit;
18 import java.io.OutputStream;
19 import javax.xml.transform.Result;
20 import javax.xml.transform.Source;
21 import javax.xml.transform.Transformer;
22 import javax.xml.transform.TransformerFactory;
23 import javax.xml.transform.dom.DOMSource;
24 import javax.xml.transform.stream.StreamResult;
25 import javax.xml.transform.stream.StreamSource;
26
27 import org.apache.tools.ant.BuildException;
28
29 /***
30 * Xalan executor via JAXP. Nothing special must exists in the classpath
31 * besides of course, a parser, jaxp and xalan.
32 *
33 * @ant.task ignore="true"
34 */
35 public class Xalan2Executor extends XalanExecutor {
36
37 private static final String aPack = "org.apache.xalan.";
38 private static final String sPack = "com.sun.org.apache.xalan.";
39
40 private TransformerFactory tfactory = TransformerFactory.newInstance();
41
42 protected String getImplementation() throws BuildException {
43 return tfactory.getClass().getName();
44 }
45
46 protected String getProcVersion(String classNameImpl)
47 throws BuildException {
48 try {
49
50 if (classNameImpl.equals(aPack + "processor.TransformerFactoryImpl")
51 ||
52 classNameImpl.equals(aPack + "xslt.XSLTProcessorFactory")) {
53 return getXalanVersion(aPack + "processor.XSLProcessorVersion");
54 }
55
56 if (classNameImpl.equals(aPack
57 + "xsltc.trax.TransformerFactoryImpl")){
58 return getXSLTCVersion(aPack +"xsltc.ProcessorVersion");
59 }
60
61 if (classNameImpl
62 .equals(sPack + "internal.xsltc.trax.TransformerFactoryImpl")){
63 return getXSLTCVersion(sPack
64 + "internal.xsltc.ProcessorVersion");
65 }
66 throw new BuildException("Could not find a valid processor version"
67 + " implementation from "
68 + classNameImpl);
69 } catch (ClassNotFoundException e){
70 throw new BuildException("Could not find processor version "
71 + "implementation", e);
72 }
73 }
74
75 void execute() throws Exception {
76 String system_id = caller.getStylesheetSystemId();
77 Source xsl_src = new StreamSource(system_id);
78 Transformer tformer = tfactory.newTransformer(xsl_src);
79 Source xml_src = new DOMSource(caller.document);
80 OutputStream os = getOutputStream();
81 try {
82 tformer.setParameter("output.dir", caller.toDir.getAbsolutePath());
83 Result result = new StreamResult(os);
84 tformer.transform(xml_src, result);
85 } finally {
86 os.close();
87 }
88 }
89 }