1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.FileNotFoundException ; 25 import java.io.InputStream ; 26 27 import java.security.AccessController ; 28 import java.security.PrivilegedAction ; 29 import java.security.PrivilegedActionException ; 30 import java.security.PrivilegedExceptionAction ; 31 32 import java.util.Properties ; 33 34 41 class SecuritySupport12 extends SecuritySupport { 42 43 ClassLoader getContextClassLoader() { 44 return (ClassLoader ) 45 AccessController.doPrivileged(new PrivilegedAction () { 46 public Object run() { 47 ClassLoader cl = null; 48 try { 49 cl = Thread.currentThread().getContextClassLoader(); 50 } catch (SecurityException ex) { } 51 return cl; 52 } 53 }); 54 } 55 56 ClassLoader getSystemClassLoader() { 57 return (ClassLoader ) 58 AccessController.doPrivileged(new PrivilegedAction () { 59 public Object run() { 60 ClassLoader cl = null; 61 try { 62 cl = ClassLoader.getSystemClassLoader(); 63 } catch (SecurityException ex) {} 64 return cl; 65 } 66 }); 67 } 68 69 ClassLoader getParentClassLoader(final ClassLoader cl) { 70 return (ClassLoader ) 71 AccessController.doPrivileged(new PrivilegedAction () { 72 public Object run() { 73 ClassLoader parent = null; 74 try { 75 parent = cl.getParent(); 76 } catch (SecurityException ex) {} 77 78 return (parent == cl) ? null : parent; 81 } 82 }); 83 } 84 85 String getSystemProperty(final String propName) { 86 return (String ) 87 AccessController.doPrivileged(new PrivilegedAction () { 88 public Object run() { 89 return System.getProperty(propName); 90 } 91 }); 92 } 93 94 FileInputStream getFileInputStream(final File file) 95 throws FileNotFoundException 96 { 97 try { 98 return (FileInputStream ) 99 AccessController.doPrivileged(new PrivilegedExceptionAction () { 100 public Object run() throws FileNotFoundException { 101 return new FileInputStream (file); 102 } 103 }); 104 } catch (PrivilegedActionException e) { 105 throw (FileNotFoundException )e.getException(); 106 } 107 } 108 109 InputStream getResourceAsStream(final ClassLoader cl, 110 final String name) 111 { 112 return (InputStream ) 113 AccessController.doPrivileged(new PrivilegedAction () { 114 public Object run() { 115 InputStream ris; 116 if (cl == null) { 117 ris = ClassLoader.getSystemResourceAsStream(name); 118 } else { 119 ris = cl.getResourceAsStream(name); 120 } 121 return ris; 122 } 123 }); 124 } 125 126 boolean getFileExists(final File f) { 127 return ((Boolean ) 128 AccessController.doPrivileged(new PrivilegedAction () { 129 public Object run() { 130 return new Boolean (f.exists()); 131 } 132 })).booleanValue(); 133 } 134 135 long getLastModified(final File f) { 136 return ((Long ) 137 AccessController.doPrivileged(new PrivilegedAction () { 138 public Object run() { 139 return new Long (f.lastModified()); 140 } 141 })).longValue(); 142 } 143 144 } 145 | Popular Tags |