001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependencyfinder;
034:
035: import java.io.*;
036: import java.util.jar.*;
037:
038: import org.apache.log4j.*;
039:
040: public class Version {
041: public static final String DEFAULT_URL = "http://depfind.sourceforge.net/";
042: public static final String DEFAULT_TITLE = "Dependency Finder";
043: public static final String DEFAULT_VERSION = "<i>unknown</i>";
044: public static final String DEFAULT_VENDOR = "Jean Tessier";
045: public static final String DEFAULT_DATE = "<i>unknown</i>";
046: public static final String DEFAULT_COPYRIGHT_HOLDER = "Jean Tessier";
047: public static final String DEFAULT_COPYRIGHT_DATE = "2001-2007";
048:
049: private String resourceURL = null;
050: private String jarName = null;
051:
052: private Attributes attributes = null;
053:
054: public Version() {
055: resourceURL = getClass().getResource("Version.class")
056: .toString();
057:
058: if (resourceURL.startsWith("jar:file:")) {
059: jarName = resourceURL.substring(9, resourceURL
060: .indexOf(".jar!") + 4);
061:
062: try {
063: JarFile jar = new JarFile(jarName);
064: Manifest manifest = jar.getManifest();
065:
066: attributes = manifest.getMainAttributes();
067: } catch (IOException ex) {
068: Logger
069: .getLogger(getClass())
070: .error(
071: "Could not get version information, using defaults",
072: ex);
073: }
074: }
075: }
076:
077: public String getResourceURL() {
078: return resourceURL;
079: }
080:
081: public String getJarName() {
082: return jarName;
083: }
084:
085: public String getImplementationURL() {
086: String result = DEFAULT_URL;
087:
088: if (attributes != null) {
089: result = attributes.getValue("Implementation-URL");
090: }
091:
092: return result;
093: }
094:
095: public String getImplementationTitle() {
096: String result = DEFAULT_TITLE;
097:
098: if (attributes != null) {
099: result = attributes.getValue("Implementation-Title");
100: }
101:
102: return result;
103: }
104:
105: public String getImplementationVersion() {
106: String result = DEFAULT_VERSION;
107:
108: if (attributes != null) {
109: result = attributes.getValue("Implementation-Version");
110: }
111:
112: return result;
113: }
114:
115: public String getImplementationVendor() {
116: String result = DEFAULT_VENDOR;
117:
118: if (attributes != null) {
119: result = attributes.getValue("Implementation-Vendor");
120: }
121:
122: return result;
123: }
124:
125: public String getImplementationDate() {
126: String result = DEFAULT_DATE;
127:
128: if (attributes != null) {
129: result = attributes.getValue("Implementation-Date");
130: }
131:
132: return result;
133: }
134:
135: public String getSpecificationTitle() {
136: String result = DEFAULT_TITLE;
137:
138: if (attributes != null) {
139: result = attributes.getValue("Specification-Title");
140: }
141:
142: return result;
143: }
144:
145: public String getSpecificationVersion() {
146: String result = DEFAULT_VERSION;
147:
148: if (attributes != null) {
149: result = attributes.getValue("Specification-Version");
150: }
151:
152: return result;
153: }
154:
155: public String getSpecificationVendor() {
156: String result = DEFAULT_VENDOR;
157:
158: if (attributes != null) {
159: result = attributes.getValue("Specification-Vendor");
160: }
161:
162: return result;
163: }
164:
165: public String getSpecificationDate() {
166: String result = DEFAULT_DATE;
167:
168: if (attributes != null) {
169: result = attributes.getValue("Specification-Date");
170: }
171:
172: return result;
173: }
174:
175: public String getCopyrightHolder() {
176: String result = DEFAULT_COPYRIGHT_HOLDER;
177:
178: if (attributes != null) {
179: result = attributes.getValue("Copyright-Holder");
180: }
181:
182: return result;
183: }
184:
185: public String getCopyrightDate() {
186: String result = DEFAULT_COPYRIGHT_DATE;
187:
188: if (attributes != null) {
189: result = attributes.getValue("Copyright-Date");
190: }
191:
192: return result;
193: }
194: }
|