01: /*
02: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/loadercontrol/ManifestParser.java,v 1.1 2005/04/20 21:05:07 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is Java 3D(tm) Fly Through.
11: * The Initial Developer of the Original Code is Paul Byrne.
12: * Portions created by Paul Byrne are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Paul Byrne.
16: *
17: **/
18: package org.jdesktop.j3dfly.utils.loadercontrol;
19:
20: import java.util.jar.JarFile;
21: import java.util.jar.Attributes;
22: import java.util.jar.Manifest;
23:
24: /**
25: *
26: * Parses Jar Manifest's invoking Listeners when specific Manifest entries
27: * are found.
28: *
29: * @author Paul Byrne
30: * @version $Id: ManifestParser.java,v 1.1 2005/04/20 21:05:07 paulby Exp $
31: */
32: public class ManifestParser {
33:
34: /**
35: * Check all the MainAttributes in the manifest against the names
36: * provided. When an Attribute matches any of the names call the listener with
37: * the associated value from the manifest
38: */
39: public static void processMainAttributes(JarFile jarFile,
40: String[] names, ManifestListener listener)
41: throws java.io.IOException {
42: //System.out.println("Checking jar "+jarFile.getName() );
43: Manifest manifest = jarFile.getManifest();
44: if (manifest == null)
45: return;
46: java.util.Map entries = manifest.getMainAttributes();
47:
48: java.util.Iterator it = entries.keySet().iterator();
49: while (it.hasNext()) {
50: Attributes.Name attr = (Attributes.Name) it.next();
51: for (int i = 0; i < names.length; i++) {
52: if (attr.toString().equals(names[i])) {
53: listener.foundManifestAttribute(names[i],
54: (String) entries.get(attr));
55: }
56: }
57: }
58:
59: }
60:
61: /**
62: * Interface which will be called every time a matching attribute is
63: * found in a manifest
64: */
65: public interface ManifestListener {
66: public void foundManifestAttribute(String name, String value);
67: }
68:
69: }
|