KickJava   Java API By Example, From Geeks To Geeks.

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


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

18 package org.apache.tools.ant.taskdefs.optional.junit;
19
20 import java.io.OutputStream JavaDoc;
21 import javax.xml.transform.Result JavaDoc;
22 import javax.xml.transform.Source JavaDoc;
23 import javax.xml.transform.Transformer JavaDoc;
24 import javax.xml.transform.TransformerFactory JavaDoc;
25 import javax.xml.transform.dom.DOMSource JavaDoc;
26 import javax.xml.transform.stream.StreamResult JavaDoc;
27 import javax.xml.transform.stream.StreamSource JavaDoc;
28
29 import org.apache.tools.ant.BuildException;
30
31 /**
32  * This class is not used by the framework any more.
33  * We plan to remove it in Ant 1.8
34  * @deprecated since Ant 1.7
35  *
36  *
37  * @ant.task ignore="true"
38  */

39 public class Xalan2Executor extends XalanExecutor {
40
41     private static final String JavaDoc APAC = "org.apache.xalan.";
42     private static final String JavaDoc SPAC = "com.sun.org.apache.xalan.";
43
44     private TransformerFactory JavaDoc tfactory = TransformerFactory.newInstance();
45
46     /** {@inheritDoc}. */
47     protected String JavaDoc getImplementation() throws BuildException {
48         return tfactory.getClass().getName();
49     }
50
51     /** {@inheritDoc}. */
52     protected String JavaDoc getProcVersion(String JavaDoc classNameImpl)
53         throws BuildException {
54         try {
55             // xalan 2
56
if (classNameImpl.equals(APAC + "processor.TransformerFactoryImpl")
57                 ||
58                 classNameImpl.equals(APAC + "xslt.XSLTProcessorFactory")) {
59                 return getXalanVersion(APAC + "processor.XSLProcessorVersion");
60             }
61             // xalan xsltc
62
if (classNameImpl.equals(APAC
63                                      + "xsltc.trax.TransformerFactoryImpl")) {
64                 return getXSLTCVersion(APAC + "xsltc.ProcessorVersion");
65             }
66             // jdk 1.5 xsltc
67
if (classNameImpl
68                 .equals(SPAC + "internal.xsltc.trax.TransformerFactoryImpl")) {
69                 return getXSLTCVersion(SPAC
70                                        + "internal.xsltc.ProcessorVersion");
71             }
72             throw new BuildException("Could not find a valid processor version"
73                                      + " implementation from "
74                                      + classNameImpl);
75         } catch (ClassNotFoundException JavaDoc e) {
76             throw new BuildException("Could not find processor version "
77                                      + "implementation", e);
78         }
79     }
80
81     /** {@inheritDoc}. */
82     void execute() throws Exception JavaDoc {
83         String JavaDoc systemId = caller.getStylesheetSystemId();
84         Source JavaDoc xslSrc = new StreamSource JavaDoc(systemId);
85         Transformer JavaDoc tformer = tfactory.newTransformer(xslSrc);
86         Source JavaDoc xmlSrc = new DOMSource JavaDoc(caller.document);
87         OutputStream JavaDoc os = getOutputStream();
88         try {
89             tformer.setParameter("output.dir", caller.toDir.getAbsolutePath());
90             Result JavaDoc result = new StreamResult JavaDoc(os);
91             tformer.transform(xmlSrc, result);
92         } finally {
93             os.close();
94         }
95     }
96 }
97
Popular Tags