1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The name "Apache Software Foundation" must not be used to endorse or
  28. * promote products derived from this software without prior written
  29. * permission. For written permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache",
  32. * nor may "Apache" appear in their name, without prior written
  33. * permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation and was
  51. * originally based on software copyright (c) 1999-2002, Sun Microsystems,
  52. * Inc., http://www.sun.com. For more information on the Apache Software
  53. * Foundation, please see <http://www.apache.org/>.
  54. */
  55. package com.sun.org.apache.xerces.internal.xinclude;
  56. import java.security.*;
  57. import java.io.*;
  58. /**
  59. * This class is duplicated for each JAXP subpackage so keep it in sync.
  60. * It is package private and therefore is not exposed as part of the JAXP
  61. * API.
  62. *
  63. * Security related methods that only work on J2SE 1.2 and newer.
  64. */
  65. class SecuritySupport12 extends SecuritySupport {
  66. ClassLoader getContextClassLoader() {
  67. return (ClassLoader)
  68. AccessController.doPrivileged(new PrivilegedAction() {
  69. public Object run() {
  70. ClassLoader cl = null;
  71. try {
  72. cl = Thread.currentThread().getContextClassLoader();
  73. } catch (SecurityException ex) { }
  74. return cl;
  75. }
  76. });
  77. }
  78. ClassLoader getSystemClassLoader() {
  79. return (ClassLoader)
  80. AccessController.doPrivileged(new PrivilegedAction() {
  81. public Object run() {
  82. ClassLoader cl = null;
  83. try {
  84. cl = ClassLoader.getSystemClassLoader();
  85. } catch (SecurityException ex) {}
  86. return cl;
  87. }
  88. });
  89. }
  90. ClassLoader getParentClassLoader(final ClassLoader cl) {
  91. return (ClassLoader)
  92. AccessController.doPrivileged(new PrivilegedAction() {
  93. public Object run() {
  94. ClassLoader parent = null;
  95. try {
  96. parent = cl.getParent();
  97. } catch (SecurityException ex) {}
  98. // eliminate loops in case of the boot
  99. // ClassLoader returning itself as a parent
  100. return (parent == cl) ? null : parent;
  101. }
  102. });
  103. }
  104. String getSystemProperty(final String propName) {
  105. return (String)
  106. AccessController.doPrivileged(new PrivilegedAction() {
  107. public Object run() {
  108. return System.getProperty(propName);
  109. }
  110. });
  111. }
  112. FileInputStream getFileInputStream(final File file)
  113. throws FileNotFoundException
  114. {
  115. try {
  116. return (FileInputStream)
  117. AccessController.doPrivileged(new PrivilegedExceptionAction() {
  118. public Object run() throws FileNotFoundException {
  119. return new FileInputStream(file);
  120. }
  121. });
  122. } catch (PrivilegedActionException e) {
  123. throw (FileNotFoundException)e.getException();
  124. }
  125. }
  126. InputStream getResourceAsStream(final ClassLoader cl,
  127. final String name)
  128. {
  129. return (InputStream)
  130. AccessController.doPrivileged(new PrivilegedAction() {
  131. public Object run() {
  132. InputStream ris;
  133. if (cl == null) {
  134. ris = ClassLoader.getSystemResourceAsStream(name);
  135. } else {
  136. ris = cl.getResourceAsStream(name);
  137. }
  138. return ris;
  139. }
  140. });
  141. }
  142. boolean getFileExists(final File f) {
  143. return ((Boolean)
  144. AccessController.doPrivileged(new PrivilegedAction() {
  145. public Object run() {
  146. return new Boolean(f.exists());
  147. }
  148. })).booleanValue();
  149. }
  150. long getLastModified(final File f) {
  151. return ((Long)
  152. AccessController.doPrivileged(new PrivilegedAction() {
  153. public Object run() {
  154. return new Long(f.lastModified());
  155. }
  156. })).longValue();
  157. }
  158. }