1 5 6 package mc.formgenerator.ggf.xslprocessing; 7 import java.io.FileNotFoundException ; 8 import java.io.FileOutputStream ; 9 import java.io.IOException ; 10 11 import javax.xml.transform.Transformer ; 12 import javax.xml.transform.TransformerConfigurationException ; 13 import javax.xml.transform.TransformerException ; 14 import javax.xml.transform.TransformerFactory ; 15 import javax.xml.transform.dom.DOMResult ; 16 import javax.xml.transform.dom.DOMSource ; 17 import javax.xml.transform.stream.StreamResult ; 18 import javax.xml.transform.stream.StreamSource ; 19 20 import org.apache.xerces.dom.DOMImplementationImpl; 21 import org.w3c.dom.DOMImplementation ; 22 import org.w3c.dom.Document ; 23 import org.w3c.dom.Element ; 24 import org.w3c.dom.NamedNodeMap ; 25 import org.w3c.dom.Node ; 26 import org.w3c.dom.NodeList ; 27 28 29 33 public class XalanExecutor { 34 35 public String xmlFile; 37 38 public String xslFile; 40 41 public String outputFile; 43 44 public Transformer transformer = null; 45 46 49 public XalanExecutor(){}; 50 51 52 53 54 59 public XalanExecutor(String theXslFile, String userLanguage, String fileXformsBonita) 60 throws TransformerConfigurationException 61 { 62 xslFile = theXslFile; 64 65 TransformerFactory tFactory = TransformerFactory.newInstance(); 67 68 transformer = tFactory.newTransformer(new StreamSource ( xslFile )); 70 transformer.setParameter("language", userLanguage); 72 transformer.setParameter("fileXformsBonita", fileXformsBonita); 74 } 75 76 public static XalanExecutor xalanExecutorFormURL(String theXslFile, String userLanguage, String fileXformsBonita) 77 throws TransformerConfigurationException 78 { 79 XalanExecutor n = new XalanExecutor(); 80 81 n.xslFile = theXslFile; 83 84 TransformerFactory tFactory = TransformerFactory.newInstance(); 86 87 n.transformer = tFactory.newTransformer(new StreamSource ( theXslFile )); 89 91 n.transformer.setParameter("language", userLanguage); 92 n.transformer.setParameter("fileXformsBonita", fileXformsBonita); 93 return n; 94 }; 95 96 97 98 99 109 public void XalanExecution(String theXmlFile, String theXslFile, String theOutputFile) 110 throws TransformerException , TransformerConfigurationException , 111 FileNotFoundException , IOException { 112 113 TransformerFactory tFactory = TransformerFactory.newInstance(); 115 116 Transformer transformer = tFactory.newTransformer(new StreamSource ( theXslFile )); 118 119 transformer.setParameter("language","en"); 121 122 transformer.transform(new StreamSource ( theXmlFile ), new StreamResult (new FileOutputStream ( theOutputFile ))); 124 } 125 126 127 128 129 140 public Document XalanExecutionDOM(Document document, String xmlBase) 141 throws TransformerException , TransformerConfigurationException , 142 FileNotFoundException , IOException { 143 144 DOMResult outputDOM = new DOMResult (); 146 147 transformer.transform( new DOMSource (document), outputDOM); 149 150 Document documentOutput = (Document )outputDOM.getNode(); 151 152 Element root = documentOutput.getDocumentElement(); 154 root.setAttribute("xml:base",xmlBase); 155 156 return documentOutput; 158 } 159 160 } 161 | Popular Tags |