1 17 package org.apache.tools.ant.taskdefs.optional.junit; 18 19 import java.io.OutputStream ; 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 ; 26 27 34 public class Xalan1Executor extends XalanExecutor { 35 36 private static final String xsltP = "org.apache.xalan.xslt.XSLTProcessor"; 37 38 XSLTProcessor processor = null; 39 public Xalan1Executor() { 40 try { 41 processor = XSLTProcessorFactory.getProcessor(); 42 } catch (SAXException e) { 43 e.printStackTrace(); } 45 } 46 protected String getImplementation() { 47 return processor.getClass().getName(); 48 } 49 50 protected String getProcVersion(String classNameImpl) 51 throws BuildException { 52 try { 53 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 e){ 61 throw new BuildException("Could not find processor version " 62 + "implementation", e); 63 } 64 } 65 66 void execute() throws Exception { 67 processor.setStylesheetParam("output.dir", "'" 69 + caller.toDir.getAbsolutePath() + "'"); 70 XSLTInputSource xml_src = new XSLTInputSource(caller.document); 71 String system_id = caller.getStylesheetSystemId(); 72 XSLTInputSource xsl_src = new XSLTInputSource(system_id); 73 OutputStream 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 |