1 56 57 package org.jdom.transform; 58 59 import java.util.*; 60 import java.io.*; 61 import javax.xml.transform.*; 62 import javax.xml.transform.stream.StreamSource ; 63 import org.jdom.*; 64 65 116 public class XSLTransformer { 117 118 private static final String CVS_ID = 119 "@(#) $RCSfile: XSLTransformer.java,v $ $Revision: 1.2 $ $Date: 2004/02/06 09:28:32 $ $Name: $"; 120 121 private Templates templates; 122 123 private XSLTransformer(Source stylesheet) throws XSLTransformException { 125 try { 126 templates = TransformerFactory.newInstance() 127 .newTemplates(stylesheet); 128 } 129 catch (TransformerException e) { 130 throw new XSLTransformException("Could not construct XSLTransformer", e); 131 } 132 } 133 134 140 public XSLTransformer(String stylesheetSystemId) throws XSLTransformException { 141 this(new StreamSource (stylesheetSystemId)); 142 } 143 144 155 public XSLTransformer(InputStream stylesheet) throws XSLTransformException { 156 this(new StreamSource (stylesheet)); 157 } 158 159 170 public XSLTransformer(Reader stylesheet) throws XSLTransformException { 171 this(new StreamSource (stylesheet)); 172 } 173 174 185 public XSLTransformer(File stylesheet) throws XSLTransformException { 186 this(new StreamSource (stylesheet)); 187 } 188 189 200 public XSLTransformer(Document stylesheet) throws XSLTransformException { 201 this(new JDOMSource(stylesheet)); 202 } 203 204 211 public List transform(List inputNodes) throws XSLTransformException { 212 JDOMSource source = new JDOMSource(inputNodes); 213 JDOMResult result = new JDOMResult(); 214 try { 215 templates.newTransformer().transform(source, result); 216 return result.getResult(); 217 } 218 catch (TransformerException e) { 219 throw new XSLTransformException("Could not perform transformation", e); 220 } 221 } 222 223 230 public Document transform(Document inputDoc) throws XSLTransformException { 231 JDOMSource source = new JDOMSource(inputDoc); 232 JDOMResult result = new JDOMResult(); 233 try { 234 templates.newTransformer().transform(source, result); 235 return result.getDocument(); 236 } 237 catch (TransformerException e) { 238 throw new XSLTransformException("Could not perform transformation", e); 239 } 240 } 241 } 242 | Popular Tags |