1 54 55 57 import java.io.*; 58 import java.util.*; 59 import java.util.jar.*; 60 import java.util.zip.*; 61 62 import org.jdom.*; 63 import org.jdom.input.*; 64 65 85 public class JDOMAbout { 86 92 public static void main(String args[]) throws Exception { 93 JDOMAbout.Info info = new JDOMAbout().new Info(); 94 95 String title = info.title; 97 98 System.out.println(title + " version " + info.version); 100 System.out.println("Copyright " + info.copyright); 101 System.out.println(); 102 103 System.out.println(info.description); 105 System.out.println(); 106 107 System.out.println("Authors:"); 109 Iterator it = info.authors.iterator(); 110 while (it.hasNext()) { 111 Author author = (Author)it.next(); 112 113 System.out.print(" " + author.name); 115 116 if (author.email == null) { 118 System.out.println(); 119 } else { 120 System.out.println(" <" + author.email + ">"); 121 } 122 } 123 System.out.println(); 124 125 System.out.println(title + " license:"); 127 System.out.println(info.license); 128 System.out.println(); 129 130 System.out.println(title + " support:"); 132 System.out.println(info.support); 133 System.out.println(); 134 135 System.out.println(title + " web site: " + info.website); 137 System.out.println(); 138 } 139 140 158 private class Info { 159 160 String title; 161 162 166 String version; 167 168 169 String copyright; 170 171 172 String description; 173 174 175 List authors; 176 177 178 String license; 179 180 181 String support; 182 183 184 String website; 185 186 193 Info() throws Exception { 194 final String INFO_FILENAME = "META-INF/info.xml"; 195 196 SAXBuilder builder = new SAXBuilder(); 197 198 JarFile jarFile = null; 201 ZipEntry zipEntry = null; 202 203 String classpath = System.getProperty("java.class.path"); 204 StringTokenizer tokenizer = new StringTokenizer(classpath, ";:"); 205 while (tokenizer.hasMoreTokens() && zipEntry == null) { 206 String token = tokenizer.nextToken(); 207 208 try { 209 jarFile = new JarFile(token); 211 212 zipEntry = jarFile.getEntry(INFO_FILENAME); 214 } 215 catch (Exception e) { 216 } 217 } 218 219 if (zipEntry == null) { 220 throw new FileNotFoundException(INFO_FILENAME + 221 " not found; it should be within the JDOM JAR but isn't"); 222 } 223 224 InputStream in = jarFile.getInputStream(zipEntry); 226 227 Document doc = builder.build(in); 229 Element root = doc.getRootElement(); 230 231 title = root.getChildTextTrim("title"); 232 version = root.getChildTextTrim("version"); 233 copyright = root.getChildTextTrim("copyright"); 234 description = root.getChildTextTrim("description"); 235 license = root.getChildTextTrim("license"); 236 support = root.getChildTextTrim("support"); 237 website = root.getChildTextTrim("web-site"); 238 239 List authorElements = root.getChildren("author"); 240 authors = new LinkedList(); 241 Iterator it = authorElements.iterator(); 242 while (it.hasNext()) { 243 Element element = (Element)it.next(); 244 245 Author author = new Author(); 246 author.name = element.getChildTextTrim("name"); 247 author.email = element.getChildTextTrim("e-mail"); 248 249 authors.add(author); 250 } 251 } 252 } 253 254 259 private class Author { 260 261 String name; 262 263 264 String email; 265 } 266 } 267 | Popular Tags |