34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
35 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
36 import com.sun.org.apache.xml.internal.utils.StopParseException;
37 import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler;
38 import java.io.File;
39 import java.io.FileInputStream;
40 import java.io.FileNotFoundException;
41 import java.io.FilenameFilter;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.net.MalformedURLException;
45 import java.net.URL;
46 import java.util.ArrayList;
47 import java.util.Enumeration;
48 import java.util.Map;
49 import java.util.Properties;
50 import java.util.Vector;
51 import java.util.zip.ZipEntry;
52 import java.util.zip.ZipFile;
53 import javax.xml.XMLConstants;
54 import javax.xml.catalog.CatalogFeatures;
55 import javax.xml.catalog.CatalogFeatures.Feature;
56 import javax.xml.catalog.CatalogManager;
57 import javax.xml.catalog.CatalogUriResolver;
58 import javax.xml.parsers.SAXParser;
59 import javax.xml.parsers.SAXParserFactory;
60 import javax.xml.transform.ErrorListener;
61 import javax.xml.transform.Source;
62 import javax.xml.transform.Templates;
63 import javax.xml.transform.Transformer;
64 import javax.xml.transform.TransformerConfigurationException;
65 import javax.xml.transform.TransformerException;
66 import javax.xml.transform.TransformerFactory;
67 import javax.xml.transform.URIResolver;
68 import javax.xml.transform.dom.DOMResult;
69 import javax.xml.transform.dom.DOMSource;
70 import javax.xml.transform.sax.SAXResult;
71 import javax.xml.transform.sax.SAXSource;
72 import javax.xml.transform.sax.SAXTransformerFactory;
73 import javax.xml.transform.sax.TemplatesHandler;
74 import javax.xml.transform.sax.TransformerHandler;
75 import javax.xml.transform.stax.*;
76 import javax.xml.transform.stream.StreamResult;
77 import javax.xml.transform.stream.StreamSource;
224 * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
225 */
226 private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
227 /**
228 * protocols allowed for external DTD references in source file and/or stylesheet.
229 */
230 private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
231
232 private XMLSecurityPropertyManager _xmlSecurityPropertyMgr;
233 private XMLSecurityManager _xmlSecurityManager;
234
235 private final JdkXmlFeatures _xmlFeatures;
236
237 private ClassLoader _extensionClassLoader = null;
238
239 // Unmodifiable view of external extension function from xslt compiler
240 // It will be populated by user-specified extension functions during the
241 // type checking
242 private Map<String, Class> _xsltcExtensionFunctions;
243
244 CatalogUriResolver _catalogUriResolver;
245 CatalogFeatures _catalogFeatures;
246 CatalogFeatures.Builder cfBuilder = CatalogFeatures.builder();
247 // Catalog features
248 String _catalogFiles = null;
249 String _catalogDefer = null;
250 String _catalogPrefer = null;
251 String _catalogResolve = null;
252
253 /**
254 * javax.xml.transform.sax.TransformerFactory implementation.
255 */
256 public TransformerFactoryImpl() {
257 this(true);
258 }
259
260 public static TransformerFactory newTransformerFactoryNoServiceLoader() {
261 return new TransformerFactoryImpl(false);
262 }
263
264 private TransformerFactoryImpl(boolean useServicesMechanism) {
617 DOMSource.FEATURE,
618 DOMResult.FEATURE,
619 SAXSource.FEATURE,
620 SAXResult.FEATURE,
621 StAXSource.FEATURE,
622 StAXResult.FEATURE,
623 StreamSource.FEATURE,
624 StreamResult.FEATURE,
625 SAXTransformerFactory.FEATURE,
626 SAXTransformerFactory.FEATURE_XMLFILTER,
627 XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM
628 };
629
630 // feature name cannot be null
631 if (name == null) {
632 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
633 throw new NullPointerException(err.toString());
634 }
635
636 // Inefficient, but array is small
637 for (int i = 0; i < features.length; i++) {
638 if (name.equals(features[i])) {
639 return true;
640 }
641 }
642
643 if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
644 return !_isNotSecureProcessing;
645 }
646
647 /** Check to see if the property is managed by the JdkXmlFeatues **/
648 int index = _xmlFeatures.getIndex(name);
649 if (index > -1) {
650 return _xmlFeatures.getFeature(index);
651 }
652
653 // Feature not supported
654 return false;
655 }
656 /**
657 * Return the state of the services mechanism feature.
1310
1311 /**
1312 * This method implements XSLTC's SourceLoader interface. It is used to
1313 * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
1314 *
1315 * @param href The URI of the document to load
1316 * @param context The URI of the currently loaded document
1317 * @param xsltc The compiler that resuests the document
1318 * @return An InputSource with the loaded document
1319 */
1320 @Override
1321 public InputSource loadSource(String href, String context, XSLTC xsltc) {
1322 try {
1323 Source source = null;
1324 if (_uriResolver != null) {
1325 source = _uriResolver.resolve(href, context);
1326 }
1327 if (source == null && _catalogFiles != null &&
1328 _xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG)) {
1329 if (_catalogUriResolver == null) {
1330 _catalogUriResolver = CatalogManager.catalogUriResolver(_catalogFeatures);
1331 }
1332 source = _catalogUriResolver.resolve(href, context);
1333 }
1334 if (source != null) {
1335 return Util.getInputSource(xsltc, source);
1336 }
1337 }
1338 catch (TransformerException e) {
1339 // should catch it when the resolver explicitly throws the exception
1340 final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
1341 xsltc.getParser().reportError(Constants.FATAL, msg);
1342 }
1343
1344 return null;
1345 }
1346
1347 /**
1348 * Build the CatalogFeatures object when a newTemplates or newTransformer is
1349 * created. This will read any System Properties for the CatalogFeatures that
1350 * may have been set.
1351 */
1352 private CatalogFeatures buildCatalogFeatures() {
1353 // build will cause the CatalogFeatures to read SPs for those not set through the API
1354 if (_catalogFeatures == null) {
1355 _catalogFeatures = cfBuilder.build();
1356 }
1357
1358 // update fields
1359 _catalogFiles = _catalogFeatures.get(Feature.FILES);
1360 _catalogDefer = _catalogFeatures.get(Feature.DEFER);
|
34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
35 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
36 import com.sun.org.apache.xml.internal.utils.StopParseException;
37 import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler;
38 import java.io.File;
39 import java.io.FileInputStream;
40 import java.io.FileNotFoundException;
41 import java.io.FilenameFilter;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.net.MalformedURLException;
45 import java.net.URL;
46 import java.util.ArrayList;
47 import java.util.Enumeration;
48 import java.util.Map;
49 import java.util.Properties;
50 import java.util.Vector;
51 import java.util.zip.ZipEntry;
52 import java.util.zip.ZipFile;
53 import javax.xml.XMLConstants;
54 import javax.xml.catalog.CatalogException;
55 import javax.xml.catalog.CatalogFeatures;
56 import javax.xml.catalog.CatalogFeatures.Feature;
57 import javax.xml.catalog.CatalogManager;
58 import javax.xml.catalog.CatalogResolver;
59 import javax.xml.parsers.SAXParser;
60 import javax.xml.parsers.SAXParserFactory;
61 import javax.xml.transform.ErrorListener;
62 import javax.xml.transform.Source;
63 import javax.xml.transform.Templates;
64 import javax.xml.transform.Transformer;
65 import javax.xml.transform.TransformerConfigurationException;
66 import javax.xml.transform.TransformerException;
67 import javax.xml.transform.TransformerFactory;
68 import javax.xml.transform.URIResolver;
69 import javax.xml.transform.dom.DOMResult;
70 import javax.xml.transform.dom.DOMSource;
71 import javax.xml.transform.sax.SAXResult;
72 import javax.xml.transform.sax.SAXSource;
73 import javax.xml.transform.sax.SAXTransformerFactory;
74 import javax.xml.transform.sax.TemplatesHandler;
75 import javax.xml.transform.sax.TransformerHandler;
76 import javax.xml.transform.stax.*;
77 import javax.xml.transform.stream.StreamResult;
78 import javax.xml.transform.stream.StreamSource;
225 * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
226 */
227 private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
228 /**
229 * protocols allowed for external DTD references in source file and/or stylesheet.
230 */
231 private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
232
233 private XMLSecurityPropertyManager _xmlSecurityPropertyMgr;
234 private XMLSecurityManager _xmlSecurityManager;
235
236 private final JdkXmlFeatures _xmlFeatures;
237
238 private ClassLoader _extensionClassLoader = null;
239
240 // Unmodifiable view of external extension function from xslt compiler
241 // It will be populated by user-specified extension functions during the
242 // type checking
243 private Map<String, Class> _xsltcExtensionFunctions;
244
245 CatalogResolver _catalogUriResolver;
246 CatalogFeatures _catalogFeatures;
247 CatalogFeatures.Builder cfBuilder = CatalogFeatures.builder();
248 // Catalog features
249 String _catalogFiles = null;
250 String _catalogDefer = null;
251 String _catalogPrefer = null;
252 String _catalogResolve = null;
253
254 /**
255 * javax.xml.transform.sax.TransformerFactory implementation.
256 */
257 public TransformerFactoryImpl() {
258 this(true);
259 }
260
261 public static TransformerFactory newTransformerFactoryNoServiceLoader() {
262 return new TransformerFactoryImpl(false);
263 }
264
265 private TransformerFactoryImpl(boolean useServicesMechanism) {
618 DOMSource.FEATURE,
619 DOMResult.FEATURE,
620 SAXSource.FEATURE,
621 SAXResult.FEATURE,
622 StAXSource.FEATURE,
623 StAXResult.FEATURE,
624 StreamSource.FEATURE,
625 StreamResult.FEATURE,
626 SAXTransformerFactory.FEATURE,
627 SAXTransformerFactory.FEATURE_XMLFILTER,
628 XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM
629 };
630
631 // feature name cannot be null
632 if (name == null) {
633 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
634 throw new NullPointerException(err.toString());
635 }
636
637 // Inefficient, but array is small
638 for (int i =0; i < features.length; i++) {
639 if (name.equals(features[i])) {
640 return true;
641 }
642 }
643
644 if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
645 return !_isNotSecureProcessing;
646 }
647
648 /** Check to see if the property is managed by the JdkXmlFeatues **/
649 int index = _xmlFeatures.getIndex(name);
650 if (index > -1) {
651 return _xmlFeatures.getFeature(index);
652 }
653
654 // Feature not supported
655 return false;
656 }
657 /**
658 * Return the state of the services mechanism feature.
1311
1312 /**
1313 * This method implements XSLTC's SourceLoader interface. It is used to
1314 * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
1315 *
1316 * @param href The URI of the document to load
1317 * @param context The URI of the currently loaded document
1318 * @param xsltc The compiler that resuests the document
1319 * @return An InputSource with the loaded document
1320 */
1321 @Override
1322 public InputSource loadSource(String href, String context, XSLTC xsltc) {
1323 try {
1324 Source source = null;
1325 if (_uriResolver != null) {
1326 source = _uriResolver.resolve(href, context);
1327 }
1328 if (source == null && _catalogFiles != null &&
1329 _xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG)) {
1330 if (_catalogUriResolver == null) {
1331 _catalogUriResolver = CatalogManager.catalogResolver(_catalogFeatures);
1332 }
1333 source = _catalogUriResolver.resolve(href, context);
1334 }
1335 if (source != null) {
1336 return Util.getInputSource(xsltc, source);
1337 }
1338 }
1339 catch (TransformerException e) {
1340 // should catch it when the resolver explicitly throws the exception
1341 final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
1342 xsltc.getParser().reportError(Constants.FATAL, msg);
1343 }
1344 catch (CatalogException e) {
1345 final ErrorMsg msg = new ErrorMsg(ErrorMsg.CATALOG_EXCEPTION, href + "\n" + e.getMessage(), this);
1346 xsltc.getParser().reportError(Constants.FATAL, msg);
1347 }
1348
1349 return null;
1350 }
1351
1352 /**
1353 * Build the CatalogFeatures object when a newTemplates or newTransformer is
1354 * created. This will read any System Properties for the CatalogFeatures that
1355 * may have been set.
1356 */
1357 private CatalogFeatures buildCatalogFeatures() {
1358 // build will cause the CatalogFeatures to read SPs for those not set through the API
1359 if (_catalogFeatures == null) {
1360 _catalogFeatures = cfBuilder.build();
1361 }
1362
1363 // update fields
1364 _catalogFiles = _catalogFeatures.get(Feature.FILES);
1365 _catalogDefer = _catalogFeatures.get(Feature.DEFER);
|