1 7 8 package javax.xml.parsers; 9 10 import java.security.*; 11 import java.net.*; 12 import java.io.*; 13 import java.util.*; 14 15 22 class SecuritySupport { 23 24 25 ClassLoader getContextClassLoader() { 26 return (ClassLoader ) 27 AccessController.doPrivileged(new PrivilegedAction() { 28 public Object run() { 29 ClassLoader cl = null; 30 try { 31 cl = Thread.currentThread().getContextClassLoader(); 32 } catch (SecurityException ex) { } 33 return cl; 34 } 35 }); 36 } 37 38 String getSystemProperty(final String propName) { 39 return (String ) 40 AccessController.doPrivileged(new PrivilegedAction() { 41 public Object run() { 42 return System.getProperty(propName); 43 } 44 }); 45 } 46 47 FileInputStream getFileInputStream(final File file) 48 throws FileNotFoundException 49 { 50 try { 51 return (FileInputStream) 52 AccessController.doPrivileged(new PrivilegedExceptionAction() { 53 public Object run() throws FileNotFoundException { 54 return new FileInputStream(file); 55 } 56 }); 57 } catch (PrivilegedActionException e) { 58 throw (FileNotFoundException)e.getException(); 59 } 60 } 61 62 InputStream getResourceAsStream(final ClassLoader cl, 63 final String name) 64 { 65 return (InputStream) 66 AccessController.doPrivileged(new PrivilegedAction() { 67 public Object run() { 68 InputStream ris; 69 if (cl == null) { 70 ris = ClassLoader.getSystemResourceAsStream(name); 71 } else { 72 ris = cl.getResourceAsStream(name); 73 } 74 return ris; 75 } 76 }); 77 } 78 79 boolean doesFileExist(final File f) { 80 return ((Boolean ) 81 AccessController.doPrivileged(new PrivilegedAction() { 82 public Object run() { 83 return new Boolean (f.exists()); 84 } 85 })).booleanValue(); 86 } 87 88 } 89 | Popular Tags |