src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
--- 1,7 ----
/*
! * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
*** 15,35 ****
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
- /*
- * $Id: TransformerFactoryImpl.java,v 1.8 2007/04/09 21:30:41 joehw Exp $
- */
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
- import com.sun.org.apache.xalan.internal.utils.FeatureManager;
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase;
- import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase.State;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager.Property;
--- 15,30 ----
*** 46,62 ****
--- 41,62 ----
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.XMLConstants;
+ import javax.xml.catalog.CatalogFeatures;
+ import javax.xml.catalog.CatalogFeatures.Feature;
+ import javax.xml.catalog.CatalogManager;
+ import javax.xml.catalog.CatalogUriResolver;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
*** 73,82 ****
--- 73,84 ----
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stax.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+ import jdk.xml.internal.JdkXmlFeatures;
+ import jdk.xml.internal.JdkXmlUtils;
import org.xml.sax.InputSource;
import org.xml.sax.XMLFilter;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
*** 84,93 ****
--- 86,96 ----
* Implementation of a JAXP1.1 TransformerFactory for Translets.
* @author G. Todd Miller
* @author Morten Jorgensen
* @author Santiago Pericas-Geertsen
*/
+ @SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory
public class TransformerFactoryImpl
extends SAXTransformerFactory implements SourceLoader, ErrorListener
{
// Public constants for attributes supported by the XSLTC TransformerFactory.
public final static String TRANSLET_NAME = "translet-name";
*** 227,245 ****
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private XMLSecurityPropertyManager _xmlSecurityPropertyMgr;
private XMLSecurityManager _xmlSecurityManager;
! private final FeatureManager _featureManager;
private ClassLoader _extensionClassLoader = null;
// Unmodifiable view of external extension function from xslt compiler
// It will be populated by user-specified extension functions during the
// type checking
private Map<String, Class> _xsltcExtensionFunctions;
/**
* javax.xml.transform.sax.TransformerFactory implementation.
*/
public TransformerFactoryImpl() {
this(true);
--- 230,257 ----
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private XMLSecurityPropertyManager _xmlSecurityPropertyMgr;
private XMLSecurityManager _xmlSecurityManager;
! private final JdkXmlFeatures _xmlFeatures;
private ClassLoader _extensionClassLoader = null;
// Unmodifiable view of external extension function from xslt compiler
// It will be populated by user-specified extension functions during the
// type checking
private Map<String, Class> _xsltcExtensionFunctions;
+ CatalogUriResolver _catalogUriResolver;
+ CatalogFeatures _catalogFeatures;
+ CatalogFeatures.Builder cfBuilder = CatalogFeatures.builder();
+ // Catalog features
+ String _catalogFiles = null;
+ String _catalogDefer = null;
+ String _catalogPrefer = null;
+ String _catalogResolve = null;
+
/**
* javax.xml.transform.sax.TransformerFactory implementation.
*/
public TransformerFactoryImpl() {
this(true);
*** 249,267 ****
return new TransformerFactoryImpl(false);
}
private TransformerFactoryImpl(boolean useServicesMechanism) {
this._useServicesMechanism = useServicesMechanism;
- _featureManager = new FeatureManager();
if (System.getSecurityManager() != null) {
_isSecureMode = true;
_isNotSecureProcessing = false;
- _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION,
- FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE);
}
_xmlSecurityPropertyMgr = new XMLSecurityPropertyManager();
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_DTD);
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_STYLESHEET);
--- 261,277 ----
return new TransformerFactoryImpl(false);
}
private TransformerFactoryImpl(boolean useServicesMechanism) {
this._useServicesMechanism = useServicesMechanism;
if (System.getSecurityManager() != null) {
_isSecureMode = true;
_isNotSecureProcessing = false;
}
+ _xmlFeatures = new JdkXmlFeatures(!_isNotSecureProcessing);
_xmlSecurityPropertyMgr = new XMLSecurityPropertyManager();
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_DTD);
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_STYLESHEET);
*** 330,353 ****
// Return value for attribute 'translet-name'
if (name.equals(TRANSLET_NAME)) {
return _transletName;
}
else if (name.equals(GENERATE_TRANSLET)) {
! return new Boolean(_generateTranslet);
}
else if (name.equals(AUTO_TRANSLET)) {
! return new Boolean(_autoTranslet);
}
else if (name.equals(ENABLE_INLINING)) {
if (_enableInlining)
return Boolean.TRUE;
else
return Boolean.FALSE;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
return _xmlSecurityManager;
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
return _extensionClassLoader;
}
/** Check to see if the property is managed by the security manager **/
String propertyValue = (_xmlSecurityManager != null) ?
_xmlSecurityManager.getLimitAsString(name) : null;
--- 340,373 ----
// Return value for attribute 'translet-name'
if (name.equals(TRANSLET_NAME)) {
return _transletName;
}
else if (name.equals(GENERATE_TRANSLET)) {
! return _generateTranslet;
}
else if (name.equals(AUTO_TRANSLET)) {
! return _autoTranslet;
}
else if (name.equals(ENABLE_INLINING)) {
if (_enableInlining)
return Boolean.TRUE;
else
return Boolean.FALSE;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
return _xmlSecurityManager;
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
return _extensionClassLoader;
+ } else if (JdkXmlUtils.CATALOG_FILES.equals(name)) {
+ return _catalogFiles;
+ } else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) {
+ return _catalogDefer;
+ } else if (JdkXmlUtils.CATALOG_PREFER.equals(name)) {
+ return _catalogPrefer;
+ } else if (JdkXmlUtils.CATALOG_RESOLVE.equals(name)) {
+ return _catalogResolve;
+ } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
+ return buildCatalogFeatures();
}
/** Check to see if the property is managed by the security manager **/
String propertyValue = (_xmlSecurityManager != null) ?
_xmlSecurityManager.getLimitAsString(name) : null;
*** 396,446 ****
_jarFileName = (String) value;
return;
}
else if (name.equals(GENERATE_TRANSLET)) {
if (value instanceof Boolean) {
! _generateTranslet = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_generateTranslet = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(AUTO_TRANSLET)) {
if (value instanceof Boolean) {
! _autoTranslet = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_autoTranslet = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(USE_CLASSPATH)) {
if (value instanceof Boolean) {
! _useClasspath = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_useClasspath = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(DEBUG)) {
if (value instanceof Boolean) {
! _debug = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_debug = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(ENABLE_INLINING)) {
if (value instanceof Boolean) {
! _enableInlining = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_enableInlining = ((String) value).equalsIgnoreCase("true");
return;
--- 416,466 ----
_jarFileName = (String) value;
return;
}
else if (name.equals(GENERATE_TRANSLET)) {
if (value instanceof Boolean) {
! _generateTranslet = ((Boolean) value);
return;
}
else if (value instanceof String) {
_generateTranslet = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(AUTO_TRANSLET)) {
if (value instanceof Boolean) {
! _autoTranslet = ((Boolean) value);
return;
}
else if (value instanceof String) {
_autoTranslet = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(USE_CLASSPATH)) {
if (value instanceof Boolean) {
! _useClasspath = ((Boolean) value);
return;
}
else if (value instanceof String) {
_useClasspath = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(DEBUG)) {
if (value instanceof Boolean) {
! _debug = ((Boolean) value);
return;
}
else if (value instanceof String) {
_debug = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(ENABLE_INLINING)) {
if (value instanceof Boolean) {
! _enableInlining = ((Boolean) value);
return;
}
else if (value instanceof String) {
_enableInlining = ((String) value).equalsIgnoreCase("true");
return;
*** 455,465 ****
catch (NumberFormatException e) {
// Falls through
}
}
else if (value instanceof Integer) {
! _indentNumber = ((Integer) value).intValue();
return;
}
}
else if ( name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
if (value instanceof ClassLoader) {
--- 475,485 ----
catch (NumberFormatException e) {
// Falls through
}
}
else if (value instanceof Integer) {
! _indentNumber = ((Integer) value);
return;
}
}
else if ( name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
if (value instanceof ClassLoader) {
*** 468,477 ****
--- 488,513 ----
} else {
final ErrorMsg err
= new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_VALUE_ERR, "Extension Functions ClassLoader");
throw new IllegalArgumentException(err.toString());
}
+ } else if (JdkXmlUtils.CATALOG_FILES.equals(name)) {
+ _catalogFiles = (String) value;
+ cfBuilder = CatalogFeatures.builder().with(Feature.FILES, _catalogFiles);
+ return;
+ } else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) {
+ _catalogDefer = (String) value;
+ cfBuilder = CatalogFeatures.builder().with(Feature.DEFER, _catalogDefer);
+ return;
+ } else if (JdkXmlUtils.CATALOG_PREFER.equals(name)) {
+ _catalogPrefer = (String) value;
+ cfBuilder = CatalogFeatures.builder().with(Feature.PREFER, _catalogPrefer);
+ return;
+ } else if (JdkXmlUtils.CATALOG_RESOLVE.equals(name)) {
+ _catalogResolve = (String) value;
+ cfBuilder = CatalogFeatures.builder().with(Feature.RESOLVE, _catalogResolve);
+ return;
}
if (_xmlSecurityManager != null &&
_xmlSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) {
return;
*** 532,563 ****
_xmlSecurityManager.setSecureProcessing(value);
// set external access restriction when FSP is explicitly set
if (value) {
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
! State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET,
! State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_DTD);
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_STYLESHEET);
}
! if (value && _featureManager != null) {
! _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION,
! FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE);
}
}
else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
//in secure mode, let _useServicesMechanism be determined by the constructor
if (!_isSecureMode)
_useServicesMechanism = value;
}
else {
! if (_featureManager != null &&
! _featureManager.setValue(name, State.APIPROPERTY, value)) {
return;
}
// unknown feature
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
--- 568,599 ----
_xmlSecurityManager.setSecureProcessing(value);
// set external access restriction when FSP is explicitly set
if (value) {
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
! FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET,
! FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_DTD);
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_STYLESHEET);
}
! if (value && _xmlFeatures != null) {
! _xmlFeatures.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION,
! JdkXmlFeatures.State.FSP, false);
}
}
else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
//in secure mode, let _useServicesMechanism be determined by the constructor
if (!_isSecureMode)
_useServicesMechanism = value;
}
else {
! if (_xmlFeatures != null &&
! _xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
return;
}
// unknown feature
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
*** 601,620 ****
for (int i =0; i < features.length; i++) {
if (name.equals(features[i])) {
return true;
}
}
! // secure processing?
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return !_isNotSecureProcessing;
}
! /** Check to see if the property is managed by the security manager **/
! String propertyValue = (_featureManager != null) ?
! _featureManager.getValueAsString(name) : null;
! if (propertyValue != null) {
! return Boolean.parseBoolean(propertyValue);
}
// Feature not supported
return false;
}
--- 637,655 ----
for (int i =0; i < features.length; i++) {
if (name.equals(features[i])) {
return true;
}
}
!
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return !_isNotSecureProcessing;
}
! /** Check to see if the property is managed by the JdkXmlFeatues **/
! int index = _xmlFeatures.getIndex(name);
! if (index > -1) {
! return _xmlFeatures.getFeature(index);
}
// Feature not supported
return false;
}
*** 626,637 ****
}
/**
* @return the feature manager
*/
! public FeatureManager getFeatureManager() {
! return _featureManager;
}
/**
* javax.xml.transform.sax.TransformerFactory implementation.
* Get the object that is used by default during the transformation to
--- 661,672 ----
}
/**
* @return the feature manager
*/
! public JdkXmlFeatures getJdkXmlFeatures() {
! return _xmlFeatures;
}
/**
* javax.xml.transform.sax.TransformerFactory implementation.
* Get the object that is used by default during the transformation to
*** 734,758 ****
}
} catch (StopParseException e ) {
// startElement encountered so do not parse further
! } catch (javax.xml.parsers.ParserConfigurationException e) {
!
throw new TransformerConfigurationException(
"getAssociatedStylesheets failed", e);
-
- } catch (org.xml.sax.SAXException se) {
-
- throw new TransformerConfigurationException(
- "getAssociatedStylesheets failed", se);
-
-
- } catch (IOException ioe ) {
- throw new TransformerConfigurationException(
- "getAssociatedStylesheets failed", ioe);
-
}
return _stylesheetPIHandler.getAssociatedStylesheet();
}
--- 769,781 ----
}
} catch (StopParseException e ) {
// startElement encountered so do not parse further
! } catch (javax.xml.parsers.ParserConfigurationException | org.xml.sax.SAXException | IOException e) {
throw new TransformerConfigurationException(
"getAssociatedStylesheets failed", e);
}
return _stylesheetPIHandler.getAssociatedStylesheet();
}
*** 766,775 ****
--- 789,801 ----
*/
@Override
public Transformer newTransformer()
throws TransformerConfigurationException
{
+ // create CatalogFeatures that is accessible by the Transformer
+ // through the factory instance
+ buildCatalogFeatures();
TransformerImpl result = new TransformerImpl(new Properties(),
_indentNumber, this);
if (_uriResolver != null) {
result.setURIResolver(_uriResolver);
}
*** 803,822 ****
}
/**
* Pass warning messages from the compiler to the error listener
*/
! private void passWarningsToListener(Vector messages)
throws TransformerException
{
if (_errorListener == null || messages == null) {
return;
}
// Pass messages to listener, one by one
final int count = messages.size();
for (int pos = 0; pos < count; pos++) {
! ErrorMsg msg = (ErrorMsg)messages.elementAt(pos);
// Workaround for the TCK failure ErrorListener.errorTests.error001.
if (msg.isWarningError())
_errorListener.error(
new TransformerConfigurationException(msg.toString()));
else
--- 829,848 ----
}
/**
* Pass warning messages from the compiler to the error listener
*/
! private void passWarningsToListener(ArrayList<ErrorMsg> messages)
throws TransformerException
{
if (_errorListener == null || messages == null) {
return;
}
// Pass messages to listener, one by one
final int count = messages.size();
for (int pos = 0; pos < count; pos++) {
! ErrorMsg msg = messages.get(pos);
// Workaround for the TCK failure ErrorListener.errorTests.error001.
if (msg.isWarningError())
_errorListener.error(
new TransformerConfigurationException(msg.toString()));
else
*** 826,844 ****
}
/**
* Pass error messages from the compiler to the error listener
*/
! private void passErrorsToListener(Vector messages) {
try {
if (_errorListener == null || messages == null) {
return;
}
// Pass messages to listener, one by one
final int count = messages.size();
for (int pos = 0; pos < count; pos++) {
! String message = messages.elementAt(pos).toString();
_errorListener.error(new TransformerException(message));
}
}
catch (TransformerException e) {
// nada
--- 852,870 ----
}
/**
* Pass error messages from the compiler to the error listener
*/
! private void passErrorsToListener(ArrayList<ErrorMsg> messages) {
try {
if (_errorListener == null || messages == null) {
return;
}
// Pass messages to listener, one by one
final int count = messages.size();
for (int pos = 0; pos < count; pos++) {
! String message = messages.get(pos).toString();
_errorListener.error(new TransformerException(message));
}
}
catch (TransformerException e) {
// nada
*** 915,925 ****
return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this);
}
}
// Create and initialize a stylesheet compiler
! final XSLTC xsltc = new XSLTC(_useServicesMechanism, _featureManager);
if (_debug) xsltc.setDebug(true);
if (_enableInlining)
xsltc.setTemplateInlining(true);
else
xsltc.setTemplateInlining(false);
--- 941,951 ----
return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this);
}
}
// Create and initialize a stylesheet compiler
! final XSLTC xsltc = new XSLTC(_useServicesMechanism, _xmlFeatures);
if (_debug) xsltc.setDebug(true);
if (_enableInlining)
xsltc.setTemplateInlining(true);
else
xsltc.setTemplateInlining(false);
*** 927,941 ****
if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, _accessExternalStylesheet);
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
xsltc.setProperty(XalanConstants.SECURITY_MANAGER, _xmlSecurityManager);
xsltc.setProperty(XalanConstants.JDK_EXTENSION_CLASSLOADER, _extensionClassLoader);
xsltc.init();
if (!_isNotSecureProcessing)
_xsltcExtensionFunctions = xsltc.getExternalExtensionFunctions();
// Set a document loader (for xsl:include/import) if defined
! if (_uriResolver != null) {
xsltc.setSourceLoader(this);
}
// Pass parameters to the Parser to make sure it locates the correct
// <?xml-stylesheet ...?> PI in an XML input document
--- 953,972 ----
if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, _accessExternalStylesheet);
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
xsltc.setProperty(XalanConstants.SECURITY_MANAGER, _xmlSecurityManager);
xsltc.setProperty(XalanConstants.JDK_EXTENSION_CLASSLOADER, _extensionClassLoader);
+
+ // set Catalog features
+ buildCatalogFeatures();
+ xsltc.setProperty(JdkXmlFeatures.CATALOG_FEATURES, _catalogFeatures);
+
xsltc.init();
if (!_isNotSecureProcessing)
_xsltcExtensionFunctions = xsltc.getExternalExtensionFunctions();
// Set a document loader (for xsl:include/import) if defined
! if (_uriResolver != null || (_xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG) && _catalogFiles != null)) {
xsltc.setSourceLoader(this);
}
// Pass parameters to the Parser to make sure it locates the correct
// <?xml-stylesheet ...?> PI in an XML input document
*** 1009,1022 ****
xsltc.printWarnings();
}
// Check that the transformation went well before returning
if (bytecodes == null) {
! Vector errs = xsltc.getErrors();
ErrorMsg err;
if (errs != null) {
! err = (ErrorMsg)errs.elementAt(errs.size()-1);
} else {
err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
}
Throwable cause = err.getCause();
TransformerConfigurationException exc;
--- 1040,1053 ----
xsltc.printWarnings();
}
// Check that the transformation went well before returning
if (bytecodes == null) {
! ArrayList<ErrorMsg> errs = xsltc.getErrors();
ErrorMsg err;
if (errs != null) {
! err = errs.get(errs.size()-1);
} else {
err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
}
Throwable cause = err.getCause();
TransformerConfigurationException exc;
*** 1043,1054 ****
xsltc.printErrors();
}
throw exc;
}
! return new TemplatesImpl(bytecodes, transletName,
xsltc.getOutputProperties(), _indentNumber, this);
}
/**
* javax.xml.transform.sax.SAXTransformerFactory implementation.
* Get a TemplatesHandler object that can process SAX ContentHandler
--- 1074,1089 ----
xsltc.printErrors();
}
throw exc;
}
! TemplatesImpl templates = new TemplatesImpl(bytecodes, transletName,
xsltc.getOutputProperties(), _indentNumber, this);
+ if (_uriResolver != null) {
+ templates.setURIResolver(_uriResolver);
+ }
+ return templates;
}
/**
* javax.xml.transform.sax.SAXTransformerFactory implementation.
* Get a TemplatesHandler object that can process SAX ContentHandler
*** 1059,1068 ****
--- 1094,1106 ----
*/
@Override
public TemplatesHandler newTemplatesHandler()
throws TransformerConfigurationException
{
+ // create CatalogFeatures that is accessible by the Handler
+ // through the factory instance
+ buildCatalogFeatures();
final TemplatesHandlerImpl handler =
new TemplatesHandlerImpl(_indentNumber, this);
if (_uriResolver != null) {
handler.setURIResolver(_uriResolver);
}
*** 1270,1296 ****
* @return An InputSource with the loaded document
*/
@Override
public InputSource loadSource(String href, String context, XSLTC xsltc) {
try {
if (_uriResolver != null) {
! final Source source = _uriResolver.resolve(href, context);
if (source != null) {
return Util.getInputSource(xsltc, source);
}
}
- }
catch (TransformerException e) {
// should catch it when the resolver explicitly throws the exception
final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
xsltc.getParser().reportError(Constants.FATAL, msg);
}
return null;
}
/**
* Reset the per-session attributes to their default values
*/
private void resetTransientAttributes() {
_transletName = DEFAULT_TRANSLET_NAME;
_destinationDirectory = null;
--- 1308,1362 ----
* @return An InputSource with the loaded document
*/
@Override
public InputSource loadSource(String href, String context, XSLTC xsltc) {
try {
+ Source source = null;
if (_uriResolver != null) {
! source = _uriResolver.resolve(href, context);
! }
! if (source == null && _catalogFiles != null &&
! _xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG)) {
! if (_catalogUriResolver == null) {
! _catalogUriResolver = CatalogManager.catalogUriResolver(_catalogFeatures);
! }
! source = _catalogUriResolver.resolve(href, context);
! }
if (source != null) {
return Util.getInputSource(xsltc, source);
}
}
catch (TransformerException e) {
// should catch it when the resolver explicitly throws the exception
final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
xsltc.getParser().reportError(Constants.FATAL, msg);
}
return null;
}
/**
+ * Build the CatalogFeatures object when a newTemplates or newTransformer is
+ * created. This will read any System Properties for the CatalogFeatures that
+ * may have been set.
+ */
+ private CatalogFeatures buildCatalogFeatures() {
+ // build will cause the CatalogFeatures to read SPs for those not set through the API
+ if (_catalogFeatures == null) {
+ _catalogFeatures = cfBuilder.build();
+ }
+
+ // update fields
+ _catalogFiles = _catalogFeatures.get(Feature.FILES);
+ _catalogDefer = _catalogFeatures.get(Feature.DEFER);
+ _catalogPrefer = _catalogFeatures.get(Feature.PREFER);
+ _catalogResolve = _catalogFeatures.get(Feature.RESOLVE);
+
+ return _catalogFeatures;
+ }
+
+ /**
* Reset the per-session attributes to their default values
*/
private void resetTransientAttributes() {
_transletName = DEFAULT_TRANSLET_NAME;
_destinationDirectory = null;