package votorola.g.web.wic; // Copyright 2010, 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import org.apache.wicket.request.*; import org.apache.wicket.request.RequestHandlerStack.ReplaceHandlerException; import org.apache.wicket.request.http.WebResponse; /** An alternative redirect exception that supports not only HTTP 301 (permanent) and 302 * (temporary) redirects, but also 303 (see other). * * @see org.apache.wicket.request.flow.RedirectToUrlException * @see Status Code Definitions */ public final class RedirectException extends ReplaceHandlerException { /** Constructs a RedirectException. * * @param _location the redirection target, to be used as the HTTP Location field * in the response. * @param _statusCode the HTTP status code. Only 301 and 303 are tested. */ public RedirectException( String _location, int _statusCode ) { super( new RequestHandler(_location,_statusCode), true ); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private static final class RequestHandler implements IRequestHandler { // cf. org.apache.wicket.request.http.handler.RedirectRequestHandler private RequestHandler( String _location, int _statusCode ) { location = _location; statusCode = _statusCode; } private final String location; private final int statusCode; // - I - R e q u e s t - H a n d l e r -------------------------------------------- public void detach( IRequestCycle requestCycle ) {} public void respond( final IRequestCycle requestCycle ) { final WebResponse response = (WebResponse)requestCycle.getResponse(); if( statusCode == 302 ) response.sendRedirect( location ); else { response.setStatus( statusCode ); response.setHeader( "Location", location ); } } } }