KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > ResetService


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.engine;
16
17 import java.io.IOException JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.Tapestry;
23 import org.apache.tapestry.services.LinkFactory;
24 import org.apache.tapestry.services.ResetEventCoordinator;
25 import org.apache.tapestry.services.ResponseRenderer;
26 import org.apache.tapestry.services.ServiceConstants;
27
28 /**
29  * ServiceLink used to discard all cached data (templates, specifications, et cetera). This is
30  * primarily used during development. It could be a weakness of a Tapestry application, making it
31  * susceptible to denial of service attacks, which is why it is disabled by default. The link
32  * generated by the ResetService redisplays the current page after discarding all data.
33  *
34  * @author Howard Lewis Ship
35  * @since 1.0.9
36  */

37
38 public class ResetService implements IEngineService
39 {
40     /** @since 4.0 */
41
42     private ResponseRenderer _responseRenderer;
43
44     /** @since 4.0 */
45
46     private ResetEventCoordinator _resetEventCoordinator;
47
48     /** @since 4.0 */
49     private boolean _enabled;
50
51     /** @since 4.0 */
52
53     private LinkFactory _linkFactory;
54
55     public ILink getLink(IRequestCycle cycle, Object JavaDoc parameter)
56     {
57         if (parameter != null)
58             throw new IllegalArgumentException JavaDoc(EngineMessages.serviceNoParameter(this));
59
60         Map JavaDoc parameters = new HashMap JavaDoc();
61
62         parameters.put(ServiceConstants.SERVICE, Tapestry.RESET_SERVICE);
63         parameters.put(ServiceConstants.PAGE, cycle.getPage().getPageName());
64
65         return _linkFactory.constructLink(cycle, parameters, true);
66     }
67
68     public String JavaDoc getName()
69     {
70         return Tapestry.RESET_SERVICE;
71     }
72
73     public void service(IRequestCycle cycle) throws IOException JavaDoc
74     {
75         String JavaDoc pageName = cycle.getParameter(ServiceConstants.PAGE);
76
77         if (_enabled)
78             _resetEventCoordinator.fireResetEvent();
79
80         cycle.activate(pageName);
81
82         // Render the same page (that contained the reset link).
83

84         _responseRenderer.renderResponse(cycle);
85     }
86
87     /** @since 4.0 */
88     public void setResponseRenderer(ResponseRenderer responseRenderer)
89     {
90         _responseRenderer = responseRenderer;
91     }
92
93     /** @since 4.0 */
94
95     public void setResetEventCoordinator(ResetEventCoordinator resetEventCoordinator)
96     {
97         _resetEventCoordinator = resetEventCoordinator;
98     }
99
100     /** @since 4.0 */
101
102     public void setEnabled(boolean enabled)
103     {
104         _enabled = enabled;
105     }
106
107     /** @since 4.0 */
108     public void setLinkFactory(LinkFactory linkFactory)
109     {
110         _linkFactory = linkFactory;
111     }
112 }
Popular Tags