jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
changeset 17534 21dc0b2762da
parent 16953 a44e04deb948
child 17991 4a8c5120a8d4
equal deleted inserted replaced
17533:93a2cadbbd33 17534:21dc0b2762da
   223      * Note the default value (false) is the safe option..
   223      * Note the default value (false) is the safe option..
   224      */
   224      */
   225     private boolean _useServicesMechanism;
   225     private boolean _useServicesMechanism;
   226 
   226 
   227     /**
   227     /**
       
   228      * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
       
   229      */
       
   230     private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
       
   231      /**
       
   232      * protocols allowed for external DTD references in source file and/or stylesheet.
       
   233      */
       
   234     private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
       
   235 
       
   236 
       
   237     /**
   228      * javax.xml.transform.sax.TransformerFactory implementation.
   238      * javax.xml.transform.sax.TransformerFactory implementation.
   229      */
   239      */
   230     public TransformerFactoryImpl() {
   240     public TransformerFactoryImpl() {
   231         this(true);
   241         this(true);
   232     }
   242     }
   236     }
   246     }
   237 
   247 
   238     private TransformerFactoryImpl(boolean useServicesMechanism) {
   248     private TransformerFactoryImpl(boolean useServicesMechanism) {
   239         this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism);
   249         this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism);
   240         this._useServicesMechanism = useServicesMechanism;
   250         this._useServicesMechanism = useServicesMechanism;
       
   251 
       
   252         String defaultAccess = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
   241         if (System.getSecurityManager() != null) {
   253         if (System.getSecurityManager() != null) {
   242             _isSecureMode = true;
   254             _isSecureMode = true;
   243             _isNotSecureProcessing = false;
   255             _isNotSecureProcessing = false;
   244         }
   256             defaultAccess = XalanConstants.getExternalAccessDefault(true);
       
   257         }
       
   258         _accessExternalStylesheet =  SecuritySupport.getDefaultAccessProperty(
       
   259                 XalanConstants.SP_ACCESS_EXTERNAL_STYLESHEET, defaultAccess);
       
   260         _accessExternalDTD =  SecuritySupport.getDefaultAccessProperty(
       
   261                 XalanConstants.SP_ACCESS_EXTERNAL_DTD, defaultAccess);
   245     }
   262     }
   246 
   263 
   247     /**
   264     /**
   248      * javax.xml.transform.sax.TransformerFactory implementation.
   265      * javax.xml.transform.sax.TransformerFactory implementation.
   249      * Set the error event listener for the TransformerFactory, which is used
   266      * Set the error event listener for the TransformerFactory, which is used
   299             if (_enableInlining)
   316             if (_enableInlining)
   300               return Boolean.TRUE;
   317               return Boolean.TRUE;
   301             else
   318             else
   302               return Boolean.FALSE;
   319               return Boolean.FALSE;
   303         }
   320         }
       
   321         else if (name.equals(XMLConstants.ACCESS_EXTERNAL_STYLESHEET)) {
       
   322             return _accessExternalStylesheet;
       
   323         }
       
   324         else if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
       
   325             return _accessExternalDTD;
       
   326         }
   304 
   327 
   305         // Throw an exception for all other attributes
   328         // Throw an exception for all other attributes
   306         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
   329         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
   307         throw new IllegalArgumentException(err.toString());
   330         throw new IllegalArgumentException(err.toString());
   308     }
   331     }
   398             }
   421             }
   399             else if (value instanceof Integer) {
   422             else if (value instanceof Integer) {
   400                 _indentNumber = ((Integer) value).intValue();
   423                 _indentNumber = ((Integer) value).intValue();
   401                 return;
   424                 return;
   402             }
   425             }
       
   426         }
       
   427         else if (name.equals(XMLConstants.ACCESS_EXTERNAL_STYLESHEET)) {
       
   428             _accessExternalStylesheet = (String)value;
       
   429             return;
       
   430         }
       
   431         else if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
       
   432             _accessExternalDTD = (String)value;
       
   433             return;
   403         }
   434         }
   404 
   435 
   405         // Throw an exception for all other attributes
   436         // Throw an exception for all other attributes
   406         final ErrorMsg err
   437         final ErrorMsg err
   407             = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
   438             = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
   442             if ((_isSecureMode) && (!value)) {
   473             if ((_isSecureMode) && (!value)) {
   443                 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE);
   474                 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE);
   444                 throw new TransformerConfigurationException(err.toString());
   475                 throw new TransformerConfigurationException(err.toString());
   445             }
   476             }
   446             _isNotSecureProcessing = !value;
   477             _isNotSecureProcessing = !value;
   447             // all done processing feature
   478 
       
   479             // set restriction, allowing no access to external stylesheet
       
   480             if (value) {
       
   481                 _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP;
       
   482                 _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP;
       
   483             }
   448             return;
   484             return;
   449         }
   485         }
   450         else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
   486         else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
   451             //in secure mode, let _useServicesMechanism be determined by the constructor
   487             //in secure mode, let _useServicesMechanism be determined by the constructor
   452             if (!_isSecureMode)
   488             if (!_isSecureMode)
   797                 xsltc.setTemplateInlining(true);
   833                 xsltc.setTemplateInlining(true);
   798         else
   834         else
   799                 xsltc.setTemplateInlining(false);
   835                 xsltc.setTemplateInlining(false);
   800 
   836 
   801         if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
   837         if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
       
   838         xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, _accessExternalStylesheet);
       
   839         xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
   802         xsltc.init();
   840         xsltc.init();
   803 
   841 
   804         // Set a document loader (for xsl:include/import) if defined
   842         // Set a document loader (for xsl:include/import) if defined
   805         if (_uriResolver != null) {
   843         if (_uriResolver != null) {
   806             xsltc.setSourceLoader(this);
   844             xsltc.setSourceLoader(this);
   878             xsltc.printWarnings();
   916             xsltc.printWarnings();
   879         }
   917         }
   880 
   918 
   881         // Check that the transformation went well before returning
   919         // Check that the transformation went well before returning
   882     if (bytecodes == null) {
   920     if (bytecodes == null) {
   883 
       
   884         Vector errs = xsltc.getErrors();
   921         Vector errs = xsltc.getErrors();
   885         ErrorMsg err = null;
   922         ErrorMsg err = null;
   886         if (errs != null) {
   923         if (errs != null) {
   887             err = (ErrorMsg)errs.get(errs.size()-1);
   924             err = (ErrorMsg)errs.elementAt(errs.size()-1);
   888         } else {
   925         } else {
   889             err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
   926             err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
   890         }
   927         }
   891         TransformerConfigurationException exc =  new TransformerConfigurationException(err.toString(), err.getCause());
   928         Throwable cause = err.getCause();
       
   929         TransformerConfigurationException exc;
       
   930         if (cause != null) {
       
   931             exc =  new TransformerConfigurationException(cause.getMessage(), cause);
       
   932         } else {
       
   933             exc =  new TransformerConfigurationException(err.toString());
       
   934         }
   892 
   935 
   893         // Pass compiler errors to the error listener
   936         // Pass compiler errors to the error listener
   894         if (_errorListener != null) {
   937         if (_errorListener != null) {
   895             passErrorsToListener(xsltc.getErrors());
   938             passErrorsToListener(xsltc.getErrors());
   896 
   939