SecuritySupport.java revision 754:17b47acf5b3d
120253Sjoerg/* 220302Sjoerg * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved. 320302Sjoerg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 420253Sjoerg * 520253Sjoerg * This code is free software; you can redistribute it and/or modify it 620253Sjoerg * under the terms of the GNU General Public License version 2 only, as 720253Sjoerg * published by the Free Software Foundation. Oracle designates this 820253Sjoerg * particular file as subject to the "Classpath" exception as provided 920302Sjoerg * by Oracle in the LICENSE file that accompanied this code. 1020253Sjoerg * 1120253Sjoerg * This code is distributed in the hope that it will be useful, but WITHOUT 1220253Sjoerg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1320253Sjoerg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1420302Sjoerg * version 2 for more details (a copy is included in the LICENSE file that 1520253Sjoerg * accompanied this code). 1620253Sjoerg * 1720302Sjoerg * You should have received a copy of the GNU General Public License version 1820253Sjoerg * 2 along with this work; if not, write to the Free Software Foundation, 1920253Sjoerg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2020253Sjoerg * 2120253Sjoerg * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2220253Sjoerg * or visit www.oracle.com if you need additional information or have any 2320253Sjoerg * questions. 2420253Sjoerg */ 2520253Sjoerg 2620253Sjoergpackage javax.xml.transform; 2730259Scharnier 2830259Scharnierimport java.security.*; 2944229Sdavidnimport java.io.*; 3030259Scharnier 3130259Scharnier/** 3220253Sjoerg * This class is duplicated for each JAXP subpackage so keep it in sync. 3320253Sjoerg * It is package private and therefore is not exposed as part of the JAXP 3420253Sjoerg * API. 3520253Sjoerg * 3620253Sjoerg * Security related methods that only work on J2SE 1.2 and newer. 3720253Sjoerg */ 3820253Sjoergclass SecuritySupport { 3920253Sjoerg 4020253Sjoerg 4120253Sjoerg ClassLoader getContextClassLoader() throws SecurityException{ 4220253Sjoerg return (ClassLoader) 4320253Sjoerg AccessController.doPrivileged(new PrivilegedAction() { 4420253Sjoerg public Object run() { 4521330Sdavidn ClassLoader cl = null; 4620253Sjoerg //try { 4720253Sjoerg cl = Thread.currentThread().getContextClassLoader(); 4820253Sjoerg //} catch (SecurityException ex) { } 4920253Sjoerg if (cl == null) 5020253Sjoerg cl = ClassLoader.getSystemClassLoader(); 5120253Sjoerg return cl; 5220253Sjoerg } 5320253Sjoerg }); 5420253Sjoerg } 5520253Sjoerg 5620253Sjoerg String getSystemProperty(final String propName) { 5720253Sjoerg return (String) 5820253Sjoerg AccessController.doPrivileged(new PrivilegedAction() { 5920253Sjoerg public Object run() { 6020253Sjoerg return System.getProperty(propName); 6120253Sjoerg } 6220253Sjoerg }); 6320253Sjoerg } 6420253Sjoerg 6520253Sjoerg FileInputStream getFileInputStream(final File file) 6620253Sjoerg throws FileNotFoundException 6720253Sjoerg { 6820253Sjoerg try { 6920253Sjoerg return (FileInputStream) 7020253Sjoerg AccessController.doPrivileged(new PrivilegedExceptionAction() { 7120253Sjoerg public Object run() throws FileNotFoundException { 7220253Sjoerg return new FileInputStream(file); 7320253Sjoerg } 7420253Sjoerg }); 7520253Sjoerg } catch (PrivilegedActionException e) { 7620253Sjoerg throw (FileNotFoundException)e.getException(); 7720253Sjoerg } 7820253Sjoerg } 7920253Sjoerg 8020253Sjoerg boolean doesFileExist(final File f) { 8120253Sjoerg return ((Boolean) 8220253Sjoerg AccessController.doPrivileged(new PrivilegedAction() { 8320253Sjoerg public Object run() { 8420253Sjoerg return new Boolean(f.exists()); 8520253Sjoerg } 8620253Sjoerg })).booleanValue(); 8721330Sdavidn } 8820253Sjoerg 8920253Sjoerg} 9020253Sjoerg