jaxp/src/com/sun/org/apache/bcel/internal/util/ClassPath.java
changeset 16953 a44e04deb948
parent 12457 c348e06f0e82
child 25264 040625ce9b72
equal deleted inserted replaced
16416:bcebd3fdefc9 16953:a44e04deb948
    64 
    64 
    65 /**
    65 /**
    66  * Responsible for loading (class) files from the CLASSPATH. Inspired by
    66  * Responsible for loading (class) files from the CLASSPATH. Inspired by
    67  * sun.tools.ClassPath.
    67  * sun.tools.ClassPath.
    68  *
    68  *
       
    69  * @version $Id: ClassPath.java,v 1.4 2007-07-19 04:34:52 ofung Exp $
    69  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
    70  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
    70  */
    71  */
    71 public class ClassPath implements Serializable {
    72 public class ClassPath implements Serializable {
    72   public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();
    73   public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();
    73 
    74 
    81     this.class_path = class_path;
    82     this.class_path = class_path;
    82 
    83 
    83     ArrayList vec = new ArrayList();
    84     ArrayList vec = new ArrayList();
    84 
    85 
    85     for(StringTokenizer tok=new StringTokenizer(class_path,
    86     for(StringTokenizer tok=new StringTokenizer(class_path,
    86                                                 System.getProperty("path.separator"));
    87                             SecuritySupport.getSystemProperty("path.separator"));
    87         tok.hasMoreTokens();)
    88         tok.hasMoreTokens();)
    88     {
    89     {
    89       String path = tok.nextToken();
    90       String path = tok.nextToken();
    90 
    91 
    91       if(!path.equals("")) {
    92       if(!path.equals("")) {
    92         File file = new File(path);
    93         File file = new File(path);
    93 
    94 
    94         try {
    95         try {
    95           if(file.exists()) {
    96           if(SecuritySupport.getFileExists(file)) {
    96             if(file.isDirectory())
    97             if(file.isDirectory())
    97               vec.add(new Dir(path));
    98               vec.add(new Dir(path));
    98             else
    99             else
    99               vec.add(new Zip(new ZipFile(file)));
   100               vec.add(new Zip(new ZipFile(file)));
   100           }
   101           }
   141 
   142 
   142       while(tok.hasMoreTokens()) {
   143       while(tok.hasMoreTokens()) {
   143         String name = tok.nextToken();
   144         String name = tok.nextToken();
   144         File   file = new File(name);
   145         File   file = new File(name);
   145 
   146 
   146         if(file.exists())
   147         if(SecuritySupport.getFileExists(file)) {
   147           list.add(name);
   148           list.add(name);
       
   149         }
   148       }
   150       }
   149     }
   151     }
   150   }
   152   }
   151 
   153 
   152   /** Checks for class path components in the following properties:
   154   /** Checks for class path components in the following properties:
   157   public static final String getClassPath() {
   159   public static final String getClassPath() {
   158 
   160 
   159     String class_path, boot_path, ext_path;
   161     String class_path, boot_path, ext_path;
   160 
   162 
   161     try {
   163     try {
   162       class_path = System.getProperty("java.class.path");
   164       class_path = SecuritySupport.getSystemProperty("java.class.path");
   163       boot_path  = System.getProperty("sun.boot.class.path");
   165       boot_path  = SecuritySupport.getSystemProperty("sun.boot.class.path");
   164       ext_path   = System.getProperty("java.ext.dirs");
   166       ext_path   = SecuritySupport.getSystemProperty("java.ext.dirs");
   165     }
   167     }
   166     catch (SecurityException e) {
   168     catch (SecurityException e) {
   167         return "";
   169         return "";
   168     }
   170     }
   169 
   171 
   174 
   176 
   175     ArrayList dirs = new ArrayList();
   177     ArrayList dirs = new ArrayList();
   176     getPathComponents(ext_path, dirs);
   178     getPathComponents(ext_path, dirs);
   177 
   179 
   178     for(Iterator e = dirs.iterator(); e.hasNext(); ) {
   180     for(Iterator e = dirs.iterator(); e.hasNext(); ) {
   179       File     ext_dir    = new File((String)e.next());
   181       File ext_dir = new File((String)e.next());
   180       String[] extensions = ext_dir.list(new FilenameFilter() {
   182       String[] extensions = SecuritySupport.getFileList(ext_dir, new FilenameFilter() {
   181         public boolean accept(File dir, String name) {
   183         public boolean accept(File dir, String name) {
   182           name = name.toLowerCase();
   184           name = name.toLowerCase();
   183           return name.endsWith(".zip") || name.endsWith(".jar");
   185           return name.endsWith(".zip") || name.endsWith(".jar");
   184         }
   186         }
   185       });
   187       });
   340 
   342 
   341     ClassFile getClassFile(String name, String suffix) throws IOException {
   343     ClassFile getClassFile(String name, String suffix) throws IOException {
   342       final File file = new File(dir + File.separatorChar +
   344       final File file = new File(dir + File.separatorChar +
   343                                  name.replace('.', File.separatorChar) + suffix);
   345                                  name.replace('.', File.separatorChar) + suffix);
   344 
   346 
   345       return file.exists()? new ClassFile() {
   347       return SecuritySupport.getFileExists(file)? new ClassFile() {
   346         public InputStream getInputStream() throws IOException { return new FileInputStream(file); }
   348         public InputStream getInputStream() throws IOException { return new FileInputStream(file); }
   347 
   349 
   348         public String      getPath()        { try {
   350         public String      getPath()        { try {
   349           return file.getCanonicalPath();
   351           return file.getCanonicalPath();
   350         } catch(IOException e) { return null; }
   352         } catch(IOException e) { return null; }