KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > junit > Xalan1Executor


1 /*
2  * Copyright 2001-2002,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.tools.ant.taskdefs.optional.junit;
18
19 import java.io.OutputStream JavaDoc;
20 import org.apache.xalan.xslt.XSLTInputSource;
21 import org.apache.xalan.xslt.XSLTProcessor;
22 import org.apache.xalan.xslt.XSLTProcessorFactory;
23 import org.apache.xalan.xslt.XSLTResultTarget;
24 import org.apache.tools.ant.BuildException;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * Xalan 1 executor. It will need a lot of things in the classpath:
29  * xerces for the serialization, xalan and bsf for the extension.
30  * @todo do everything via reflection to avoid compile problems ?
31  *
32  * @ant.task ignore="true"
33  */

34 public class Xalan1Executor extends XalanExecutor {
35
36     private static final String JavaDoc xsltP = "org.apache.xalan.xslt.XSLTProcessor";
37
38     XSLTProcessor processor = null;
39     public Xalan1Executor() {
40         try {
41             processor = XSLTProcessorFactory.getProcessor();
42         } catch (SAXException JavaDoc e) {
43             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
44
}
45     }
46     protected String JavaDoc getImplementation() {
47         return processor.getClass().getName();
48     }
49
50     protected String JavaDoc getProcVersion(String JavaDoc classNameImpl)
51         throws BuildException {
52         try {
53             // xalan 1
54
if (classNameImpl.equals(xsltP)){
55                 return getXalanVersion(xsltP + "Version");
56             }
57             throw new BuildException("Could not find a valid processor version"
58                                      + " implementation from "
59                                      + classNameImpl);
60         } catch (ClassNotFoundException JavaDoc e){
61             throw new BuildException("Could not find processor version "
62                                      + "implementation", e);
63         }
64     }
65
66     void execute() throws Exception JavaDoc {
67         // need to quote otherwise it breaks because of "extra illegal tokens"
68
processor.setStylesheetParam("output.dir", "'"
69                                      + caller.toDir.getAbsolutePath() + "'");
70         XSLTInputSource xml_src = new XSLTInputSource(caller.document);
71         String JavaDoc system_id = caller.getStylesheetSystemId();
72         XSLTInputSource xsl_src = new XSLTInputSource(system_id);
73         OutputStream JavaDoc os = getOutputStream();
74         try {
75             XSLTResultTarget target = new XSLTResultTarget(os);
76             processor.process(xml_src, xsl_src, target);
77         } finally {
78             os.close();
79         }
80     }
81 }
82
Popular Tags