8129572: Cleanup usage of getResourceAsStream in jaxp
Reviewed-by: alanb, joehw, mchung, redestad
This commit is contained in:
parent
9ced0d90d5
commit
4ebbfc918f
@ -24,7 +24,6 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ClassLoader;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
@ -115,33 +114,6 @@ public final class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return resource using the same classloader for the ObjectFactory by
|
||||
* default or bootclassloader when Security Manager is in place
|
||||
*/
|
||||
public static InputStream getResourceAsStream(final String name) {
|
||||
if (System.getSecurityManager() != null) {
|
||||
return getResourceAsStream(null, name);
|
||||
} else {
|
||||
return getResourceAsStream(findClassLoader(), name);
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name) {
|
||||
return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream("/" + name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource bundle using the specified base name, the default locale,
|
||||
* and the caller's class loader.
|
||||
|
@ -128,29 +128,10 @@ public final class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return resource using the same classloader for the ObjectFactory by
|
||||
* default or bootclassloader when Security Manager is in place
|
||||
*/
|
||||
public static InputStream getResourceAsStream(final String name) {
|
||||
if (System.getSecurityManager()!=null) {
|
||||
return getResourceAsStream(null, name);
|
||||
} else {
|
||||
return getResourceAsStream(ObjectFactory.findClassLoader(), name);
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name) {
|
||||
return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream("/"+name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
return SecuritySupport.class.getResourceAsStream("/"+name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -118,34 +118,6 @@ public final class SecuritySupport {
|
||||
throw (FileNotFoundException)e.getException();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return resource using the same classloader for the ObjectFactory by default
|
||||
* or bootclassloader when Security Manager is in place
|
||||
*/
|
||||
public static InputStream getResourceAsStream(final String name) {
|
||||
if (System.getSecurityManager()!=null) {
|
||||
return getResourceAsStream(null, name);
|
||||
} else {
|
||||
return getResourceAsStream(ObjectFactory.findClassLoader(), name);
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream("/"+name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
|
||||
|
@ -23,7 +23,6 @@ package com.sun.org.apache.xerces.internal.xinclude;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
@ -113,23 +112,6 @@ final class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = ClassLoader.getSystemResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean getFileExists(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -23,7 +23,6 @@ package com.sun.org.apache.xml.internal.serialize;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
@ -113,23 +112,6 @@ final class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = ClassLoader.getSystemResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean getFileExists(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -27,11 +27,9 @@ import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.XPathContext;
|
||||
import com.sun.org.apache.xpath.internal.objects.XNumber;
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import com.sun.org.apache.xpath.internal.objects.XString;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
|
||||
/**
|
||||
@ -69,7 +67,7 @@ public class FuncSystemProperty extends FunctionOneArg
|
||||
// property argument is to be looked for.
|
||||
Properties xsltInfo = new Properties();
|
||||
|
||||
loadPropertyFile(XSLT_PROPERTIES, xsltInfo);
|
||||
loadPropertyFile(xsltInfo);
|
||||
|
||||
if (indexOfNSSep > 0)
|
||||
{
|
||||
@ -159,25 +157,21 @@ public class FuncSystemProperty extends FunctionOneArg
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a propery bundle from a specified file
|
||||
* Retrieve a property bundle from a XSLT_PROPERTIES
|
||||
*
|
||||
* @param file The string name of the property file. The name
|
||||
* should already be fully qualified as path/filename
|
||||
* @param target The target property bag the file will be placed into.
|
||||
*/
|
||||
public void loadPropertyFile(String file, Properties target)
|
||||
private void loadPropertyFile(Properties target)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Use SecuritySupport class to provide priveleged access to property file
|
||||
InputStream is = SecuritySupport.getResourceAsStream(ObjectFactory.findClassLoader(),
|
||||
file);
|
||||
// Use SecuritySupport class to provide privileged access to property file
|
||||
InputStream is = SecuritySupport.getResourceAsStream(XSLT_PROPERTIES);
|
||||
|
||||
// get a buffered version
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
|
||||
target.load(bis); // and load up the property bag from this
|
||||
bis.close(); // close out after reading
|
||||
try (BufferedInputStream bis = new BufferedInputStream(is)) {
|
||||
target.load(bis); // and load up the property bag from this
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -26,9 +26,7 @@
|
||||
package javax.xml.datatype;
|
||||
|
||||
import java.security.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class is duplicated for each JAXP subpackage so keep it in sync.
|
||||
@ -77,23 +75,6 @@ class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -26,9 +26,7 @@
|
||||
package javax.xml.parsers;
|
||||
|
||||
import java.security.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class is duplicated for each JAXP subpackage so keep it in sync.
|
||||
@ -81,23 +79,6 @@ class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -26,9 +26,7 @@
|
||||
package javax.xml.stream;
|
||||
|
||||
import java.security.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class is duplicated for each JAXP subpackage so keep it in sync.
|
||||
@ -81,23 +79,6 @@ class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -26,9 +26,7 @@
|
||||
package javax.xml.transform;
|
||||
|
||||
import java.security.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class is duplicated for each JAXP subpackage so keep it in sync.
|
||||
@ -79,23 +77,6 @@ class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -28,7 +28,6 @@ package javax.xml.validation;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.security.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
@ -134,23 +133,6 @@ class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -27,7 +27,6 @@ package javax.xml.xpath;
|
||||
|
||||
import java.net.URL;
|
||||
import java.security.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
@ -131,23 +130,6 @@ class SecuritySupport {
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
@ -87,7 +87,7 @@ class SecuritySupport {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = Object.class.getResourceAsStream(name);
|
||||
ris = SecuritySupport.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
|
@ -134,6 +134,9 @@ public class LSSerializerTest {
|
||||
DOMImplementation impl = doc.getImplementation();
|
||||
DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
|
||||
LSSerializer writer = implLS.createLSSerializer();
|
||||
|
||||
System.out.println("Serializer is: " + implLS.getClass().getName() + " " + implLS);
|
||||
|
||||
DOMErrorHandlerImpl eh = new DOMErrorHandlerImpl();
|
||||
writer.getDomConfig().setParameter("error-handler", eh);
|
||||
|
||||
@ -200,6 +203,8 @@ public class LSSerializerTest {
|
||||
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation;
|
||||
LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
|
||||
|
||||
System.out.println("Serializer is: " + lsSerializer.getClass().getName() + " " + lsSerializer);
|
||||
|
||||
// get configuration
|
||||
DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
|
||||
|
||||
@ -294,6 +299,8 @@ public class LSSerializerTest {
|
||||
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation;
|
||||
LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
|
||||
|
||||
System.out.println("Serializer is: " + lsSerializer.getClass().getName() + " " + lsSerializer);
|
||||
|
||||
// get default serialization
|
||||
String defaultSerialization = lsSerializer.writeToString(document);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user