1 17 18 package org.apache.tools.ant.taskdefs.optional; 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.FileOutputStream ; 23 import java.io.IOException ; 24 import org.apache.tools.ant.taskdefs.XSLTLiaison; 25 import org.apache.xalan.xslt.XSLTInputSource; 26 import org.apache.xalan.xslt.XSLTProcessor; 27 import org.apache.xalan.xslt.XSLTProcessorFactory; 28 import org.apache.xalan.xslt.XSLTResultTarget; 29 30 35 public class XalanLiaison implements XSLTLiaison { 36 37 protected XSLTProcessor processor; 38 protected File stylesheet; 39 40 public XalanLiaison() throws Exception { 41 processor = XSLTProcessorFactory.getProcessor(); 42 } 43 44 public void setStylesheet(File stylesheet) throws Exception { 45 this.stylesheet = stylesheet; 46 } 47 48 public void transform(File infile, File outfile) throws Exception { 49 FileInputStream fis = null; 50 FileOutputStream fos = null; 51 FileInputStream xslStream = null; 52 try { 53 xslStream = new FileInputStream (stylesheet); 54 fis = new FileInputStream (infile); 55 fos = new FileOutputStream (outfile); 56 XSLTInputSource xslSheet = new XSLTInputSource(xslStream); 59 xslSheet.setSystemId(stylesheet.getAbsolutePath()); 60 XSLTInputSource src = new XSLTInputSource(fis); 61 src.setSystemId(infile.getAbsolutePath()); 62 XSLTResultTarget res = new XSLTResultTarget(fos); 63 processor.process(src, xslSheet, res); 64 } finally { 65 try { 69 if (xslStream != null) { 70 xslStream.close(); 71 } 72 } catch (IOException ignored) { 73 } 75 try { 76 if (fis != null) { 77 fis.close(); 78 } 79 } catch (IOException ignored) { 80 } 82 try { 83 if (fos != null) { 84 fos.close(); 85 } 86 } catch (IOException ignored) { 87 } 89 } 90 } 91 92 public void addParam(String name, String value) { 93 processor.setStylesheetParam(name, value); 94 } 95 96 } | Popular Tags |