/* Wotonomy: OpenStep design patterns for pure Java applications. Copyright (C) 2000 Blacksmith, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org */ package net.wotonomy.web; import java.util.Enumeration; import net.wotonomy.foundation.NSData; import net.wotonomy.foundation.NSMutableDictionary; /** * An implementation of WORequestHandler that * retrieves resources from the deployed application. * * @author michael@mpowers.net * @author $Author: cgruber $ * @version $Revision: 905 $ */ public class WOResourceRequestHandler extends WORequestHandler { private NSMutableDictionary resourceCache; private WOResourceManager resourceManager; public WOResourceRequestHandler() { //TODO: should probably have some kind of limit on the cache resourceCache = new NSMutableDictionary(); resourceManager = WOApplication.application().resourceManager(); } public WOResponse handleRequest( WORequest aRequest ) { WOResponse response = new WOResponse(); StringBuffer buf = new StringBuffer(); //TODO: this is just to get things working... String framework = null; Enumeration e = aRequest.requestHandlerPathArray().objectEnumerator(); if ( e.hasMoreElements() ) { framework = e.nextElement().toString(); if ( framework.equals( "application" ) ) { buf.append('/').append( framework ); framework = null; } } if ( e.hasMoreElements() ) { buf.append( e.nextElement() ); } while ( e.hasMoreElements() ) { buf.append('/').append( e.nextElement() ); } String resource; if ( buf.length() > 0 ) { resource = buf.toString(); byte[] data = resourceManager.bytesForResourceNamed( resource, framework, aRequest.browserLanguages() ); if ( data != null ) { response.setHeader( resourceManager.contentTypeForResourceNamed( resource ), "Content-Type" ); response.setContent( new NSData( data ) ); return response; } } response.setStatus( 404 ); // not found return response; } } /* * $Log$ * Revision 1.2 2006/02/19 01:44:02 cgruber * Add xmlrpc files * Remove jclark and replace with dom4j and javax.xml.sax stuff * Re-work dependencies and imports so it all compiles. * * Revision 1.1 2006/02/16 13:22:22 cgruber * Check in all sources in eclipse-friendly maven-enabled packages. * * Revision 1.6 2003/08/07 00:15:15 chochos * general cleanup (mostly removing unused imports) * * Revision 1.5 2003/01/27 15:08:00 mpowers * Implemented WOResourceManager, using java resources for now. * * Revision 1.4 2003/01/22 23:01:36 mpowers * Better handling for request handler path. * Better support for resources with absolute path. * * Revision 1.3 2003/01/20 16:18:22 mpowers * Fixed class loading issues with resource retrieval. * * Revision 1.2 2003/01/17 20:58:20 mpowers * Fixed up WOHyperlink. * * */