--- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java 2016-11-16 12:13:20.000000000 +0100 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java 2016-11-16 12:13:19.000000000 +0100 @@ -17,7 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.sun.org.apache.xalan.internal.xsltc.trax; import com.sun.org.apache.xalan.internal.XalanConstants; @@ -47,7 +46,6 @@ 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; @@ -150,27 +148,6 @@ private String _jarFileName = null; /** - * This Map is used to store parameters for locating - * processing instructions in XML docs. - */ - private Map _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 true when debugging is enabled. */ private boolean _debug = false; @@ -209,6 +186,7 @@ *

State of secure processing feature.

*/ private boolean _isNotSecureProcessing = true; + /** *

State of secure mode.

*/ @@ -222,6 +200,11 @@ private boolean _useServicesMechanism; /** + * Indicates whether a stream source should be handled namespace aware + */ + private boolean _namespaceAware = true; + + /** * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element. */ private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT; @@ -240,7 +223,7 @@ // Unmodifiable view of external extension function from xslt compiler // It will be populated by user-specified extension functions during the // type checking - private Map _xsltcExtensionFunctions; + private Map> _xsltcExtensionFunctions; CatalogResolver _catalogUriResolver; CatalogFeatures _catalogFeatures; @@ -283,7 +266,7 @@ _xsltcExtensionFunctions = null; } - public Map getExternalExtensionsMap() { + public Map> getExternalExtensionsMap() { return _xsltcExtensionFunctions; } @@ -558,9 +541,8 @@ 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)) { + } else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { if ((_isSecureMode) && (!value)) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE); throw new TransformerConfigurationException(err.toString()); @@ -584,15 +566,19 @@ _xmlFeatures.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION, JdkXmlFeatures.State.FSP, false); } - } - else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { + } else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { //in secure mode, let _useServicesMechanism be determined by the constructor if (!_isSecureMode) _useServicesMechanism = value; - } - else { + } else { if (_xmlFeatures != null && - _xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) { + _xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) { + return; + } + + // handle namespaces feature (used for Stream InputSource) + if (name.equals(Constants.NAMESPACE_FEATURE)) { + _namespaceAware = value; return; } @@ -613,7 +599,7 @@ */ @Override public boolean getFeature(String name) { - // All supported features should be listed here + // all supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, @@ -635,25 +621,32 @@ } // Inefficient, but array is small - for (int i =0; i < features.length; i++) { + 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 **/ + // 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 + // namespaces feature + if (name.equals(Constants.NAMESPACE_FEATURE)) { + return _namespaceAware; + } + + // feature not supported return false; } + /** * Return the state of the services mechanism feature. */ @@ -661,7 +654,7 @@ return _useServicesMechanism; } - /** + /** * @return the feature manager */ public JdkXmlFeatures getJdkXmlFeatures() { @@ -896,7 +889,7 @@ transletName = _packageName + "." + transletName; try { - final Class clazz = ObjectFactory.findProviderClass(transletName, true); + final Class clazz = ObjectFactory.findProviderClass(transletName, true); resetTransientAttributes(); templates = new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this); @@ -979,17 +972,6 @@ xsltc.setSourceLoader(this); } - // Pass parameters to the Parser to make sure it locates the correct - // 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) { @@ -1434,7 +1416,7 @@ } // Load the translet into a bytecode array. - Vector bytecodes = new Vector(); + ArrayList bytecodes = new ArrayList<>(); int fileLength = (int)transletFile.length(); if (fileLength > 0) { FileInputStream input; @@ -1454,10 +1436,10 @@ return null; } - bytecodes.addElement(bytes); - } - else + bytecodes.add(bytes); + } else { return null; + } // Find the parent directory of the translet. String transletParentDir = transletFile.getParent(); @@ -1500,7 +1482,7 @@ continue; } - bytecodes.addElement(bytes); + bytecodes.add(bytes); } } @@ -1509,7 +1491,7 @@ if ( count > 0) { final byte[][] result = new byte[count][1]; for (int i = 0; i < count; i++) { - result[i] = (byte[])bytecodes.elementAt(i); + result[i] = bytecodes.get(i); } return result; @@ -1558,58 +1540,47 @@ } // 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") && + try (ZipFile jarFile = new ZipFile(file)) { + String transletPath = fullClassName.replace('.', '/'); + String transletAuxPrefix = transletPath + "$"; + String transletFullName = transletPath + ".class"; + + ArrayList bytecodes = new ArrayList<>(); + + // Iterate through all entries in the jar file to find the + // translet and auxiliary classes. + Enumeration 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)))) - { - 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; + 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] = (byte[])bytecodes.elementAt(i); + // 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; } - - return result; - } - else + } catch (IOException e) { return null; + } } /** @@ -1622,13 +1593,13 @@ 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; - } + 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; + } } /** @@ -1642,8 +1613,7 @@ * @param source The input Source * @return The name of the translet class */ - private String getTransletBaseName(Source source) - { + private String getTransletBaseName(Source source) { String transletBaseName = null; if (!_transletName.equals(DEFAULT_TRANSLET_NAME)) return _transletName; @@ -1668,8 +1638,7 @@ * @return The file name in the local filesystem, or null if the * systemId does not represent a local file. */ - private String getStylesheetFileName(Source source) - { + private String getStylesheetFileName(Source source) { String systemId = source.getSystemId(); if (systemId != null) { File file = new File(systemId); @@ -1689,15 +1658,18 @@ else return null; } - } - else + } else { return null; + } } /** * Returns a new instance of the XSLTC DTM Manager service. */ protected final XSLTCDTMManager createNewDTMManagerInstance() { - return XSLTCDTMManager.createNewDTMManagerInstance(); + XSLTCDTMManager m = XSLTCDTMManager.createNewDTMManagerInstance(); + if (!_namespaceAware) + m.setNamespaceAware(false); + return m; } }