Coverage Report - org.apache.tapestry.engine.ResetService
 
Classes in this File Line Coverage Branch Coverage Complexity
ResetService
0%
0/22
0%
0/4
1.375
 
 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;
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 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.ResetEventHub;
 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
 30  
  * cetera). This is primarily used during development. It could be a weakness of
 31  
  * a Tapestry application, making it susceptible to denial of service attacks,
 32  
  * which is why it is disabled by default. The link generated by the
 33  
  * ResetService redisplays the current page after discarding all data.
 34  
  * 
 35  
  * @author Howard Lewis Ship
 36  
  * @since 1.0.9
 37  
  */
 38  
 
 39  0
 public class ResetService implements IEngineService
 40  
 {
 41  
 
 42  
     /** @since 4.0 */
 43  
 
 44  
     private ResponseRenderer _responseRenderer;
 45  
 
 46  
     /** @since 4.0 */
 47  
 
 48  
     private ResetEventHub _resetEventHub;
 49  
 
 50  
     /** @since 4.0 */
 51  
     private boolean _enabled;
 52  
 
 53  
     /** @since 4.0 */
 54  
 
 55  
     private LinkFactory _linkFactory;
 56  
 
 57  
     /** @since 4.0 */
 58  
     private IRequestCycle _requestCycle;
 59  
 
 60  
     public ILink getLink(boolean post, Object parameter)
 61  
     {
 62  0
         if (parameter != null)
 63  0
             throw new IllegalArgumentException(EngineMessages
 64  
                     .serviceNoParameter(this));
 65  
 
 66  0
         Map parameters = new HashMap();
 67  
 
 68  0
         parameters.put(ServiceConstants.PAGE, _requestCycle.getPage()
 69  
                 .getPageName());
 70  
 
 71  0
         return _linkFactory.constructLink(this, post, parameters, true);
 72  
     }
 73  
 
 74  
     public String getName()
 75  
     {
 76  0
         return Tapestry.RESET_SERVICE;
 77  
     }
 78  
 
 79  
     public void service(IRequestCycle cycle)
 80  
         throws IOException
 81  
     {
 82  0
         String pageName = cycle.getParameter(ServiceConstants.PAGE);
 83  
 
 84  0
         if (_enabled) _resetEventHub.fireResetEvent();
 85  
 
 86  0
         cycle.activate(pageName);
 87  
 
 88  
         // Render the same page (that contained the reset link).
 89  
 
 90  0
         _responseRenderer.renderResponse(cycle);
 91  0
     }
 92  
 
 93  
     /** @since 4.0 */
 94  
     public void setResponseRenderer(ResponseRenderer responseRenderer)
 95  
     {
 96  0
         _responseRenderer = responseRenderer;
 97  0
     }
 98  
 
 99  
     /** @since 4.0 */
 100  
 
 101  
     public void setResetEventHub(ResetEventHub resetEventHub)
 102  
     {
 103  0
         _resetEventHub = resetEventHub;
 104  0
     }
 105  
 
 106  
     /** @since 4.0 */
 107  
 
 108  
     public void setEnabled(boolean enabled)
 109  
     {
 110  0
         _enabled = enabled;
 111  0
     }
 112  
 
 113  
     /** @since 4.0 */
 114  
     public void setLinkFactory(LinkFactory linkFactory)
 115  
     {
 116  0
         _linkFactory = linkFactory;
 117  0
     }
 118  
 
 119  
     /** @since 4.0 */
 120  
     public void setRequestCycle(IRequestCycle requestCycle)
 121  
     {
 122  0
         _requestCycle = requestCycle;
 123  0
     }
 124  
 }