mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 12:04:39 +02:00
Initial load
This commit is contained in:
parent
686d76f772
commit
74f4779697
1972 changed files with 585739 additions and 0 deletions
110
jaxp/src/share/classes/javax/xml/stream/SecuritySupport.java
Normal file
110
jaxp/src/share/classes/javax/xml/stream/SecuritySupport.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
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.
|
||||
* It is package private and therefore is not exposed as part of the JAXP
|
||||
* API.
|
||||
*
|
||||
* Security related methods that only work on J2SE 1.2 and newer.
|
||||
*/
|
||||
class SecuritySupport {
|
||||
|
||||
|
||||
ClassLoader getContextClassLoader() throws SecurityException{
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
//try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
//} catch (SecurityException ex) { }
|
||||
|
||||
if (cl == null)
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String getSystemProperty(final String propName) {
|
||||
return (String)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(propName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FileInputStream getFileInputStream(final File file)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
try {
|
||||
return (FileInputStream)
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws FileNotFoundException {
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (FileNotFoundException)e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
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 doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Boolean(f.exists());
|
||||
}
|
||||
})).booleanValue();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue