001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry;
016    
017    import org.apache.hivemind.ApplicationRuntimeException;
018    
019    /**
020     * Exception thrown to force a redirection to an arbitrary location. This is
021     * used when, after processing a request (such as a form submission or a link
022     * being clicked), it is desirable to go to some arbitrary new location.
023     * 
024     * @author Howard Lewis Ship
025     * @since 1.0.6
026     */
027    
028    public class RedirectException extends ApplicationRuntimeException
029    {
030    
031        private static final long serialVersionUID = -9215837473156146010L;
032    
033        private final String _redirectLocation;
034    
035        public RedirectException(String redirectLocation)
036        {
037            this(null, redirectLocation);
038        }
039    
040        /**
041         * @param message
042         *            A message describing why the redirection is taking place.
043         * @param redirectLocation
044         *            The location to redirect to, may be a relative path (relative
045         *            to the {@link javax.servlet.ServletContext}).
046         * @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
047         * @see javax.servlet.http.HttpServletResponse#encodeRedirectURL(String)
048         */
049    
050        public RedirectException(String message, String redirectLocation)
051        {
052            super(message);
053    
054            _redirectLocation = redirectLocation;
055        }
056    
057        public String getRedirectLocation()
058        {
059            return _redirectLocation;
060        }
061    }