    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.ecs.ElementContainer;
    025import org.apache.ecs.html.A;
    026import org.apache.fulcrum.parser.ParameterParser;
    027import org.apache.turbine.modules.Screen;
    028import org.apache.turbine.pipeline.PipelineData;
    029import org.apache.turbine.util.RunData;
    030import org.apache.turbine.util.uri.TurbineURI;
    031
    032/**
    033 * Users will get this screen if the screen on their browser is in an
    034 * invalid state.  For example, if they hit "Back" or "Reload" and
    035 * then try to submit old form data.
    036 *
    037 * If you want one of your screens to check for invalid state
    038 * then add a hidden form field called "_session_access_counter"
    039 * with the value currently stored in the session.  The
    040 * SessionValidator action will check to see if it is an old
    041 * value and redirect you to this screen.
    042 *
    043 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    044 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    045 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    046 * @version $Id: InvalidState.java 1773378 2016-12-09 13:19:59Z tv $
    047 */
    048public class InvalidState
    049    extends Screen
    050{
    051    /**
    052     * Build the Screen.
    053     *
    054     * @param pipelineData Turbine information.
    055     * @throws Exception a generic exception.
    056     */
    057    @Override
    058    public String doBuild(PipelineData pipelineData)
    059            throws Exception
    060    {
    061        RunData data = getRunData(pipelineData);
    062        ElementContainer body = new ElementContainer();
    063        ElementContainer message = new ElementContainer();
    064
    065        StringBuilder sb = new StringBuilder();
    066        sb.append("<b>There has been an error.</b>")
    067                .append("<p>")
    068                .append("- If you used the browser \"Back\" or \"Reload\"")
    069                .append(" buttons please use the navigation buttons we provide")
    070                .append(" within the screen.")
    071                .append("<p>")
    072                .append("Please click ");
    073
    074        message.addElement(sb.toString());
    075        ParameterParser pp;
    076        pp = (ParameterParser) data.getUser().getTemp("prev_parameters");
    077        pp.remove("_session_access_counter");
    078
    079        TurbineURI back = new TurbineURI(data,(String) data.getUser().getTemp("prev_screen"));
    080        back.addPathInfo(pp);
    081        message.addElement(new A().setHref(back.getRelativeLink()).addElement("here"));
    082
    083        message.addElement(" to return the the screen you were working on.");
    084
    085        body.addElement(message);
    086        return body.toString();
    087    }
    088}