47 import javax.xml.transform.Source; |
47 import javax.xml.transform.Source; |
48 import javax.xml.transform.Templates; |
48 import javax.xml.transform.Templates; |
49 import javax.xml.transform.Transformer; |
49 import javax.xml.transform.Transformer; |
50 import javax.xml.transform.TransformerConfigurationException; |
50 import javax.xml.transform.TransformerConfigurationException; |
51 import javax.xml.transform.TransformerException; |
51 import javax.xml.transform.TransformerException; |
|
52 import javax.xml.transform.TransformerFactory; |
52 import javax.xml.transform.URIResolver; |
53 import javax.xml.transform.URIResolver; |
53 import javax.xml.transform.dom.DOMResult; |
54 import javax.xml.transform.dom.DOMResult; |
54 import javax.xml.transform.dom.DOMSource; |
55 import javax.xml.transform.dom.DOMSource; |
55 import javax.xml.transform.sax.SAXResult; |
56 import javax.xml.transform.sax.SAXResult; |
56 import javax.xml.transform.sax.SAXSource; |
57 import javax.xml.transform.sax.SAXSource; |
62 import javax.xml.transform.stax.*; |
63 import javax.xml.transform.stax.*; |
63 |
64 |
64 import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler; |
65 import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler; |
65 import com.sun.org.apache.xml.internal.utils.StopParseException; |
66 import com.sun.org.apache.xml.internal.utils.StopParseException; |
66 |
67 |
|
68 import com.sun.org.apache.xalan.internal.XalanConstants; |
67 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; |
69 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; |
68 import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader; |
70 import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader; |
69 import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; |
71 import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; |
70 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
72 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
71 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; |
73 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; |
|
74 import com.sun.org.apache.xalan.internal.utils.ObjectFactory; |
|
75 import com.sun.org.apache.xalan.internal.utils.FactoryImpl; |
72 |
76 |
73 |
77 |
74 import org.xml.sax.InputSource; |
78 import org.xml.sax.InputSource; |
75 import org.xml.sax.XMLFilter; |
79 import org.xml.sax.XMLFilter; |
76 import org.xml.sax.XMLReader; |
80 import org.xml.sax.XMLReader; |
210 private boolean _isNotSecureProcessing = true; |
214 private boolean _isNotSecureProcessing = true; |
211 /** |
215 /** |
212 * <p>State of secure mode.</p> |
216 * <p>State of secure mode.</p> |
213 */ |
217 */ |
214 private boolean _isSecureMode = false; |
218 private boolean _isSecureMode = false; |
|
219 |
|
220 /** |
|
221 * Indicates whether implementation parts should use |
|
222 * service loader (or similar). |
|
223 * Note the default value (false) is the safe option.. |
|
224 */ |
|
225 private boolean _useServicesMechanism; |
|
226 |
215 /** |
227 /** |
216 * javax.xml.transform.sax.TransformerFactory implementation. |
228 * javax.xml.transform.sax.TransformerFactory implementation. |
217 */ |
229 */ |
218 public TransformerFactoryImpl() { |
230 public TransformerFactoryImpl() { |
219 m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(); |
231 this(true); |
|
232 } |
|
233 |
|
234 public static TransformerFactory newTransformerFactoryNoServiceLoader() { |
|
235 return new TransformerFactoryImpl(false); |
|
236 } |
|
237 |
|
238 private TransformerFactoryImpl(boolean useServicesMechanism) { |
|
239 this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism); |
|
240 this._useServicesMechanism = useServicesMechanism; |
220 if (System.getSecurityManager() != null) { |
241 if (System.getSecurityManager() != null) { |
221 _isSecureMode = true; |
242 _isSecureMode = true; |
222 _isNotSecureProcessing = false; |
243 _isNotSecureProcessing = false; |
223 } |
244 } |
224 } |
245 } |
271 else if (name.equals(GENERATE_TRANSLET)) { |
292 else if (name.equals(GENERATE_TRANSLET)) { |
272 return new Boolean(_generateTranslet); |
293 return new Boolean(_generateTranslet); |
273 } |
294 } |
274 else if (name.equals(AUTO_TRANSLET)) { |
295 else if (name.equals(AUTO_TRANSLET)) { |
275 return new Boolean(_autoTranslet); |
296 return new Boolean(_autoTranslet); |
|
297 } |
|
298 else if (name.equals(ENABLE_INLINING)) { |
|
299 if (_enableInlining) |
|
300 return Boolean.TRUE; |
|
301 else |
|
302 return Boolean.FALSE; |
276 } |
303 } |
277 |
304 |
278 // Throw an exception for all other attributes |
305 // Throw an exception for all other attributes |
279 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name); |
306 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name); |
280 throw new IllegalArgumentException(err.toString()); |
307 throw new IllegalArgumentException(err.toString()); |
417 throw new TransformerConfigurationException(err.toString()); |
444 throw new TransformerConfigurationException(err.toString()); |
418 } |
445 } |
419 _isNotSecureProcessing = !value; |
446 _isNotSecureProcessing = !value; |
420 // all done processing feature |
447 // all done processing feature |
421 return; |
448 return; |
|
449 } |
|
450 else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { |
|
451 //in secure mode, let _useServicesMechanism be determined by the constructor |
|
452 if (!_isSecureMode) |
|
453 _useServicesMechanism = value; |
422 } |
454 } |
423 else { |
455 else { |
424 // unknown feature |
456 // unknown feature |
425 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name); |
457 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name); |
426 throw new TransformerConfigurationException(err.toString()); |
458 throw new TransformerConfigurationException(err.toString()); |
446 StAXSource.FEATURE, |
478 StAXSource.FEATURE, |
447 StAXResult.FEATURE, |
479 StAXResult.FEATURE, |
448 StreamSource.FEATURE, |
480 StreamSource.FEATURE, |
449 StreamResult.FEATURE, |
481 StreamResult.FEATURE, |
450 SAXTransformerFactory.FEATURE, |
482 SAXTransformerFactory.FEATURE, |
451 SAXTransformerFactory.FEATURE_XMLFILTER |
483 SAXTransformerFactory.FEATURE_XMLFILTER, |
|
484 XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM |
452 }; |
485 }; |
453 |
486 |
454 // feature name cannot be null |
487 // feature name cannot be null |
455 if (name == null) { |
488 if (name == null) { |
456 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); |
489 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); |
468 return !_isNotSecureProcessing; |
501 return !_isNotSecureProcessing; |
469 } |
502 } |
470 |
503 |
471 // Feature not supported |
504 // Feature not supported |
472 return false; |
505 return false; |
|
506 } |
|
507 /** |
|
508 * Return the state of the services mechanism feature. |
|
509 */ |
|
510 public boolean useServicesMechnism() { |
|
511 return _useServicesMechanism; |
473 } |
512 } |
474 |
513 |
475 /** |
514 /** |
476 * javax.xml.transform.sax.TransformerFactory implementation. |
515 * javax.xml.transform.sax.TransformerFactory implementation. |
477 * Get the object that is used by default during the transformation to |
516 * Get the object that is used by default during the transformation to |
541 dom2sax.parse(); |
580 dom2sax.parse(); |
542 } else { |
581 } else { |
543 isource = SAXSource.sourceToInputSource(source); |
582 isource = SAXSource.sourceToInputSource(source); |
544 baseId = isource.getSystemId(); |
583 baseId = isource.getSystemId(); |
545 |
584 |
546 SAXParserFactory factory = SAXParserFactory.newInstance(); |
585 SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism); |
547 factory.setNamespaceAware(true); |
586 factory.setNamespaceAware(true); |
548 |
587 |
549 if (!_isNotSecureProcessing) { |
588 if (!_isNotSecureProcessing) { |
550 try { |
589 try { |
551 factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
590 factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
700 |
739 |
701 if (_packageName != null) |
740 if (_packageName != null) |
702 transletName = _packageName + "." + transletName; |
741 transletName = _packageName + "." + transletName; |
703 |
742 |
704 try { |
743 try { |
705 final Class clazz = ObjectFactory.findProviderClass( |
744 final Class clazz = ObjectFactory.findProviderClass(transletName, true); |
706 transletName, ObjectFactory.findClassLoader(), true); |
|
707 resetTransientAttributes(); |
745 resetTransientAttributes(); |
708 |
746 |
709 return new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this); |
747 return new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this); |
710 } |
748 } |
711 catch (ClassNotFoundException cnfe) { |
749 catch (ClassNotFoundException cnfe) { |
751 return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this); |
789 return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this); |
752 } |
790 } |
753 } |
791 } |
754 |
792 |
755 // Create and initialize a stylesheet compiler |
793 // Create and initialize a stylesheet compiler |
756 final XSLTC xsltc = new XSLTC(); |
794 final XSLTC xsltc = new XSLTC(_useServicesMechanism); |
757 if (_debug) xsltc.setDebug(true); |
795 if (_debug) xsltc.setDebug(true); |
758 if (_enableInlining) xsltc.setTemplateInlining(true); |
796 if (_enableInlining) |
|
797 xsltc.setTemplateInlining(true); |
|
798 else |
|
799 xsltc.setTemplateInlining(false); |
|
800 |
759 if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true); |
801 if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true); |
760 xsltc.init(); |
802 xsltc.init(); |
761 |
803 |
762 // Set a document loader (for xsl:include/import) if defined |
804 // Set a document loader (for xsl:include/import) if defined |
763 if (_uriResolver != null) { |
805 if (_uriResolver != null) { |