KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > common > JarUtils


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.common;
21
22 import java.io.IOException JavaDoc;
23 import java.util.jar.Attributes JavaDoc;
24 import java.util.jar.JarFile JavaDoc;
25
26 /**
27  * Simple operations on jar files
28  */

29 public class JarUtils
30 {
31     /**
32      * Get an attribute value
33      *
34      * @param jarUrl the jar file
35      * @param attribute the attribute to fetch
36      * @return the attribute value
37      */

38     private static String JavaDoc getManifestAttribute(String JavaDoc jarUrl, String JavaDoc attribute)
39     throws IOException JavaDoc
40     {
41         JarFile JavaDoc jar = new JarFile JavaDoc(jarUrl);
42         Attributes JavaDoc attr = jar.getManifest().getMainAttributes();
43         String JavaDoc value = attr.getValue(attribute);
44         
45         jar.close();
46         return value;
47     }
48     
49     /**
50      * Get the service class name specified in a jar
51      *
52      * @param jarUrl the jar file
53      * @return the class name
54      */

55     public static String JavaDoc getServiceClass(String JavaDoc jarUrl)
56     throws IOException JavaDoc
57     {
58         return getManifestAttribute(jarUrl, "Service-Class");
59     }
60
61     /**
62      * Get the plugin class name specified in a jar
63      *
64      * @param jarUrl the jar file
65      * @return the class name
66      */

67     public static String JavaDoc getPluginClass(String JavaDoc jarUrl)
68     throws IOException JavaDoc
69     {
70         return getManifestAttribute(jarUrl, "Plugin-Class");
71     }
72     
73     /**
74      * Check the web enabled attribute specified in a jar
75      *
76      * @param jarUrl the jar file
77      * @return true if Web-Enabled is true
78      */

79     public static boolean isWebEnabled(String JavaDoc jarUrl)
80     throws IOException JavaDoc
81     {
82         return Boolean.valueOf(getManifestAttribute(jarUrl, "Web-Enabled")).booleanValue();
83     }
84 }
Popular Tags