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