/* * ResourceHandler.java * * Brazil project web application toolkit, * export version: 2.3 * Copyright (c) 1999-2008 Sun Microsystems, Inc. * * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is included as the file "license.terms", * and also available at http://www.sun.com/ * * The Original Code is from: * Brazil project web application toolkit release 2.3. * The Initial Developer of the Original Code is: suhler. * Portions created by suhler are Copyright (C) Sun Microsystems, Inc. * All Rights Reserved. * * Contributor(s): cstevens, suhler. * * Version: 2.7 * Created by suhler on 99/07/09 * Last modified by suhler on 08/12/19 11:14:35 * * Version Histories: * * 2.7 08/12/19-11:14:35 (suhler) * make sure streams are closed * * 2.6 06/11/13-15:04:14 (suhler) * move MatchString to package "util" from "handler" * * 2.5 06/04/28-16:16:45 (suhler) * compute content length properly * * 2.4 06/04/25-14:15:49 (suhler) * use consolidated mime type handling in FileHandler * * 2.3 04/12/30-12:37:55 (suhler) * javadoc fixes * * 2.2 03/08/01-16:18:18 (suhler) * fixes for javadoc * * 2.1 02/10/01-16:36:35 (suhler) * version change * * 1.21 01/07/20-11:31:12 (suhler) * MatchUrl -> MatchString * * 1.20 01/07/17-14:16:36 (suhler) * use MatchUrl * * 1.19 00/12/11-13:27:31 (suhler) * add class=props for automatic property extraction * * 1.18 00/10/06-10:50:34 (suhler) * Merged changes between child workspace "/home/suhler/brazil/naws" and * parent workspace "/net/mack.eng/export/ws/brazil/naws". * * 1.17 00/10/05-15:51:01 (cstevens) * lint * * 1.16.1.1 00/08/16-12:11:34 (suhler) * remove unused import * * 1.16 00/07/10-15:08:44 (cstevens) * ResourceHandler.getResourceStream() didn't work under Windows due to * platform-dependant file names. Class.getResourceAsStream() requires '/' as * separator while File.getParent() requires '\'. Added code to turn '/' into * '\' and vice versa as necessary. ResourceHandler.getResourceStream() now * accepts either '\' or '/' in path. * * 1.15 00/06/30-10:28:27 (cstevens) * * 1.14 00/05/31-13:46:34 (suhler) * doc cleanup * * 1.13 00/05/24-11:25:27 (suhler) * remove leading @ processing * * 1.12 00/05/22-18:37:07 (suhler) * remove junk, add comments * * 1.11 00/05/19-11:48:48 (suhler) * doc fixes * * 1.10 00/04/24-12:58:38 (cstevens) * init stuff, ignore * * 1.9 00/04/20-11:50:23 (cstevens) * copyright. * * 1.8 00/04/17-14:24:38 (cstevens) * Get ResourcePath. * * 1.7 00/04/12-15:54:14 (cstevens) * ResourceHandler exposes public method to load files and get Strings or bytes * from the jar file. * * 1.6 00/03/29-16:07:40 (cstevens) * ResourceHandler exposes public method to load files from the jar file. * * 1.5 00/03/10-17:06:51 (cstevens) * Fix wildcard and unneeded imports * * 1.4 00/03/02-17:46:24 (cstevens) * NullPointerException if file resource was not found in .jar file * * 1.3 99/10/26-17:11:18 (cstevens) * Get rid of public variables Request.server and Request.sock: * A. In all cases, Request.server was not necessary; it was mainly used for * constructing the absolute URL for a redirect, so Request.redirect() was * rewritten to take an absolute or relative URL and do the right thing. * B. Request.sock was changed to Request.getSock(); it is still rarely used * for diagnostics and logging (e.g., ChainSawHandler). * * 1.2 99/07/12-09:27:35 (suhler) * lint * * 1.2 99/07/09-16:05:02 (Codemgr) * SunPro Code Manager data about conflicts, renames, etc... * Name history : 1 0 handlers/ResourceHandler.java * * 1.1 99/07/09-16:05:01 (suhler) * date and time created 99/07/09 16:05:01 by suhler * */ package sunlabs.brazil.handler; import sunlabs.brazil.server.FileHandler; import sunlabs.brazil.server.Handler; import sunlabs.brazil.server.Request; import sunlabs.brazil.server.Server; import sunlabs.brazil.util.MatchString; import sunlabs.brazil.util.http.HttpInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; import java.io.FileNotFoundException; import java.io.File; import java.io.FileInputStream; import java.util.Properties; /** * Handler for serving documents out of the jar file. * * Look for url's as resources, presumably in the same "jar" * file as the class files. * This allows an entire web site to be included in the jar file. * A typical way to use this handler (with java 1.2+) is as follows: *
jar uf [jar file] [web site]*
sunlabs/brazil/main/config
. See
* {@link sunlabs.brazil.server.Main Main.java} for more info.
*Main-Class: sunlabs.brazil.server.Main, * and add it to the manifest with: *
jar ufm [jar file] [startup file]*
java -jar [jar file] [optional server options....]*
* if no suffix is provided, and the "directory" exists, a redirect * is issued, to add-on the trailing slash. * * The following server properties are used: *