View Javadoc

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