1 16 package org.apache.roller.util; 17 18 import java.io.FileInputStream ; 19 import java.io.FileNotFoundException ; 20 import java.io.FileOutputStream ; 21 22 import javax.xml.transform.Result ; 23 import javax.xml.transform.Source ; 24 import javax.xml.transform.SourceLocator ; 25 import javax.xml.transform.Templates ; 26 import javax.xml.transform.Transformer ; 27 import javax.xml.transform.TransformerConfigurationException ; 28 import javax.xml.transform.TransformerException ; 29 import javax.xml.transform.TransformerFactory ; 30 import javax.xml.transform.stream.StreamResult ; 31 import javax.xml.transform.stream.StreamSource ; 32 33 37 public class XSLTransform 38 { 39 public static void main(String [] args) 40 { 41 if (args.length < 3) 42 { 43 System.out.println("USAGE: infile outfile xslfile"); 44 System.exit(-1); 45 } 46 String inFilename = args[0]; 47 String outFilename = args[1]; 48 String xslFilename = args[2]; 49 try 50 { 51 TransformerFactory factory = TransformerFactory.newInstance(); 53 54 Templates template = factory.newTemplates(new StreamSource ( 56 new FileInputStream (xslFilename))); 57 58 Transformer xformer = template.newTransformer(); 60 61 Source source = new StreamSource (new FileInputStream (inFilename)); 63 Result result = new StreamResult (new FileOutputStream (outFilename)); 64 65 xformer.transform(source, result); 68 } 69 catch (FileNotFoundException e) 70 { 71 e.printStackTrace(); 72 } 73 catch (TransformerConfigurationException e) 74 { 75 e.printStackTrace(); 77 } 78 catch (TransformerException e) 79 { 80 SourceLocator locator = e.getLocator(); 83 int col = locator.getColumnNumber(); 84 int line = locator.getLineNumber(); 85 String publicId = locator.getPublicId(); 86 String systemId = locator.getSystemId(); 87 System.out.println("ERROR: line = "+line+" col = "+col); 88 } 89 } 90 } | Popular Tags |