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.fulcrum.parser.ParameterParser;
25  import org.apache.turbine.modules.Screen;
26  import org.apache.turbine.pipeline.PipelineData;
27  import org.apache.turbine.util.RunData;
28  import org.apache.turbine.util.uri.TurbineURI;
29  
30  /**
31   * Users will get this screen if the screen on their browser is in an
32   * invalid state.  For example, if they hit "Back" or "Reload" and
33   * then try to submit old form data.
34   *
35   * If you want one of your screens to check for invalid state
36   * then add a hidden form field called "_session_access_counter"
37   * with the value currently stored in the session.  The
38   * SessionValidator action will check to see if it is an old
39   * value and redirect you to this screen.
40   *
41   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
42   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
43   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
44   * @version $Id$
45   */
46  public class InvalidState implements Screen
47  {
48      /**
49       * Build the Screen.
50       *
51       * @param pipelineData Turbine information.
52       * @throws Exception a generic exception.
53       */
54      @Override
55      public String doBuild(PipelineData pipelineData)
56              throws Exception
57      {
58          RunData data = pipelineData.getRunData();
59          StringBuilder body = new StringBuilder();
60          body.append("<body>");
61  
62          StringBuilder message = new StringBuilder();
63          StringBuilder sb = new StringBuilder();
64          sb.append("<b>There has been an error.</b>")
65                  .append("<p>")
66                  .append("- If you used the browser \"Back\" or \"Reload\"")
67                  .append(" buttons please use the navigation buttons we provide")
68                  .append(" within the screen.")
69                  .append("<p>")
70                  .append("Please click ");
71  
72          message.append(sb.toString());
73          ParameterParser pp;
74          pp = (ParameterParser) data.getUser().getTemp("prev_parameters");
75          pp.remove("_session_access_counter");
76  
77          TurbineURIuri/TurbineURI.html#TurbineURI">TurbineURI back = new TurbineURI(data,(String) data.getUser().getTemp("prev_screen"));
78          back.addPathInfo(pp);
79          message.append( "<a href=\"" ).append(back.getRelativeLink()).append("\">here</a>");
80          message.append(" to return the the screen you were working on.");
81  
82          body.append(message);
83          body.append("</body>");
84          return body.toString();
85      }
86  }