1 16 17 package org.xml.sax.helpers; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.FileNotFoundException ; 22 import java.io.InputStream ; 23 import java.security.AccessController ; 24 import java.security.PrivilegedAction ; 25 import java.security.PrivilegedActionException ; 26 import java.security.PrivilegedExceptionAction ; 27 28 35 class SecuritySupport12 extends SecuritySupport { 36 37 public ClassLoader getContextClassLoader() { 38 return (ClassLoader ) 39 AccessController.doPrivileged(new PrivilegedAction () { 40 public Object run() { 41 ClassLoader cl = null; 42 try { 43 cl = Thread.currentThread().getContextClassLoader(); 44 } catch (SecurityException ex) { } 45 return cl; 46 } 47 }); 48 } 49 50 public String getSystemProperty(final String propName) { 51 return (String ) 52 AccessController.doPrivileged(new PrivilegedAction () { 53 public Object run() { 54 return System.getProperty(propName); 55 } 56 }); 57 } 58 59 public FileInputStream getFileInputStream(final File file) 60 throws FileNotFoundException 61 { 62 try { 63 return (FileInputStream ) 64 AccessController.doPrivileged(new PrivilegedExceptionAction () { 65 public Object run() throws FileNotFoundException { 66 return new FileInputStream (file); 67 } 68 }); 69 } catch (PrivilegedActionException e) { 70 throw (FileNotFoundException )e.getException(); 71 } 72 } 73 74 public InputStream getResourceAsStream(final ClassLoader cl, 75 final String name) 76 { 77 return (InputStream ) 78 AccessController.doPrivileged(new PrivilegedAction () { 79 public Object run() { 80 InputStream ris; 81 if (cl == null) { 82 ris = ClassLoader.getSystemResourceAsStream(name); 83 } else { 84 ris = cl.getResourceAsStream(name); 85 } 86 return ris; 87 } 88 }); 89 } 90 } 91 | Popular Tags |