View Javadoc

1   package org.apache.turbine.modules.screens.error;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  
24  import org.apache.ecs.ConcreteElement;
25  import org.apache.ecs.ElementContainer;
26  
27  import org.apache.ecs.html.A;
28  import org.apache.fulcrum.parser.ParameterParser;
29  
30  import org.apache.turbine.modules.Screen;
31  import org.apache.turbine.pipeline.PipelineData;
32  import org.apache.turbine.util.RunData;
33  import org.apache.turbine.util.uri.TurbineURI;
34  
35  /**
36   * Users will get this screen if the screen on their browser is in an
37   * invalid state.  For example, if they hit "Back" or "Reload" and
38   * then try to submit old form data.
39   *
40   * If you want one of your screens to check for invalid state
41   * then add a hidden form field called "_session_access_counter"
42   * with the value currently stored in the session.  The
43   * SessionValidator action will check to see if it is an old
44   * value and redirect you to this screen.
45   *
46   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
47   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
48   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
49   * @version $Id: InvalidState.java 717934 2008-11-15 21:48:47Z tv $
50   */
51  public class InvalidState
52      extends Screen
53  {
54      /**
55       * Build the Screen.
56       *
57       * @param data Turbine information.
58       * @exception Exception, a generic exception.
59       */
60      public ConcreteElement doBuild(RunData data)
61              throws Exception
62      {
63          ElementContainer body = new ElementContainer();
64          ElementContainer message = new ElementContainer();
65  
66          StringBuffer sb = new StringBuffer();
67          sb.append("<b>There has been an error.</b>")
68                  .append("<p>")
69                  .append("- If you used the browser \"Back\" or \"Reload\"")
70                  .append(" buttons please use the navigation buttons we provide")
71                  .append(" within the screen.")
72                  .append("<p>")
73                  .append("Please click ");
74  
75          message.addElement(sb.toString());
76          ParameterParser pp;
77          pp = (ParameterParser) data.getUser().getTemp("prev_parameters");
78          pp.remove("_session_access_counter");
79  
80          TurbineURI back = new TurbineURI(data,(String) data.getUser().getTemp("prev_screen"));
81          back.addPathInfo(pp);
82          message.addElement(new A().setHref(back.getRelativeLink()).addElement("here"));
83  
84          message.addElement(" to return the the screen you were working on.");
85  
86          body.addElement(message);
87          return body;
88      }
89  
90      /**
91       * Build the Screen.
92       *
93       * @param pipelineData Turbine information.
94       * @exception Exception, a generic exception.
95       */
96      public ConcreteElement doBuild(PipelineData pipelineData)
97              throws Exception
98      {
99          RunData data = getRunData(pipelineData);
100         return doBuild(data);
101     }
102 
103 }