/hg/release/icedtea7-forest-2.4/jaxp: 2 new changesets
andrew at icedtea.classpath.org
andrew at icedtea.classpath.org
Tue Apr 15 20:50:14 UTC 2014
changeset 9c07ba84aaa3 in /hg/release/icedtea7-forest-2.4/jaxp
details: http://icedtea.classpath.org/hg/release/icedtea7-forest-2.4/jaxp?cmd=changeset;node=9c07ba84aaa3
author: aefimov
date: Mon Jan 13 19:07:53 2014 +0400
8029282: Enhance CharInfo set up
Reviewed-by: joehw
changeset 94b7e8e0d96f in /hg/release/icedtea7-forest-2.4/jaxp
details: http://icedtea.classpath.org/hg/release/icedtea7-forest-2.4/jaxp?cmd=changeset;node=94b7e8e0d96f
author: aefimov
date: Thu Jan 16 12:56:28 2014 +0400
8031330: Refactor ObjectFactory
Reviewed-by: joehw
diffstat:
src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java | 25 +-
src/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java | 2 +-
src/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java | 14 +-
src/com/sun/org/apache/xml/internal/serializer/CharInfo.java | 125 ++++-----
src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java | 2 +-
src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java | 2 +-
6 files changed, 77 insertions(+), 93 deletions(-)
diffs (353 lines):
diff -r 076644826249 -r 94b7e8e0d96f src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java
--- a/src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java Wed Mar 26 16:03:42 2014 +0000
+++ b/src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java Thu Jan 16 12:56:28 2014 +0400
@@ -54,8 +54,8 @@
//
// Constants
//
- private static final String XALAN_INTERNAL = "com.sun.org.apache.xalan.internal";
- private static final String XERCES_INTERNAL = "com.sun.org.apache.xerces.internal";
+ private static final String JAXP_INTERNAL = "com.sun.org.apache";
+ private static final String STAX_INTERNAL = "com.sun.xml.internal";
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
@@ -497,12 +497,8 @@
public static Class findProviderClass(String className, boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
- if (System.getSecurityManager()!=null) {
- return Class.forName(className);
- } else {
- return findProviderClass (className,
+ return findProviderClass (className,
findClassLoader (), doFallback);
- }
}
/**
@@ -517,8 +513,8 @@
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
- if (className.startsWith(XALAN_INTERNAL) ||
- className.startsWith(XERCES_INTERNAL)) {
+ if (className.startsWith(JAXP_INTERNAL) ||
+ className.startsWith(STAX_INTERNAL)) {
cl = null;
} else {
final int lastDot = className.lastIndexOf(".");
@@ -533,16 +529,7 @@
Class providerClass;
if (cl == null) {
- // XXX Use the bootstrap ClassLoader. There is no way to
- // load a class using the bootstrap ClassLoader that works
- // in both JDK 1.1 and Java 2. However, this should still
- // work b/c the following should be true:
- //
- // (cl == null) iff current ClassLoader == null
- //
- // Thus Class.forName(String) will use the current
- // ClassLoader which will be the bootstrap ClassLoader.
- providerClass = Class.forName(className);
+ providerClass = Class.forName(className, false, ObjectFactory.class.getClassLoader());
} else {
try {
providerClass = cl.loadClass(className);
diff -r 076644826249 -r 94b7e8e0d96f src/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java
--- a/src/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java Wed Mar 26 16:03:42 2014 +0000
+++ b/src/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java Thu Jan 16 12:56:28 2014 +0400
@@ -57,7 +57,7 @@
return securitySupport;
}
- static ClassLoader getContextClassLoader() {
+ public static ClassLoader getContextClassLoader() {
return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
diff -r 076644826249 -r 94b7e8e0d96f src/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java
--- a/src/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java Wed Mar 26 16:03:42 2014 +0000
+++ b/src/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java Thu Jan 16 12:56:28 2014 +0400
@@ -48,7 +48,8 @@
//
// Constants
//
- private static final String DEFAULT_INTERNAL_CLASSES = "com.sun.org.apache.";
+ private static final String JAXP_INTERNAL = "com.sun.org.apache";
+ private static final String STAX_INTERNAL = "com.sun.xml.internal";
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME = "xerces.properties";
@@ -288,12 +289,8 @@
public static Class findProviderClass(String className, boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
- if (System.getSecurityManager()!=null) {
- return Class.forName(className);
- } else {
- return findProviderClass (className,
+ return findProviderClass (className,
findClassLoader (), doFallback);
- }
}
/**
* Find a Class using the specified ClassLoader
@@ -306,7 +303,8 @@
//restrict the access to package as speicified in java.security policy
SecurityManager security = System.getSecurityManager();
if (security != null) {
- if (className.startsWith(DEFAULT_INTERNAL_CLASSES)) {
+ if (className.startsWith(JAXP_INTERNAL) ||
+ className.startsWith(STAX_INTERNAL)) {
cl = null;
} else {
final int lastDot = className.lastIndexOf(".");
@@ -318,7 +316,7 @@
Class providerClass;
if (cl == null) {
//use the bootstrap ClassLoader.
- providerClass = Class.forName(className);
+ providerClass = Class.forName(className, false, ObjectFactory.class.getClassLoader());
} else {
try {
providerClass = cl.loadClass(className);
diff -r 076644826249 -r 94b7e8e0d96f src/com/sun/org/apache/xml/internal/serializer/CharInfo.java
--- a/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java Wed Mar 26 16:03:42 2014 +0000
+++ b/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java Thu Jan 16 12:56:28 2014 +0400
@@ -22,6 +22,11 @@
*/
package com.sun.org.apache.xml.internal.serializer;
+import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
+import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
+import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver;
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -29,19 +34,11 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
import javax.xml.transform.TransformerException;
-import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
-import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver;
-import com.sun.org.apache.xml.internal.serializer.utils.Utils;
-import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
-import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
-
/**
* This class provides services that tell if a character should have
* special treatement, such as entity reference substitution or normalization
@@ -176,13 +173,19 @@
// file
// 3) try treating the resource a URI
- if (internal) {
- try {
+ try {
+ if (internal) {
// Load entity property files by using PropertyResourceBundle,
// cause of security issure for applets
entities = PropertyResourceBundle.getBundle(entitiesResource);
- } catch (Exception e) {}
- }
+ } else {
+ ClassLoader cl = SecuritySupport.getContextClassLoader();
+ if (cl != null) {
+ entities = PropertyResourceBundle.getBundle(entitiesResource,
+ Locale.getDefault(), cl);
+ }
+ }
+ } catch (Exception e) {}
if (entities != null) {
Enumeration keys = entities.getKeys();
@@ -198,6 +201,7 @@
set(S_CARRIAGERETURN);
} else {
InputStream is = null;
+ String err = null;
// Load user specified resource file by using URL loading, it
// requires a valid URI as parameter
@@ -205,18 +209,22 @@
if (internal) {
is = CharInfo.class.getResourceAsStream(entitiesResource);
} else {
- ClassLoader cl = ObjectFactory.findClassLoader();
- if (cl == null) {
- is = ClassLoader.getSystemResourceAsStream(entitiesResource);
- } else {
- is = cl.getResourceAsStream(entitiesResource);
+ ClassLoader cl = SecuritySupport.getContextClassLoader();
+ if (cl != null) {
+ try {
+ is = cl.getResourceAsStream(entitiesResource);
+ } catch (Exception e) {
+ err = e.getMessage();
+ }
}
if (is == null) {
try {
URL url = new URL(entitiesResource);
is = url.openStream();
- } catch (Exception e) {}
+ } catch (Exception e) {
+ err = e.getMessage();
+ }
}
}
@@ -224,7 +232,7 @@
throw new RuntimeException(
Utils.messages.createMessage(
MsgKey.ER_RESOURCE_COULD_NOT_FIND,
- new Object[] {entitiesResource, entitiesResource}));
+ new Object[] {entitiesResource, err}));
}
// Fix Bugzilla#4000: force reading in UTF-8
@@ -456,64 +464,56 @@
return isCleanTextASCII[value];
}
-// In the future one might want to use the array directly and avoid
-// the method call, but I think the JIT alreay inlines this well enough
-// so don't do it (for now) - bjm
-// public final boolean[] getASCIIClean()
-// {
-// return isCleanTextASCII;
-// }
+ /**
+ * Read an internal resource file that describes the mapping of
+ * characters to entity references; Construct a CharInfo object.
+ *
+ * @param entitiesFileName Name of entities resource file that should
+ * be loaded, which describes the mapping of characters to entity references.
+ * @param method the output method type, which should be one of "xml", "html", and "text".
+ * @return an instance of CharInfo
+ *
+ * @xsl.usage internal
+ */
+ static CharInfo getCharInfoInternal(String entitiesFileName, String method)
+ {
+ CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName);
+ if (charInfo != null) {
+ return charInfo;
+ }
- private static CharInfo getCharInfoBasedOnPrivilege(
- final String entitiesFileName, final String method,
- final boolean internal){
- return (CharInfo) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return new CharInfo(entitiesFileName,
- method, internal);}
- });
+ charInfo = new CharInfo(entitiesFileName, method, true);
+ m_getCharInfoCache.put(entitiesFileName, charInfo);
+ return charInfo;
}
/**
- * Factory that reads in a resource file that describes the mapping of
- * characters to entity references.
+ * Constructs a CharInfo object using the following process to try reading
+ * the entitiesFileName parameter:
*
- * Resource files must be encoded in UTF-8 and have a format like:
+ * 1) attempt to load it as a ResourceBundle
+ * 2) try using the class loader to find the specified file
+ * 3) try opening it as an URI
+ *
+ * In case of 2 and 3, the resource file must be encoded in UTF-8 and have the
+ * following format:
* <pre>
* # First char # is a comment
* Entity numericValue
* quot 34
* amp 38
* </pre>
- * (Note: Why don't we just switch to .properties files? Oct-01 -sc)
*
- * @param entitiesResource Name of entities resource file that should
- * be loaded, which describes that mapping of characters to entity references.
- * @param method the output method type, which should be one of "xml", "html", "text"...
- *
- * @xsl.usage internal
+ * @param entitiesFileName Name of entities resource file that should
+ * be loaded, which describes the mapping of characters to entity references.
+ * @param method the output method type, which should be one of "xml", "html", and "text".
+ * @return an instance of CharInfo
*/
static CharInfo getCharInfo(String entitiesFileName, String method)
{
- CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName);
- if (charInfo != null) {
- return charInfo;
- }
-
- // try to load it internally - cache
try {
- charInfo = getCharInfoBasedOnPrivilege(entitiesFileName,
- method, true);
- m_getCharInfoCache.put(entitiesFileName, charInfo);
- return charInfo;
- } catch (Exception e) {}
-
- // try to load it externally - do not cache
- try {
- return getCharInfoBasedOnPrivilege(entitiesFileName,
- method, false);
+ return new CharInfo(entitiesFileName, method, false);
} catch (Exception e) {}
String absoluteEntitiesFileName;
@@ -530,8 +530,7 @@
}
}
- return getCharInfoBasedOnPrivilege(entitiesFileName,
- method, false);
+ return new CharInfo(absoluteEntitiesFileName, method, false);
}
/** Table of user-specified char infos. */
diff -r 076644826249 -r 94b7e8e0d96f src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
--- a/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java Wed Mar 26 16:03:42 2014 +0000
+++ b/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java Thu Jan 16 12:56:28 2014 +0400
@@ -60,7 +60,7 @@
*/
private static final CharInfo m_htmlcharInfo =
// new CharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
- CharInfo.getCharInfo(CharInfo.HTML_ENTITIES_RESOURCE, Method.HTML);
+ CharInfo.getCharInfoInternal(CharInfo.HTML_ENTITIES_RESOURCE, Method.HTML);
/** A digital search trie for fast, case insensitive lookup of ElemDesc objects. */
static final Trie m_elementFlags = new Trie();
diff -r 076644826249 -r 94b7e8e0d96f src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
--- a/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java Wed Mar 26 16:03:42 2014 +0000
+++ b/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java Thu Jan 16 12:56:28 2014 +0400
@@ -58,7 +58,7 @@
*/
private static CharInfo m_xmlcharInfo =
// new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
- CharInfo.getCharInfo(CharInfo.XML_ENTITIES_RESOURCE, Method.XML);
+ CharInfo.getCharInfoInternal(CharInfo.XML_ENTITIES_RESOURCE, Method.XML);
/**
* Default constructor.
More information about the distro-pkg-dev
mailing list