< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Print this page
rev 1063 : 8172974: [JAXP] XALAN: Wrong result when transforming namespace unaware StAX Input

*** 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. --- 1,7 ---- /* ! * Copyright (c) 2007, 2017, 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.
*** 45,55 **** 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.CatalogException; import javax.xml.catalog.CatalogFeatures; --- 45,54 ----
*** 148,178 **** * The jar file name which the translet classes are packaged into */ private String _jarFileName = null; /** - * This Map is used to store parameters for locating - * <?xml-stylesheet ...?> processing instructions in XML docs. - */ - private Map<Source, PIParamWrapper> _piParams = null; - - /** - * The above Map stores objects of this class. - */ - private static class PIParamWrapper { - public String _media = null; - public String _title = null; - public String _charset = null; - - public PIParamWrapper(String media, String title, String charset) { - _media = media; - _title = title; - _charset = charset; - } - } - - /** * Set to <code>true</code> when debugging is enabled. */ private boolean _debug = false; /** --- 147,156 ----
*** 207,234 **** /** * <p>State of secure processing feature.</p> */ private boolean _isNotSecureProcessing = true; /** * <p>State of secure mode.</p> */ private boolean _isSecureMode = false; /** * Indicates whether implementation parts should use * service loader (or similar). ! * Note the default value (false) is the safe option.. */ private boolean _useServicesMechanism; /** * protocols allowed for external references set by the stylesheet * processing instruction, Import and Include element. */ private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT; ! /** * protocols allowed for external DTD references in source file and/or stylesheet. */ private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT; private XMLSecurityPropertyManager _xmlSecurityPropertyMgr; --- 185,214 ---- /** * <p>State of secure processing feature.</p> */ private boolean _isNotSecureProcessing = true; + /** * <p>State of secure mode.</p> */ private boolean _isSecureMode = false; /** * Indicates whether implementation parts should use * service loader (or similar). ! * Note the default value (false) is the safe option. */ private boolean _useServicesMechanism; /** * protocols allowed for external references set by the stylesheet * processing instruction, Import and Include element. */ private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT; ! ! /** * protocols allowed for external DTD references in source file and/or stylesheet. */ private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT; private XMLSecurityPropertyManager _xmlSecurityPropertyMgr;
*** 564,576 **** // feature name cannot be null if (name == null) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); - } // secure processing? ! else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { if ((_isSecureMode) && (!value)) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE); throw new TransformerConfigurationException(err.toString()); } _isNotSecureProcessing = !value; --- 544,555 ---- // feature name cannot be null if (name == null) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); // secure processing? ! } else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { if ((_isSecureMode) && (!value)) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE); throw new TransformerConfigurationException(err.toString()); } _isNotSecureProcessing = !value;
*** 590,608 **** 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); --- 569,585 ---- 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);
*** 619,629 **** * @param name The feature name * @return 'true' if feature is supported, 'false' if not */ @Override public boolean getFeature(String name) { ! // All supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, SAXSource.FEATURE, SAXResult.FEATURE, --- 596,606 ---- * @param name The feature name * @return 'true' if feature is supported, 'false' if not */ @Override public boolean getFeature(String name) { ! // all supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, SAXSource.FEATURE, SAXResult.FEATURE,
*** 641,677 **** ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); } // Inefficient, but array is small ! 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; } /** * Return the state of the services mechanism feature. */ public boolean useServicesMechnism() { return _useServicesMechanism; } ! /** * @return the feature manager */ public JdkXmlFeatures getJdkXmlFeatures() { return _xmlFeatures; } --- 618,656 ---- ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); } // Inefficient, but array is small ! 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 JdkXmlFeatues int index = _xmlFeatures.getIndex(name); if (index > -1) { return _xmlFeatures.getFeature(index); } ! // feature not supported return false; } + /** * Return the state of the services mechanism feature. */ public boolean useServicesMechnism() { return _useServicesMechanism; } ! /** * @return the feature manager */ public JdkXmlFeatures getJdkXmlFeatures() { return _xmlFeatures; }
*** 832,842 **** final Templates templates = newTemplates(source); final Transformer transformer = templates.newTransformer(); if (_uriResolver != null) { transformer.setURIResolver(_uriResolver); } ! return(transformer); } /** * Pass warning messages from the compiler to the error listener */ --- 811,821 ---- final Templates templates = newTemplates(source); final Transformer transformer = templates.newTransformer(); if (_uriResolver != null) { transformer.setURIResolver(_uriResolver); } ! return transformer; } /** * Pass warning messages from the compiler to the error listener */
*** 985,1005 **** if (_uriResolver != null || ( _catalogFiles != null && _xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG))) { xsltc.setSourceLoader(this); } - // Pass parameters to the Parser to make sure it locates the correct - // <?xml-stylesheet ...?> PI in an XML input document - if ((_piParams != null) && (_piParams.get(source) != null)) { - // Get the parameters for this Source object - PIParamWrapper p = _piParams.get(source); - // Pass them on to the compiler (which will pass then to the parser) - if (p != null) { - xsltc.setPIParameters(p._media, p._title, p._charset); - } - } - // Set the attributes for translet generation int outputType = XSLTC.BYTEARRAY_OUTPUT; if (_generateTranslet || _autoTranslet) { // Set the translet name xsltc.setClassName(getTransletBaseName(source)); --- 964,973 ----
*** 1440,1450 **** if (transletTimestamp < xslTimestamp) return null; } // Load the translet into a bytecode array. ! Vector bytecodes = new Vector(); int fileLength = (int)transletFile.length(); if (fileLength > 0) { FileInputStream input; try { input = new FileInputStream(transletFile); --- 1408,1418 ---- if (transletTimestamp < xslTimestamp) return null; } // Load the translet into a bytecode array. ! ArrayList<byte[]> bytecodes = new ArrayList<>(); int fileLength = (int)transletFile.length(); if (fileLength > 0) { FileInputStream input; try { input = new FileInputStream(transletFile);
*** 1460,1473 **** } catch (IOException e) { return null; } ! bytecodes.addElement(bytes); ! } ! else return null; // Find the parent directory of the translet. String transletParentDir = transletFile.getParent(); if (transletParentDir == null) transletParentDir = SecuritySupport.getSystemProperty("user.dir"); --- 1428,1441 ---- } catch (IOException e) { return null; } ! bytecodes.add(bytes); ! } else { return null; + } // Find the parent directory of the translet. String transletParentDir = transletFile.getParent(); if (transletParentDir == null) transletParentDir = SecuritySupport.getSystemProperty("user.dir");
*** 1506,1525 **** } catch (IOException e) { continue; } ! bytecodes.addElement(bytes); } } // Convert the Vector of byte[] to byte[][]. final int count = bytecodes.size(); if ( count > 0) { final byte[][] result = new byte[count][1]; for (int i = 0; i < count; i++) { ! result[i] = (byte[])bytecodes.elementAt(i); } return result; } else --- 1474,1493 ---- } catch (IOException e) { continue; } ! bytecodes.add(bytes); } } // Convert the Vector of byte[] to byte[][]. final int count = bytecodes.size(); if ( count > 0) { final byte[][] result = new byte[count][1]; for (int i = 0; i < count; i++) { ! result[i] = bytecodes.get(i); } return result; } else
*** 1564,1625 **** if (transletTimestamp < xslTimestamp) return null; } // Create a ZipFile object for the jar file ! ZipFile jarFile; ! try { ! jarFile = new ZipFile(file); ! } ! catch (IOException e) { ! return null; ! } ! ! String transletPath = fullClassName.replace('.', '/'); ! String transletAuxPrefix = transletPath + "$"; ! String transletFullName = transletPath + ".class"; ! ! Vector bytecodes = new Vector(); ! ! // Iterate through all entries in the jar file to find the ! // translet and auxiliary classes. ! Enumeration entries = jarFile.entries(); ! while (entries.hasMoreElements()) ! { ! ZipEntry entry = (ZipEntry)entries.nextElement(); ! String entryName = entry.getName(); ! if (entry.getSize() > 0 && ! (entryName.equals(transletFullName) || ! (entryName.endsWith(".class") && entryName.startsWith(transletAuxPrefix)))) ! { ! try { InputStream input = jarFile.getInputStream(entry); int size = (int)entry.getSize(); byte[] bytes = new byte[size]; readFromInputStream(bytes, input, size); input.close(); ! bytecodes.addElement(bytes); ! } ! catch (IOException e) { ! return null; } } - } ! // Convert the Vector of byte[] to byte[][]. ! final int count = bytecodes.size(); ! if (count > 0) { ! final byte[][] result = new byte[count][1]; ! for (int i = 0; i < count; i++) { ! result[i] = (byte[])bytecodes.elementAt(i); } ! ! return result; ! } ! else return null; } /** * Read a given number of bytes from the InputStream into a byte array. * --- 1532,1582 ---- if (transletTimestamp < xslTimestamp) return null; } // Create a ZipFile object for the jar file ! try (ZipFile jarFile = new ZipFile(file)) { ! String transletPath = fullClassName.replace('.', '/'); ! String transletAuxPrefix = transletPath + "$"; ! String transletFullName = transletPath + ".class"; ! ! ArrayList<byte[]> bytecodes = new ArrayList<>(); ! ! // Iterate through all entries in the jar file to find the ! // translet and auxiliary classes. ! Enumeration<? extends ZipEntry> entries = jarFile.entries(); ! while (entries.hasMoreElements()) { ! ZipEntry entry = entries.nextElement(); ! String entryName = entry.getName(); ! if (entry.getSize() > 0 && ! (entryName.equals(transletFullName) || ! (entryName.endsWith(".class") && entryName.startsWith(transletAuxPrefix)))) ! { InputStream input = jarFile.getInputStream(entry); int size = (int)entry.getSize(); byte[] bytes = new byte[size]; readFromInputStream(bytes, input, size); input.close(); ! bytecodes.add(bytes); } } ! // Convert the Vector of byte[] to byte[][]. ! final int count = bytecodes.size(); ! if (count > 0) { ! final byte[][] result = new byte[count][1]; ! for (int i = 0; i < count; i++) { ! result[i] = bytecodes.get(i); ! } ! return result; ! } else { ! return null; } ! } catch (IOException e) { return null; + } } /** * Read a given number of bytes from the InputStream into a byte array. *
*** 1628,1644 **** * @param size The number of bytes to read. */ private void readFromInputStream(byte[] bytes, InputStream input, int size) throws IOException { ! int n = 0; ! int offset = 0; ! int length = size; ! while (length > 0 && (n = input.read(bytes, offset, length)) > 0) { ! offset = offset + n; ! length = length - n; ! } } /** * Return the base class name of the translet. * The translet name is resolved using the following rules: --- 1585,1601 ---- * @param size The number of bytes to read. */ private void readFromInputStream(byte[] bytes, InputStream input, int size) throws IOException { ! int n = 0; ! int offset = 0; ! int length = size; ! while (length > 0 && (n = input.read(bytes, offset, length)) > 0) { ! offset = offset + n; ! length = length - n; ! } } /** * Return the base class name of the translet. * The translet name is resolved using the following rules:
*** 1648,1659 **** * 3. return "GregorSamsa" if the result from step 2 is null. * * @param source The input Source * @return The name of the translet class */ ! private String getTransletBaseName(Source source) ! { String transletBaseName = null; if (!_transletName.equals(DEFAULT_TRANSLET_NAME)) return _transletName; else { String systemId = source.getSystemId(); --- 1605,1615 ---- * 3. return "GregorSamsa" if the result from step 2 is null. * * @param source The input Source * @return The name of the translet class */ ! private String getTransletBaseName(Source source) { String transletBaseName = null; if (!_transletName.equals(DEFAULT_TRANSLET_NAME)) return _transletName; else { String systemId = source.getSystemId();
*** 1674,1685 **** * * @param source The Source * @return The file name in the local filesystem, or null if the * systemId does not represent a local file. */ ! private String getStylesheetFileName(Source source) ! { String systemId = source.getSystemId(); if (systemId != null) { File file = new File(systemId); if (file.exists()) return systemId; --- 1630,1640 ---- * * @param source The Source * @return The file name in the local filesystem, or null if the * systemId does not represent a local file. */ ! private String getStylesheetFileName(Source source) { String systemId = source.getSystemId(); if (systemId != null) { File file = new File(systemId); if (file.exists()) return systemId;
*** 1695,1707 **** if ("file".equals(url.getProtocol())) return url.getFile(); else return null; } ! } ! else return null; } /** * Returns a new instance of the XSLTC DTM Manager service. */ --- 1650,1662 ---- if ("file".equals(url.getProtocol())) return url.getFile(); else return null; } ! } else { return null; + } } /** * Returns a new instance of the XSLTC DTM Manager service. */
< prev index next >