001package org.apache.turbine.modules.screens.error;
002
003
004/*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements.  See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership.  The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License.  You may obtain a copy of the License at
012 *
013 *   http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied.  See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024import org.apache.fulcrum.parser.ParameterParser;
025import org.apache.turbine.modules.Screen;
026import org.apache.turbine.pipeline.PipelineData;
027import org.apache.turbine.util.RunData;
028import org.apache.turbine.util.uri.TurbineURI;
029
030/**
031 * Users will get this screen if the screen on their browser is in an
032 * invalid state.  For example, if they hit "Back" or "Reload" and
033 * then try to submit old form data.
034 *
035 * If you want one of your screens to check for invalid state
036 * then add a hidden form field called "_session_access_counter"
037 * with the value currently stored in the session.  The
038 * SessionValidator action will check to see if it is an old
039 * value and redirect you to this screen.
040 *
041 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
042 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
043 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
044 * @version $Id$
045 */
046public class InvalidState implements Screen
047{
048    /**
049     * Build the Screen.
050     *
051     * @param pipelineData Turbine information.
052     * @throws Exception a generic exception.
053     */
054    @Override
055    public String doBuild(PipelineData pipelineData)
056            throws Exception
057    {
058        RunData data = pipelineData.getRunData();
059        StringBuilder body = new StringBuilder();
060        body.append("<body>");
061
062        StringBuilder message = new StringBuilder();
063        StringBuilder sb = new StringBuilder();
064        sb.append("<b>There has been an error.</b>")
065                .append("<p>")
066                .append("- If you used the browser \"Back\" or \"Reload\"")
067                .append(" buttons please use the navigation buttons we provide")
068                .append(" within the screen.")
069                .append("<p>")
070                .append("Please click ");
071
072        message.append(sb.toString());
073        ParameterParser pp;
074        pp = (ParameterParser) data.getUser().getTemp("prev_parameters");
075        pp.remove("_session_access_counter");
076
077        TurbineURI back = new TurbineURI(data,(String) data.getUser().getTemp("prev_screen"));
078        back.addPathInfo(pp);
079        message.append( "<a href=\"" ).append(back.getRelativeLink()).append("\">here</a>");
080        message.append(" to return the the screen you were working on.");
081
082        body.append(message);
083        body.append("</body>");
084        return body.toString();
085    }
086}