8132091: Clean up JAXP code that has dependency on Java version string

Reviewed-by: lancea
This commit is contained in:
Joe Wang 2015-12-03 11:42:25 -08:00
parent 7ce24de93e
commit 60e4fa0770
7 changed files with 16 additions and 71 deletions

@ -221,27 +221,4 @@ public final class XalanConstants {
public static final String FEATURE_TRUE = "true";
public static final String FEATURE_FALSE = "false";
/**
* Check if we're in jdk8 or above
*/
public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
/*
* Check the major version of the current JDK against that specified
* in the parameter
*
* In JDK9 the java version string was changed to comply with JEP-223
* so this method was modified to handle that new format as well
*
* @param compareTo a JDK major version to be compared to
* @return true if the current major version is the same or above
* that represented by the parameter
*/
public static boolean isJavaVersionAtLeast(int compareTo) {
String javaVersion = SecuritySupport.getSystemProperty("java.version");
javaVersion = (javaVersion.matches("[1-9][0-9]*(\\.(0|[1-9][0-9]*))*\\-.*")) ?
javaVersion.split("-|\\.")[0] :
javaVersion.split("\\.", 3)[1];
return Integer.parseInt(javaVersion) >= compareTo;
}
} // class Constants

@ -524,7 +524,7 @@ public class TransformerFactoryImpl
_xmlSecurityManager.setSecureProcessing(value);
// set external access restriction when FSP is explicitly set
if (value && XalanConstants.IS_JDK8_OR_ABOVE) {
if (value) {
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET,
@ -539,7 +539,6 @@ public class TransformerFactoryImpl
_featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION,
FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE);
}
return;
}
else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
//in secure mode, let _useServicesMechanism be determined by the constructor

@ -203,11 +203,6 @@ public final class Constants {
*/
public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
/**
* Check if we're in jdk8 or above
*/
public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
//
// Implementation limits: corresponding System Properties of the above
// API properties
@ -856,25 +851,6 @@ public final class Constants {
? new ArrayEnumeration(fgXercesProperties) : fgEmptyEnumeration;
} // getXercesProperties():Enumeration
/*
* Check the major version of the current JDK against that specified
* in the parameter
*
* In JDK9 the java version string was changed to comply with JEP-223
* so this method was modified to handle that new format as well
*
* @param compareTo a JDK major version to be compared to
* @return true if the current major version is the same or above
* that represented by the parameter
*/
public static boolean isJavaVersionAtLeast(int compareTo) {
String javaVersion = SecuritySupport.getSystemProperty("java.version");
javaVersion = (javaVersion.matches("[1-9][0-9]*(\\.(0|[1-9][0-9]*))*\\-.*")) ?
javaVersion.split("-|\\.")[0] :
javaVersion.split("\\.", 3)[1];
return Integer.parseInt(javaVersion) >= compareTo;
}
//
// Classes
//

@ -184,13 +184,11 @@ public class DocumentBuilderImpl extends DocumentBuilder
*/
if (features != null) {
Boolean temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
if (temp != null) {
if (temp && Constants.IS_JDK8_OR_ABOVE) {
fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_SCHEMA,
State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
if (temp != null && temp) {
fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_SCHEMA,
State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
}
}

@ -164,14 +164,11 @@ public class SAXParserImpl extends javax.xml.parsers.SAXParser
if (features != null) {
Boolean temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
if (temp != null) {
if (temp && Constants.IS_JDK8_OR_ABOVE) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
if (temp != null && temp) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
}
}

@ -427,12 +427,10 @@ public final class XMLSchemaFactory extends SchemaFactory {
fSecurityManager.setSecureProcessing(value);
if (value) {
if (Constants.IS_JDK8_OR_ABOVE) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);

@ -364,7 +364,7 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
fInitSecurityManager.setSecureProcessing(value);
setProperty(SECURITY_MANAGER, fInitSecurityManager);
if (value && Constants.IS_JDK8_OR_ABOVE) {
if (value) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,