Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / util / ClassPathZip.java
1 package jde.util;
2
3 import java.util.*;
4 import java.util.zip.*;
5 import java.io.*;
6
7 /**
8  * A ClassPathEntry representing a ZIP or JAR file.
9  *
10  * Copyright (C) 2001, 2002 Eric D. Friedman (eric@hfriedman.rdsl.lmi.net)
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  * Created: Tuesday Aug 14 19:46:52 2001
27  *
28  * @author Eric D. Friedman
29  * @version $Id: ClassPathZip.java,v 1.2 2002/11/30 04:36:06 paulk Exp $
30  */
31
32 class ClassPathZip extends ClassPathEntry {
33     private File zipOrJar;
34
35     /**
36      * Creates a ClassPathZip instance representing <code>zipOrJar</code>
37      *
38      * @param zipOrJar a <code>File</code> value
39      * @return a <code>ClassPathZip</code> value
40      * @exception IOException if an error occurs
41      */
42     ClassPathZip (File zipOrJar) {
43         super();
44         this.zipOrJar = zipOrJar;
45     }
46
47     /**
48      * Load all of the classes in the zip/jar and set the loaded flag
49      * to true.
50      *
51      * @exception IOException if an error occurs
52      */
53     void load() throws IOException {
54         ZipFile zipFile = new ZipFile(zipOrJar);
55         Enumeration enum = zipFile.entries();
56         while (enum.hasMoreElements()) {
57             ZipEntry zipEntry = (ZipEntry)enum.nextElement();
58             String current = zipEntry.getName();
59             if (current.toLowerCase().endsWith(".class")) {
60                 current = current.substring(0, current.length() - 6);
61                 current = current.replace('/', '.');
62                 current = current.replace('\\', '.');
63                 current = current.replace('$', '.');
64                 super.addClass(current);
65             }
66         }
67         setLoaded(true);
68     }
69
70     /**
71      * Return the zip/jar name as our string.
72      *
73      * @return a <code>String</code> value
74      */
75     public String toString() {
76         return zipOrJar.toString();
77     }
78 }// ClassPathZip
79
80 /*
81  * $Log: ClassPathZip.java,v $
82  * Revision 1.2  2002/11/30 04:36:06  paulk
83  * load() method now replaces a $ with a period (.) in class names. Thanks to Petter Mahlen.
84  * 
85  */
86
87 // End of ClassPathZip.java