KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependencyfinder > Version


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependencyfinder;
34
35 import java.io.*;
36 import java.util.jar.*;
37
38 import org.apache.log4j.*;
39
40 public class Version {
41     public static final String JavaDoc DEFAULT_URL = "http://depfind.sourceforge.net/";
42     public static final String JavaDoc DEFAULT_TITLE = "Dependency Finder";
43     public static final String JavaDoc DEFAULT_VERSION = "<i>unknown</i>";
44     public static final String JavaDoc DEFAULT_VENDOR = "Jean Tessier";
45     public static final String JavaDoc DEFAULT_DATE = "<i>unknown</i>";
46     public static final String JavaDoc DEFAULT_COPYRIGHT_HOLDER = "Jean Tessier";
47     public static final String JavaDoc DEFAULT_COPYRIGHT_DATE = "2001-2005";
48
49     private String JavaDoc resourceURL = null;
50     private String JavaDoc jarName = null;
51
52     private Attributes attributes = null;
53     
54     public Version() {
55         resourceURL = getClass().getResource("Version.class").toString();
56         
57         if (resourceURL.startsWith("jar:file:")) {
58             jarName = resourceURL.substring(9, resourceURL.indexOf(".jar!") + 4);
59
60             try {
61                 JarFile jar = new JarFile(jarName);
62                 Manifest manifest = jar.getManifest();
63                 
64                 attributes = manifest.getMainAttributes();
65             } catch (IOException ex) {
66                 Logger.getLogger(getClass()).error("Could not get version information, using defaults", ex);
67             }
68         }
69     }
70     
71     public String JavaDoc getResourceURL() {
72         return resourceURL;
73     }
74
75     public String JavaDoc getJarName() {
76         return jarName;
77     }
78
79     public String JavaDoc getImplementationURL() {
80         String JavaDoc result = DEFAULT_URL;
81
82         if (attributes != null) {
83             result = attributes.getValue("Implementation-URL");
84         }
85
86         return result;
87     }
88
89     public String JavaDoc getImplementationTitle() {
90         String JavaDoc result = DEFAULT_TITLE;
91
92         if (attributes != null) {
93             result = attributes.getValue("Implementation-Title");
94         }
95
96         return result;
97     }
98
99     public String JavaDoc getImplementationVersion() {
100         String JavaDoc result = DEFAULT_VERSION;
101
102         if (attributes != null) {
103             result = attributes.getValue("Implementation-Version");
104         }
105
106         return result;
107     }
108
109     public String JavaDoc getImplementationVendor() {
110         String JavaDoc result = DEFAULT_VENDOR;
111
112         if (attributes != null) {
113             result = attributes.getValue("Implementation-Vendor");
114         }
115
116         return result;
117     }
118
119     public String JavaDoc getImplementationDate() {
120         String JavaDoc result = DEFAULT_DATE;
121
122         if (attributes != null) {
123             result = attributes.getValue("Implementation-Date");
124         }
125
126         return result;
127     }
128
129     public String JavaDoc getSpecificationTitle() {
130         String JavaDoc result = DEFAULT_TITLE;
131
132         if (attributes != null) {
133             result = attributes.getValue("Specification-Title");
134         }
135
136         return result;
137     }
138
139     public String JavaDoc getSpecificationVersion() {
140         String JavaDoc result = DEFAULT_VERSION;
141
142         if (attributes != null) {
143             result = attributes.getValue("Specification-Version");
144         }
145
146         return result;
147     }
148
149     public String JavaDoc getSpecificationVendor() {
150         String JavaDoc result = DEFAULT_VENDOR;
151
152         if (attributes != null) {
153             result = attributes.getValue("Specification-Vendor");
154         }
155
156         return result;
157     }
158
159     public String JavaDoc getSpecificationDate() {
160         String JavaDoc result = DEFAULT_DATE;
161
162         if (attributes != null) {
163             result = attributes.getValue("Specification-Date");
164         }
165
166         return result;
167     }
168
169     public String JavaDoc getCopyrightHolder() {
170         String JavaDoc result = DEFAULT_COPYRIGHT_HOLDER;
171
172         if (attributes != null) {
173             result = attributes.getValue("Copyright-Holder");
174         }
175
176         return result;
177     }
178
179     public String JavaDoc getCopyrightDate() {
180         String JavaDoc result = DEFAULT_COPYRIGHT_DATE;
181
182         if (attributes != null) {
183             result = attributes.getValue("Copyright-Date");
184         }
185
186         return result;
187     }
188 }
189
Popular Tags