source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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