View Javadoc

1   /*
2    * ZipList.java
3    *
4    * Created on March 15, 2001, 12:39 PM
5    */
6   package org.freehep.demo.iconbrowser;
7   
8   import java.util.zip.*;
9   import java.util.*;
10  import javax.swing.tree.*;
11  import java.io.*;
12  
13  /**
14   * Creates a jar file describing image archives.
15   * When reading images from a jar file on the classpath it is not possible
16   * to find out what images are available. This utility generates a separate
17   * jar file that includes listings of the available images.
18   * @author  Tony Johnson (tonyj@slac.stanford.edu)
19   * @version $Id: ZipAnnotate.java 10506 2007-01-30 22:48:57Z duns $ 
20   */
21  public class ZipAnnotate
22  {
23      /**
24      * @param args the command line arguments (a list of jar files to annotate)
25      */
26      public static void main (String args[]) throws Exception
27      {
28          ZipOutputStream zout = new ZipOutputStream(new FileOutputStream("ZipAnnotate.jar"));
29          zout.putNextEntry(new ZipEntry("IconBrowser.list"));
30          PrintWriter out = new PrintWriter(new OutputStreamWriter(zout));
31          for (int i=0; i<args.length; i++) out.println(IconBrowser.fileName(args[i],File.separator));
32          out.flush();
33          for (int i=0; i<args.length; i++)
34          {
35              String file = args[i];
36              ZipFile zip = new ZipFile(file);
37              ZipTree tree = new ZipTree(zip);
38              zout.putNextEntry(new ZipEntry(IconBrowser.fileName(file,File.separator)+".list"));
39              out = new PrintWriter(new OutputStreamWriter(zout));
40              dumpNode(out,tree,true);
41              out.flush();
42              zout.closeEntry();
43          }
44          zout.close();
45          System.exit(0);
46      }
47      private static void dumpNode(PrintWriter out, DefaultMutableTreeNode node, boolean root)
48      {
49          IconDirectory dir = (IconDirectory) node.getUserObject();
50          if (!root) out.println(dir.getName());
51          for (int i=0; i<dir.getNEntries(); i++)
52          {
53              out.println(dir.getEntryName(i));
54          }
55          Enumeration e = node.children();
56          while (e.hasMoreElements())
57          {
58              DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
59              dumpNode(out,child,false);
60          }
61      }
62  }