1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 public WOResourceRequestHandler()
41 {
42
43 resourceCache = new NSMutableDictionary();
44 resourceManager = WOApplication.application().resourceManager();
45 }
46
47 public WOResponse handleRequest( WORequest aRequest )
48 {
49 WOResponse response = new WOResponse();
50
51 StringBuffer buf = new StringBuffer();
52
53
54 String framework = null;
55 Enumeration e = aRequest.requestHandlerPathArray().objectEnumerator();
56 if ( e.hasMoreElements() )
57 {
58 framework = e.nextElement().toString();
59 if ( framework.equals( "application" ) )
60 {
61 buf.append('/').append( framework );
62 framework = null;
63 }
64 }
65 if ( e.hasMoreElements() )
66 {
67 buf.append( e.nextElement() );
68 }
69 while ( e.hasMoreElements() )
70 {
71 buf.append('/').append( e.nextElement() );
72 }
73
74 String resource;
75 if ( buf.length() > 0 )
76 {
77 resource = buf.toString();
78 byte[] data = resourceManager.bytesForResourceNamed(
79 resource, framework, aRequest.browserLanguages() );
80 if ( data != null )
81 {
82 response.setHeader(
83 resourceManager.contentTypeForResourceNamed( resource ),
84 "Content-Type" );
85 response.setContent( new NSData( data ) );
86 return response;
87 }
88 }
89 response.setStatus( 404 );
90 return response;
91 }
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122