6 * Copyright 2001-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: TransformerImpl.java,v 1.10 2007/06/13 01:57:09 joehw Exp $ 22 */ 23 24 package com.sun.org.apache.xalan.internal.xsltc.trax; 25 26 import com.sun.org.apache.xalan.internal.utils.FactoryImpl; 27 import java.io.File; 28 import java.io.FileOutputStream; 29 import java.io.IOException; 30 import java.io.InputStream; 31 import java.io.OutputStream; 32 import java.io.Reader; 33 import java.io.Writer; 34 import java.net.URI; 35 import java.net.URL; 36 import java.net.URLConnection; 37 import java.net.UnknownServiceException; 38 import java.util.Enumeration; 39 import java.util.Properties; 40 import java.util.StringTokenizer; 41 import java.util.Vector; 42 import java.lang.reflect.Constructor; 43 44 import javax.xml.parsers.DocumentBuilder; 45 import javax.xml.parsers.DocumentBuilderFactory; 46 import javax.xml.parsers.ParserConfigurationException; 47 import javax.xml.stream.XMLEventReader; 48 import javax.xml.stream.XMLStreamReader; 49 import javax.xml.transform.ErrorListener; 50 import javax.xml.transform.OutputKeys; 51 import javax.xml.transform.Result; 52 import javax.xml.transform.Source; 53 import javax.xml.transform.Transformer; 54 import javax.xml.transform.TransformerException; 55 import javax.xml.transform.URIResolver; 56 import javax.xml.transform.dom.DOMResult; 57 import javax.xml.transform.dom.DOMSource; 58 import javax.xml.transform.sax.SAXResult; 59 import javax.xml.transform.sax.SAXSource; 60 import javax.xml.transform.stax.StAXResult; 61 import javax.xml.transform.stax.StAXSource; 62 import javax.xml.transform.stream.StreamResult; 63 import javax.xml.transform.stream.StreamSource; 64 65 import com.sun.org.apache.xml.internal.utils.SystemIDResolver; 66 67 import com.sun.org.apache.xalan.internal.xsltc.DOM; 68 import com.sun.org.apache.xalan.internal.xsltc.DOMCache; 69 import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM; 70 import com.sun.org.apache.xalan.internal.xsltc.StripFilter; 71 import com.sun.org.apache.xalan.internal.xsltc.Translet; 72 import com.sun.org.apache.xalan.internal.xsltc.TransletException; 73 import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory; 74 import com.sun.org.apache.xml.internal.serializer.SerializationHandler; 75 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 76 import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter; 77 import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl; 78 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; 79 import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; 80 import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable; 81 import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory; 82 83 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter; 190 */ 191 //private boolean _isIncremental = false; 192 193 /** 194 * A flag indicating whether this transformer implements the identity 195 * transform. 196 */ 197 private boolean _isIdentity = false; 198 199 /** 200 * State of the secure processing feature. 201 */ 202 private boolean _isSecureProcessing = false; 203 204 /** 205 * Indicates whether implementation parts should use 206 * service loader (or similar). 207 * Note the default value (false) is the safe option.. 208 */ 209 private boolean _useServicesMechanism; 210 211 /** 212 * A hashtable to store parameters for the identity transform. These 213 * are not needed during the transformation, but we must keep track of 214 * them to be fully complaint with the JAXP API. 215 */ 216 private Hashtable _parameters = null; 217 218 /** 219 * This class wraps an ErrorListener into a MessageHandler in order to 220 * capture messages reported via xsl:message. 221 */ 222 static class MessageHandler 223 extends com.sun.org.apache.xalan.internal.xsltc.runtime.MessageHandler 224 { 225 private ErrorListener _errorListener; 226 227 public MessageHandler(ErrorListener errorListener) { 228 _errorListener = errorListener; 229 } 243 } 244 } 245 246 protected TransformerImpl(Properties outputProperties, int indentNumber, 247 TransformerFactoryImpl tfactory) 248 { 249 this(null, outputProperties, indentNumber, tfactory); 250 _isIdentity = true; 251 // _properties.put(OutputKeys.METHOD, "xml"); 252 } 253 254 protected TransformerImpl(Translet translet, Properties outputProperties, 255 int indentNumber, TransformerFactoryImpl tfactory) 256 { 257 _translet = (AbstractTranslet) translet; 258 _properties = createOutputProperties(outputProperties); 259 _propertiesClone = (Properties) _properties.clone(); 260 _indentNumber = indentNumber; 261 _tfactory = tfactory; 262 _useServicesMechanism = _tfactory.useServicesMechnism(); 263 _readerManager = XMLReaderManager.getInstance(_useServicesMechanism); 264 //_isIncremental = tfactory._incremental; 265 } 266 267 /** 268 * Return the state of the secure processing feature. 269 */ 270 public boolean isSecureProcessing() { 271 return _isSecureProcessing; 272 } 273 274 /** 275 * Set the state of the secure processing feature. 276 */ 277 public void setSecureProcessing(boolean flag) { 278 _isSecureProcessing = flag; 279 } 280 /** 281 * Return the state of the services mechanism feature. 282 */ 283 public boolean useServicesMechnism() { | 6 * Copyright 2001-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: TransformerImpl.java,v 1.10 2007/06/13 01:57:09 joehw Exp $ 22 */ 23 24 package com.sun.org.apache.xalan.internal.xsltc.trax; 25 26 import com.sun.org.apache.xalan.internal.XalanConstants; 27 import com.sun.org.apache.xalan.internal.utils.FactoryImpl; 28 import java.io.File; 29 import java.io.FileOutputStream; 30 import java.io.IOException; 31 import java.io.InputStream; 32 import java.io.OutputStream; 33 import java.io.Reader; 34 import java.io.Writer; 35 import java.net.URI; 36 import java.net.URL; 37 import java.net.URLConnection; 38 import java.net.UnknownServiceException; 39 import java.util.Enumeration; 40 import java.util.Properties; 41 import java.util.StringTokenizer; 42 import java.util.Vector; 43 import java.lang.reflect.Constructor; 44 45 import javax.xml.parsers.DocumentBuilder; 46 import javax.xml.parsers.DocumentBuilderFactory; 47 import javax.xml.parsers.ParserConfigurationException; 48 import javax.xml.stream.XMLEventReader; 49 import javax.xml.stream.XMLStreamReader; 50 import javax.xml.transform.ErrorListener; 51 import javax.xml.transform.OutputKeys; 52 import javax.xml.transform.Result; 53 import javax.xml.transform.Source; 54 import javax.xml.transform.Transformer; 55 import javax.xml.transform.TransformerException; 56 import javax.xml.transform.URIResolver; 57 import javax.xml.transform.dom.DOMResult; 58 import javax.xml.transform.dom.DOMSource; 59 import javax.xml.transform.sax.SAXResult; 60 import javax.xml.transform.sax.SAXSource; 61 import javax.xml.transform.stax.StAXResult; 62 import javax.xml.transform.stax.StAXSource; 63 import javax.xml.transform.stream.StreamResult; 64 import javax.xml.transform.stream.StreamSource; 65 import javax.xml.XMLConstants; 66 67 import com.sun.org.apache.xml.internal.utils.SystemIDResolver; 68 69 import com.sun.org.apache.xalan.internal.xsltc.DOM; 70 import com.sun.org.apache.xalan.internal.xsltc.DOMCache; 71 import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM; 72 import com.sun.org.apache.xalan.internal.xsltc.StripFilter; 73 import com.sun.org.apache.xalan.internal.xsltc.Translet; 74 import com.sun.org.apache.xalan.internal.xsltc.TransletException; 75 import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory; 76 import com.sun.org.apache.xml.internal.serializer.SerializationHandler; 77 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 78 import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter; 79 import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl; 80 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; 81 import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; 82 import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable; 83 import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory; 84 85 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter; 192 */ 193 //private boolean _isIncremental = false; 194 195 /** 196 * A flag indicating whether this transformer implements the identity 197 * transform. 198 */ 199 private boolean _isIdentity = false; 200 201 /** 202 * State of the secure processing feature. 203 */ 204 private boolean _isSecureProcessing = false; 205 206 /** 207 * Indicates whether implementation parts should use 208 * service loader (or similar). 209 * Note the default value (false) is the safe option.. 210 */ 211 private boolean _useServicesMechanism; 212 /** 213 * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element. 214 */ 215 private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT; 216 /** 217 * protocols allowed for external DTD references in source file and/or stylesheet. 218 */ 219 private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT; 220 221 /** 222 * A hashtable to store parameters for the identity transform. These 223 * are not needed during the transformation, but we must keep track of 224 * them to be fully complaint with the JAXP API. 225 */ 226 private Hashtable _parameters = null; 227 228 /** 229 * This class wraps an ErrorListener into a MessageHandler in order to 230 * capture messages reported via xsl:message. 231 */ 232 static class MessageHandler 233 extends com.sun.org.apache.xalan.internal.xsltc.runtime.MessageHandler 234 { 235 private ErrorListener _errorListener; 236 237 public MessageHandler(ErrorListener errorListener) { 238 _errorListener = errorListener; 239 } 253 } 254 } 255 256 protected TransformerImpl(Properties outputProperties, int indentNumber, 257 TransformerFactoryImpl tfactory) 258 { 259 this(null, outputProperties, indentNumber, tfactory); 260 _isIdentity = true; 261 // _properties.put(OutputKeys.METHOD, "xml"); 262 } 263 264 protected TransformerImpl(Translet translet, Properties outputProperties, 265 int indentNumber, TransformerFactoryImpl tfactory) 266 { 267 _translet = (AbstractTranslet) translet; 268 _properties = createOutputProperties(outputProperties); 269 _propertiesClone = (Properties) _properties.clone(); 270 _indentNumber = indentNumber; 271 _tfactory = tfactory; 272 _useServicesMechanism = _tfactory.useServicesMechnism(); 273 _accessExternalStylesheet = (String)_tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET); 274 _accessExternalDTD = (String)_tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_DTD); 275 _readerManager = XMLReaderManager.getInstance(_useServicesMechanism); 276 _readerManager.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD); 277 //_isIncremental = tfactory._incremental; 278 } 279 280 /** 281 * Return the state of the secure processing feature. 282 */ 283 public boolean isSecureProcessing() { 284 return _isSecureProcessing; 285 } 286 287 /** 288 * Set the state of the secure processing feature. 289 */ 290 public void setSecureProcessing(boolean flag) { 291 _isSecureProcessing = flag; 292 } 293 /** 294 * Return the state of the services mechanism feature. 295 */ 296 public boolean useServicesMechnism() { |