Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/transform/SecuritySupport.java
32285 views
/*1* Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.transform;2627import java.security.*;28import java.net.*;29import java.io.*;30import java.util.*;3132/**33* This class is duplicated for each JAXP subpackage so keep it in sync.34* It is package private and therefore is not exposed as part of the JAXP35* API.36*37* Security related methods that only work on J2SE 1.2 and newer.38*/39class SecuritySupport {404142ClassLoader getContextClassLoader() throws SecurityException{43return (ClassLoader)44AccessController.doPrivileged(new PrivilegedAction() {45public Object run() {46ClassLoader cl = null;47//try {48cl = Thread.currentThread().getContextClassLoader();49//} catch (SecurityException ex) { }50if (cl == null)51cl = ClassLoader.getSystemClassLoader();52return cl;53}54});55}5657String getSystemProperty(final String propName) {58return (String)59AccessController.doPrivileged(new PrivilegedAction() {60public Object run() {61return System.getProperty(propName);62}63});64}6566FileInputStream getFileInputStream(final File file)67throws FileNotFoundException68{69try {70return (FileInputStream)71AccessController.doPrivileged(new PrivilegedExceptionAction() {72public Object run() throws FileNotFoundException {73return new FileInputStream(file);74}75});76} catch (PrivilegedActionException e) {77throw (FileNotFoundException)e.getException();78}79}8081InputStream getResourceAsStream(final ClassLoader cl,82final String name)83{84return (InputStream)85AccessController.doPrivileged(new PrivilegedAction() {86public Object run() {87InputStream ris;88if (cl == null) {89ris = Object.class.getResourceAsStream(name);90} else {91ris = cl.getResourceAsStream(name);92}93return ris;94}95});96}9798boolean doesFileExist(final File f) {99return ((Boolean)100AccessController.doPrivileged(new PrivilegedAction() {101public Object run() {102return new Boolean(f.exists());103}104})).booleanValue();105}106107}108109110