001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright © 2002 Jesse Stockall. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution, if
019: * any, must include the following acknowlegement:
020: * "This product includes software developed by the
021: * Apache Software Foundation (http://www.apache.org/)."
022: * Alternately, this acknowlegement may appear in the software itself,
023: * if and wherever such third-party acknowlegements normally appear.
024: *
025: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
026: * Foundation" must not be used to endorse or promote products derived
027: * from this software without prior written permission. For written
028: * permission, please contact apache@apache.org.
029: *
030: * 5. Products derived from this software may not be called "Apache"
031: * nor may "Apache" appear in their names without prior written
032: * permission of the Apache Group.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: * This software consists of voluntary contributions made by many
049: * individuals on behalf of the Apache Software Foundation. For more
050: * information on the Apache Software Foundation, please see
051: * <http://www.apache.org/>.
052: */
053: package org.apache.tools.ant.taskdefs.optional.genjar;
054:
055: import java.io.IOException;
056: import java.io.InputStream;
057: import java.text.SimpleDateFormat;
058: import java.util.Date;
059: import java.util.Locale;
060:
061: /**
062: * <p>
063: *
064: * A PathResolver is used for each component of the classpath.</p> <p>
065: *
066: * Each type of component is a specialization of this base class. For example, a jar file
067: * encountered in the classpath causes a JarResolver to be instantiated. A JarResolver knows how to
068: * search within jar files for specific files. </p> <p>
069: *
070: * This approach is taken for two reasons:
071: * <ol>
072: * <li> To encapsulate the specifics of fetching streams and what attributes are set on a jar
073: * entry's manifest entry. </li>
074: * <li> To provide an association between the <i>source</i> of a class (or resource) and the
075: * repository from which it came. This info is priceless when trying to figure out why the wrong
076: * classes are being included in your jar. </li>
077: * </ol>
078: * </p>
079: *
080: * @author Original Code: <a href="mailto:jake@riggshill.com">John W. Kohler </a>
081: * @author Jesse Stockall
082: * @version $Revision: 1.2 $ $Date: 2003/02/23 10:06:10 $
083: */
084: abstract class PathResolver {
085: /** name of attribute for content's original location (path) */
086: static final String CONTENT_LOC = "Content-Location";
087: /** name of attribute for original content's modification time */
088: static final String LAST_MOD = "Last-Modified";
089: /** format string for RFC1123 date */
090: static final String RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
091:
092: /** Description of the Field */
093: protected Logger log;
094: private static SimpleDateFormat dateFmt = null;
095:
096: /**
097: * Constructor for the PathResolver object
098: *
099: * @param log Description of the Parameter
100: */
101: PathResolver(Logger log) {
102: this .log = log;
103: if (dateFmt == null) {
104: dateFmt = new SimpleDateFormat(RFC1123, Locale.getDefault());
105: //
106: // true conformance to rfc1123 would have us using GMT
107: // rather than local time - this doesn;t make sense to
108: // me since the biggest reason to use the time stamps
109: // is to compare against the source files - which are in
110: // local time
111: //
112: /*
113: dateFmt.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
114: */
115: }
116: }
117:
118: /**
119: * Given a JarEntrySpec, a path to the actual resource is generated and an input stream is
120: * returned on the path.
121: *
122: * @param je Description of the Parameter
123: * @return IOStream opened on the file referenced
124: * @exception IOException if any errors are encountered
125: */
126: abstract InputStream resolve(JarEntrySpec je) throws IOException;
127:
128: /**
129: * Given a file name (possibly relative), an InputStream is opened on that file or an exception
130: * is thrown.
131: *
132: * @param fname Description of the Parameter
133: * @return IOStream opened on the named file
134: * @throws IOException Oops!
135: */
136: abstract InputStream resolve(String fname) throws IOException;
137:
138: /**
139: * Closes any resources opened by the resolver.
140: *
141: * @throws IOException Oops!
142: */
143: abstract void close() throws IOException;
144:
145: /**
146: * Formats a date compatable with RFC1123. Well, close anyway. To be truly conformant the time
147: * zone would always be GMT. This formats the date in local time.
148: *
149: * @param d Description of the Parameter
150: * @return String representation of the date
151: */
152: protected String formatDate(Date d) {
153: return dateFmt.format(d);
154: }
155:
156: /**
157: * Description of the Method
158: *
159: * @param l Description of the Parameter
160: * @return Description of the Return Value
161: */
162: protected String formatDate(long l) {
163: return formatDate(new Date(l));
164: }
165: }
166: // vi:set ts=4 sw=4:
|