1. /*
  2. * @(#)SecuritySupport.java 1.2 04/07/26
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.xml.parsers;
  8. import java.security.*;
  9. import java.net.*;
  10. import java.io.*;
  11. import java.util.*;
  12. /**
  13. * This class is duplicated for each JAXP subpackage so keep it in sync.
  14. * It is package private and therefore is not exposed as part of the JAXP
  15. * API.
  16. *
  17. * Security related methods that only work on J2SE 1.2 and newer.
  18. */
  19. class SecuritySupport {
  20. ClassLoader getContextClassLoader() {
  21. return (ClassLoader)
  22. AccessController.doPrivileged(new PrivilegedAction() {
  23. public Object run() {
  24. ClassLoader cl = null;
  25. try {
  26. cl = Thread.currentThread().getContextClassLoader();
  27. } catch (SecurityException ex) { }
  28. return cl;
  29. }
  30. });
  31. }
  32. String getSystemProperty(final String propName) {
  33. return (String)
  34. AccessController.doPrivileged(new PrivilegedAction() {
  35. public Object run() {
  36. return System.getProperty(propName);
  37. }
  38. });
  39. }
  40. FileInputStream getFileInputStream(final File file)
  41. throws FileNotFoundException
  42. {
  43. try {
  44. return (FileInputStream)
  45. AccessController.doPrivileged(new PrivilegedExceptionAction() {
  46. public Object run() throws FileNotFoundException {
  47. return new FileInputStream(file);
  48. }
  49. });
  50. } catch (PrivilegedActionException e) {
  51. throw (FileNotFoundException)e.getException();
  52. }
  53. }
  54. InputStream getResourceAsStream(final ClassLoader cl,
  55. final String name)
  56. {
  57. return (InputStream)
  58. AccessController.doPrivileged(new PrivilegedAction() {
  59. public Object run() {
  60. InputStream ris;
  61. if (cl == null) {
  62. ris = ClassLoader.getSystemResourceAsStream(name);
  63. } else {
  64. ris = cl.getResourceAsStream(name);
  65. }
  66. return ris;
  67. }
  68. });
  69. }
  70. boolean doesFileExist(final File f) {
  71. return ((Boolean)
  72. AccessController.doPrivileged(new PrivilegedAction() {
  73. public Object run() {
  74. return new Boolean(f.exists());
  75. }
  76. })).booleanValue();
  77. }
  78. }