Coverage Report - net.wotonomy.web.WOResourceRequestHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
WOResourceRequestHandler
0% 
0% 
4.5
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2000 Blacksmith, Inc.
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 */
 18  
 
 19  
 package net.wotonomy.web;
 20  
 
 21  
 import java.util.Enumeration;
 22  
 
 23  
 import net.wotonomy.foundation.NSData;
 24  
 import net.wotonomy.foundation.NSMutableDictionary;
 25  
 
 26  
 /**
 27  
 * An implementation of WORequestHandler that  
 28  
 * retrieves resources from the deployed application.
 29  
 *
 30  
 * @author michael@mpowers.net
 31  
 * @author $Author: cgruber $
 32  
 * @version $Revision: 905 $
 33  
 */
 34  
 public class WOResourceRequestHandler
 35  
         extends WORequestHandler
 36  
 {
 37  
     private NSMutableDictionary resourceCache;
 38  
     private WOResourceManager resourceManager;
 39  
     
 40  0
     public WOResourceRequestHandler()
 41  0
     {
 42  
         //TODO: should probably have some kind of limit on the cache
 43  0
         resourceCache = new NSMutableDictionary();
 44  0
         resourceManager = WOApplication.application().resourceManager();
 45  0
     }
 46  
     
 47  
     public WOResponse handleRequest( WORequest aRequest )
 48  
     {
 49  0
         WOResponse response = new WOResponse();
 50  
         
 51  0
         StringBuffer buf = new StringBuffer();
 52  
         
 53  
         //TODO: this is just to get things working...
 54  0
         String framework = null;
 55  0
         Enumeration e = aRequest.requestHandlerPathArray().objectEnumerator();
 56  0
         if ( e.hasMoreElements() )
 57  
         {
 58  0
             framework = e.nextElement().toString();
 59  0
             if ( framework.equals( "application" ) )
 60  
             {
 61  0
                 buf.append('/').append( framework );
 62  0
                 framework = null;
 63  
             }
 64  
         }
 65  0
         if ( e.hasMoreElements() )
 66  
         {
 67  0
             buf.append( e.nextElement() );
 68  
         }
 69  0
         while ( e.hasMoreElements() )
 70  
         {
 71  0
             buf.append('/').append( e.nextElement() );
 72  0
         }
 73  
         
 74  
         String resource;
 75  0
         if ( buf.length() > 0 )
 76  
         {
 77  0
             resource = buf.toString();
 78  0
             byte[] data = resourceManager.bytesForResourceNamed(
 79  0
                 resource, framework, aRequest.browserLanguages() );
 80  0
             if ( data != null )
 81  
             {
 82  0
                 response.setHeader(
 83  0
                     resourceManager.contentTypeForResourceNamed( resource ),
 84  0
                     "Content-Type" );
 85  0
                 response.setContent( new NSData( data ) );
 86  0
                 return response;
 87  
             }
 88  
         }
 89  0
         response.setStatus( 404 ); // not found
 90  0
         return response;
 91  
     }
 92  
 }
 93  
 
 94  
 /*
 95  
  * $Log$
 96  
  * Revision 1.2  2006/02/19 01:44:02  cgruber
 97  
  * Add xmlrpc files
 98  
  * Remove jclark and replace with dom4j and javax.xml.sax stuff
 99  
  * Re-work dependencies and imports so it all compiles.
 100  
  *
 101  
  * Revision 1.1  2006/02/16 13:22:22  cgruber
 102  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 103  
  *
 104  
  * Revision 1.6  2003/08/07 00:15:15  chochos
 105  
  * general cleanup (mostly removing unused imports)
 106  
  *
 107  
  * Revision 1.5  2003/01/27 15:08:00  mpowers
 108  
  * Implemented WOResourceManager, using java resources for now.
 109  
  *
 110  
  * Revision 1.4  2003/01/22 23:01:36  mpowers
 111  
  * Better handling for request handler path.
 112  
  * Better support for resources with absolute path.
 113  
  *
 114  
  * Revision 1.3  2003/01/20 16:18:22  mpowers
 115  
  * Fixed class loading issues with resource retrieval.
 116  
  *
 117  
  * Revision 1.2  2003/01/17 20:58:20  mpowers
 118  
  * Fixed up WOHyperlink.
 119  
  *
 120  
  *
 121  
  */
 122