1 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 DEFAULT_URL = "http://depfind.sourceforge.net/"; 42 public static final String DEFAULT_TITLE = "Dependency Finder"; 43 public static final String DEFAULT_VERSION = "<i>unknown</i>"; 44 public static final String DEFAULT_VENDOR = "Jean Tessier"; 45 public static final String DEFAULT_DATE = "<i>unknown</i>"; 46 public static final String DEFAULT_COPYRIGHT_HOLDER = "Jean Tessier"; 47 public static final String DEFAULT_COPYRIGHT_DATE = "2001-2005"; 48 49 private String resourceURL = null; 50 private String 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 getResourceURL() { 72 return resourceURL; 73 } 74 75 public String getJarName() { 76 return jarName; 77 } 78 79 public String getImplementationURL() { 80 String result = DEFAULT_URL; 81 82 if (attributes != null) { 83 result = attributes.getValue("Implementation-URL"); 84 } 85 86 return result; 87 } 88 89 public String getImplementationTitle() { 90 String result = DEFAULT_TITLE; 91 92 if (attributes != null) { 93 result = attributes.getValue("Implementation-Title"); 94 } 95 96 return result; 97 } 98 99 public String getImplementationVersion() { 100 String result = DEFAULT_VERSION; 101 102 if (attributes != null) { 103 result = attributes.getValue("Implementation-Version"); 104 } 105 106 return result; 107 } 108 109 public String getImplementationVendor() { 110 String result = DEFAULT_VENDOR; 111 112 if (attributes != null) { 113 result = attributes.getValue("Implementation-Vendor"); 114 } 115 116 return result; 117 } 118 119 public String getImplementationDate() { 120 String result = DEFAULT_DATE; 121 122 if (attributes != null) { 123 result = attributes.getValue("Implementation-Date"); 124 } 125 126 return result; 127 } 128 129 public String getSpecificationTitle() { 130 String result = DEFAULT_TITLE; 131 132 if (attributes != null) { 133 result = attributes.getValue("Specification-Title"); 134 } 135 136 return result; 137 } 138 139 public String getSpecificationVersion() { 140 String result = DEFAULT_VERSION; 141 142 if (attributes != null) { 143 result = attributes.getValue("Specification-Version"); 144 } 145 146 return result; 147 } 148 149 public String getSpecificationVendor() { 150 String result = DEFAULT_VENDOR; 151 152 if (attributes != null) { 153 result = attributes.getValue("Specification-Vendor"); 154 } 155 156 return result; 157 } 158 159 public String getSpecificationDate() { 160 String result = DEFAULT_DATE; 161 162 if (attributes != null) { 163 result = attributes.getValue("Specification-Date"); 164 } 165 166 return result; 167 } 168 169 public String getCopyrightHolder() { 170 String 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 getCopyrightDate() { 180 String 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 |