[jdom-interest] JDOM Easter Egg + MANIFEST.MF with versioning info.

Steven Gould steven.gould at cgiusa.com
Sun Mar 11 01:49:53 PST 2001


Below are three files for inclusion in the JDOM source tree:
MANIFEST.MF, info.xml and JDOMEasterEgg.java. These address the
following items from the TODO.txt file:

>>>
* Look at putting XML files in the jdom.jar META-INF directory for
things like
  version, credits, description, etc, then access/print the info using
JDOM
  classes executed by a "java -jar jdom.jar" command.
  See http://java.sun.com/docs/books/tutorial/jar/

* Add JDOM version info to the MANIFEST.MF so servlets and such can
depend on
  it using
http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html
<<<

Note that the build.xml file needs to be modified to use the manifest
file below and include META-INF/info.xml. Here's the CVS diff for
build.xml:

>>>
Index: build.xml
===================================================================
RCS file: /home/cvspublic/jdom/build.xml,v
retrieving revision 1.15
diff -r1.15 build.xml
165c165
<          includes="org/**"/>
---
>          manifest="${build.dest}/META-INF/MANIFEST.MF"/>
<<<

Steve

----------------------------------------
src/java/META-INF/MANIFEST.MF
----------------------------------------

Manifest-Version: 1.0
Main-Class: JDOMEasterEgg
Class-Path: ../lib/xerces.jar xerces.jar

Name: org/jdom/
Sealed: true
Specification-Title: "JDOM Classes"
Specification-Version: "1.0"
Specification-Vendor: "jdom.org"
Implementation-Title: "org.jdom"
Implementation-Version: "build1.0-beta6"
Implementation-Vendor: "jdom.org"

Name: org/jdom/input/
Sealed: true
Specification-Title: "JDOM Input Classes"
Specification-Version: "1.0"
Specification-Vendor: "jdom.org"
Implementation-Title: "org.jdom.input"
Implementation-Version: "build1.0-beta6"
Implementation-Vendor: "jdom.org"

Name: org/jdom/output/
Sealed: true
Specification-Title: "JDOM Output Classes"
Specification-Version: "1.0"
Specification-Vendor: "jdom.org"
Implementation-Title: "org.jdom.output"
Implementation-Version: "build1.0-beta6"
Implementation-Vendor: "jdom.org"

Name: org/jdom/adapters/
Sealed: true
Specification-Title: "JDOM Adapter Classes"
Specification-Version: "1.0"
Specification-Vendor: "jdom.org"
Implementation-Title: "org.jdom.adapter"
Implementation-Version: "build1.0-beta6"
Implementation-Vendor: "jdom.org"


----------------------------------------
src/java/META-INF/info.xml
----------------------------------------
<?xml version="1.0"?>
<info>
    <title>JDOM</title>
    <version>1.0 Beta 6</version>
    <description>
        JDOM is a Java-oriented object model which models XML documents.

        It provides a Java-centric means of generating and manipulating
        XML documents. While JDOM interoperates well with existing
        standards such as the Simple API for XML (SAX) and the Document
        Object Model (DOM), it is not an abstraction layer or
        enhancement to those APIs. Rather, it seeks to provide a robust,

        light-weight means of reading and writing XML data without the
        complex and memory-consumptive options that current API
        offerings provide.
    </description>
    <copyright>2000-2001, Jason Hunter and Brett McLaughlin</copyright>
    <license>BSD/Apache style, see LICENSE.txt</license>
    <support>See the jdom-interest mailing list at jdom.org</support>
    <web-site>http://www.jdom.org/</web-site>
    <!--
    The following list of authors was initially extracted from @author
    comments in the code. Apologies if anyone has been left out.
    -->
    <author>
        <name>Brett McLaughlin</name>
        <e-mail>brett at jdom.org</e-mail>
    </author>
    <author>
        <name>Jason Hunter</name>
        <e-mail>jhunter at jdom.org</e-mail>
    </author>
    <author>
        <name>Steven Gould</name>
        <e-mail>steven.gould at cgiusa.com</e-mail>
    </author>
    <author>
        <name>Alex Chaffee</name>
        <e-mail>alex at jguru.com</e-mail>
    </author>
    <author>
        <name>Jon Baer</name>
 <e-mail>jonbaer at digitalanywhere.com</e-mail>
    </author>
    <author>
        <name>Elliotte Rusty Harold</name>
        <e-mail>elharo at metalab.unc.edu</e-mail>
    </author>
    <author>
        <name>Dan Schaffer</name>
    </author>
    <author>
        <name>David and Will (from Post Tool Design)</name>
    </author>
    <author>
        <name>Fred Trimble</name>
    </author>
    <author>
        <name>Jason Reid</name>
    </author>
    <author>
        <name>Kevin Regan</name>
    </author>
    <author>
        <name>Lucas Gonze</name>
    </author>
    <author>
        <name>Matthew Merlo</name>
    </author>
    <author>
        <name>Philip Nelson</name>
    </author>
    <author>
        <name>Wesley Biggs</name>
    </author>
    <author>
        <name>Wolfgang Werner</name>
    </author>
    <author>
        <name>Yusuf Goolamabbas</name>
    </author>
</info>

----------------------------------------
src/java/JDOMEasterEgg.java
----------------------------------------
 System.out.println( info.description );
 System.out.println();

 // Iterate through authors, outputting each in turn
 System.out.println( "Authors:" );
 Iterator it = info.authors.iterator();
 while ( it.hasNext() )
     {
  Author author = (Author)it.next();

  // Output the author's name
  System.out.print( "  " + author.name );

  // If the author has an e-mail address, output it too
  if ( author.email == null )
      System.out.println();
  else
      System.out.println( " <" + author.email + ">" );
     }
 System.out.println();

 // Display "license" information
 System.out.println( title + " license:" );
 System.out.println( info.license );
 System.out.println();

 // Display "support" information
 System.out.println( title + " support:" );
 System.out.println( info.support );
 System.out.println();

 // Display "license" information
 System.out.println( title + " web site: " + info.website );
 System.out.println();
    }

    /**
     * This class encapsulates the locating of, and reading of, the JAR
     * information file. This file should be named META-INF/info.xml.
The
     * default constructor initializes all members variables from the
     * content of the info.xml file.
     *
     * <p>This class has been separated out for a couple of reasons:
     * <ol>
     *  <li>So that the presentation of the data in info.xml can be
     *      separated out from the reading of the file - enabling a
"looser"
     *      coupling between the data and presentation.</li>
     *  <li>Just in case we later decide to make this information
     *      publically accessible. If this happens we'll probably want
to
     *      implement "get" methods for each of the member variables.
For
     *      now, it was decided that doing so may be too much of an
overhead
     *      for an internal class.</li>
     * </ol>
     */
    private class Info
    {
 /** The product title, or product name. */
 String title;

 /**
  * The product/JAR version number - or string. This can contain
  * characters.
  */
 String version;

 /** The JAR copyright message. */
 String copyright;

 /** A description of the contents of this JAR. */
 String description;

 /** A list of authors of this product/JAR. */
 List authors;

 /** The product/JAR license information. */
 String license;

 /** Product/JAR support information. */
 String support;

 /** The main web site for this product/JAR. */
 String website;

 /**
  * Constructor for the Info class - initializes all member
  * variables with values taken from the JAR information file.
  * The JAR information file should be called META-INF/info.xml
  * and be contained within the JAR file.
  */
 Info()
 {
     final String INFO_FILENAME = "META-INF/info.xml";

     SAXBuilder builder = new SAXBuilder();

     // If invoked using java -jar, the JAR file will be the only
     // thing in the CLASSPATH
     String jarFileName = System.getProperty("java.class.path");
     //System.out.println( "java.class.path = " + jarFileName );

     try
  {
      // Create a JarFile representation of the JAR
      JarFile jarFile = new JarFile( jarFileName );

      // Get a reference to the info.xml entry in the JAR
      ZipEntry zipEntry = jarFile.getEntry( INFO_FILENAME );
      if ( null == zipEntry )
   {
       // This should never happen provided the
       //  JAR was correctly built
       System.err.println( "Incomplete JAR file - "
      + INFO_FILENAME
      + " file not found" );
       System.exit( 1 );
   }

      // Get input stream for reading info.xml file
      InputStream in = jarFile.getInputStream( zipEntry );

      // Using JDOM, read the info.xml file
      Document doc = builder.build( in );
      Element root = doc.getRootElement();

      title = root.getChildTextTrim("title");
      version = root.getChildTextTrim("version");
      copyright = root.getChildTextTrim("copyright");
      description = root.getChildTextTrim("description");
      license = root.getChildTextTrim("license");
      support = root.getChildTextTrim("support");
      website = root.getChildTextTrim("web-site");

      List authorElements = root.getChildren( "author" );
      authors = new LinkedList();
      Iterator it = authorElements.iterator();
      while ( it.hasNext() )
   {
       Element element = (Element)it.next();

       Author author = new Author();
       author.name = element.getChildTextTrim("name");
       author.email = element.getChildTextTrim("e-mail");

       authors.add( author );
   }
  }
     catch ( JDOMException exJdom )
  {
      System.err.println( exJdom );
  }
     catch ( Exception ex )
  {
      System.err.println( ex );
  }
 }
    }

    /**
     * A helper class that stores information about a single Author. By
     * using this class, the Info class can store Author information
     * without any dependence on JDOM and XML elements.
     */
    private class Author
    {
 /** The name of this author. */
 String name;

 /** The e-mail address of this author. */
 String email;
    }
}





More information about the jdom-interest mailing list