< prev index next >
src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
Print this page
rev 1025 : 8023653: [JAXP] xalan inconsistently parses DOMSource and StreamSource
@@ -15,11 +15,10 @@
* 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.
*/
-
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.FeaturePropertyBase;
@@ -45,11 +44,10 @@
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;
@@ -148,31 +146,10 @@
* 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;
/**
@@ -207,10 +184,11 @@
/**
* <p>State of secure processing feature.</p>
*/
private boolean _isNotSecureProcessing = true;
+
/**
* <p>State of secure mode.</p>
*/
private boolean _isSecureMode = false;
@@ -220,10 +198,15 @@
* Note the default value (false) is the safe option..
*/
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;
/**
* protocols allowed for external DTD references in source file and/or stylesheet.
@@ -238,11 +221,11 @@
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;
+ private Map<String, Class<?>> _xsltcExtensionFunctions;
CatalogResolver _catalogUriResolver;
CatalogFeatures _catalogFeatures;
CatalogFeatures.Builder cfBuilder = CatalogFeatures.builder();
// Catalog features
@@ -281,11 +264,11 @@
_xmlSecurityManager = new XMLSecurityManager(true);
//Unmodifiable hash map with loaded external extension functions
_xsltcExtensionFunctions = null;
}
- public Map<String,Class> getExternalExtensionsMap() {
+ public Map<String, Class<?>> getExternalExtensionsMap() {
return _xsltcExtensionFunctions;
}
/**
* javax.xml.transform.sax.TransformerFactory implementation.
@@ -556,13 +539,12 @@
// 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)) {
+ } 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;
@@ -582,19 +564,23 @@
if (value && _xmlFeatures != null) {
_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;
}
// unknown feature
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
@@ -611,11 +597,11 @@
* @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
+ // all supported features should be listed here
String[] features = {
DOMSource.FEATURE,
DOMResult.FEATURE,
SAXSource.FEATURE,
SAXResult.FEATURE,
@@ -633,37 +619,44 @@
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++) {
+ 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.
*/
public boolean useServicesMechnism() {
return _useServicesMechanism;
}
- /**
+ /**
* @return the feature manager
*/
public JdkXmlFeatures getJdkXmlFeatures() {
return _xmlFeatures;
}
@@ -894,11 +887,11 @@
if (_packageName != null)
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);
if (_uriResolver != null) {
templates.setURIResolver(_uriResolver);
@@ -977,21 +970,10 @@
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));
@@ -1432,11 +1414,11 @@
if (transletTimestamp < xslTimestamp)
return null;
}
// Load the translet into a bytecode array.
- Vector bytecodes = new Vector();
+ ArrayList<byte[]> bytecodes = new ArrayList<>();
int fileLength = (int)transletFile.length();
if (fileLength > 0) {
FileInputStream input;
try {
input = new FileInputStream(transletFile);
@@ -1452,14 +1434,14 @@
}
catch (IOException e) {
return null;
}
- bytecodes.addElement(bytes);
- }
- else
+ 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");
@@ -1498,20 +1480,20 @@
}
catch (IOException e) {
continue;
}
- bytecodes.addElement(bytes);
+ 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);
+ result[i] = bytecodes.get(i);
}
return result;
}
else
@@ -1556,62 +1538,51 @@
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") &&
+ 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))))
- {
- 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;
+ }
}
/**
* Read a given number of bytes from the InputStream into a byte array.
*
@@ -1620,17 +1591,17 @@
* @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;
- }
+ 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:
@@ -1640,12 +1611,11 @@
* 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)
- {
+ private String getTransletBaseName(Source source) {
String transletBaseName = null;
if (!_transletName.equals(DEFAULT_TRANSLET_NAME))
return _transletName;
else {
String systemId = source.getSystemId();
@@ -1666,12 +1636,11 @@
*
* @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)
- {
+ private String getStylesheetFileName(Source source) {
String systemId = source.getSystemId();
if (systemId != null) {
File file = new File(systemId);
if (file.exists())
return systemId;
@@ -1687,17 +1656,20 @@
if ("file".equals(url.getProtocol()))
return url.getFile();
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;
}
}
< prev index next >