1. /*
  2. * Copyright 2002-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: SecuritySupport.java,v 1.1.1.1 2004/02/26 11:39:31 vk112360 Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.dom;
  20. import java.io.File;
  21. import java.io.FileInputStream;
  22. import java.io.FileNotFoundException;
  23. import java.io.InputStream;
  24. import java.util.Properties;
  25. /**
  26. * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
  27. * It is package private and therefore is not exposed as part of the Xalan-Java
  28. * API.
  29. *
  30. * Base class with security related methods that work on JDK 1.1.
  31. */
  32. class SecuritySupport {
  33. /*
  34. * Make this of type Object so that the verifier won't try to
  35. * prove its type, thus possibly trying to load the SecuritySupport12
  36. * class.
  37. */
  38. private static final Object securitySupport;
  39. static {
  40. SecuritySupport ss = null;
  41. try {
  42. Class c = Class.forName("java.security.AccessController");
  43. // if that worked, we're on 1.2.
  44. /*
  45. // don't reference the class explicitly so it doesn't
  46. // get dragged in accidentally.
  47. c = Class.forName("javax.mail.SecuritySupport12");
  48. Constructor cons = c.getConstructor(new Class[] { });
  49. ss = (SecuritySupport)cons.newInstance(new Object[] { });
  50. */
  51. /*
  52. * Unfortunately, we can't load the class using reflection
  53. * because the class is package private. And the class has
  54. * to be package private so the APIs aren't exposed to other
  55. * code that could use them to circumvent security. Thus,
  56. * we accept the risk that the direct reference might fail
  57. * on some JDK 1.1 JVMs, even though we would never execute
  58. * this code in such a case. Sigh...
  59. */
  60. ss = new SecuritySupport12();
  61. } catch (Exception ex) {
  62. // ignore it
  63. } finally {
  64. if (ss == null)
  65. ss = new SecuritySupport();
  66. securitySupport = ss;
  67. }
  68. }
  69. /**
  70. * Return an appropriate instance of this class, depending on whether
  71. * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
  72. */
  73. static SecuritySupport getInstance() {
  74. return (SecuritySupport)securitySupport;
  75. }
  76. ClassLoader getContextClassLoader() {
  77. return null;
  78. }
  79. ClassLoader getSystemClassLoader() {
  80. return null;
  81. }
  82. ClassLoader getParentClassLoader(ClassLoader cl) {
  83. return null;
  84. }
  85. String getSystemProperty(String propName) {
  86. return System.getProperty(propName);
  87. }
  88. FileInputStream getFileInputStream(File file)
  89. throws FileNotFoundException
  90. {
  91. return new FileInputStream(file);
  92. }
  93. InputStream getResourceAsStream(ClassLoader cl, String name) {
  94. InputStream ris;
  95. if (cl == null) {
  96. ris = ClassLoader.getSystemResourceAsStream(name);
  97. } else {
  98. ris = cl.getResourceAsStream(name);
  99. }
  100. return ris;
  101. }
  102. boolean getFileExists(File f) {
  103. return f.exists();
  104. }
  105. long getLastModified(File f) {
  106. return f.lastModified();
  107. }
  108. }