01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import java.io.IOException;
18:
19: import org.apache.tapestry.services.ComponentClassResolver;
20: import org.apache.tapestry.services.Dispatcher;
21: import org.apache.tapestry.services.PageRenderRequestHandler;
22: import org.apache.tapestry.services.Request;
23: import org.apache.tapestry.services.Response;
24:
25: /**
26: * Recognizes a request for the application root (i.e., "/") and handles this the same as a render
27: * request for the "Start" page.
28: */
29: public class RootPathDispatcher implements Dispatcher {
30: private final ComponentClassResolver _componentClassResolver;
31:
32: private final PageRenderRequestHandler _handler;
33:
34: private final PageResponseRenderer _renderer;
35:
36: private final String _startPageName;
37:
38: private final String[] _emptyContext = new String[0];
39:
40: public RootPathDispatcher(
41: final ComponentClassResolver componentClassResolver,
42: final PageRenderRequestHandler handler,
43: final PageResponseRenderer renderer,
44: final String startPageName) {
45: _componentClassResolver = componentClassResolver;
46: _handler = handler;
47: _renderer = renderer;
48: _startPageName = startPageName;
49: }
50:
51: public boolean dispatch(Request request, final Response response)
52: throws IOException {
53: // Only match the root path
54:
55: if (!request.getPath().equals("/"))
56: return false;
57:
58: if (_componentClassResolver.isPageName(_startPageName)) {
59: _handler.handle(_startPageName, _emptyContext);
60:
61: return true;
62: }
63:
64: return false;
65: }
66:
67: }
|