001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.markup.html.pages; 018 019import org.apache.wicket.AttributeModifier; 020import org.apache.wicket.Page; 021import org.apache.wicket.core.request.handler.PageProvider; 022import org.apache.wicket.core.request.handler.RenderPageRequestHandler; 023import org.apache.wicket.markup.html.WebMarkupContainer; 024import org.apache.wicket.markup.html.WebPage; 025import org.apache.wicket.model.Model; 026 027/** 028 * Page that let the browser redirect. Use this if you want to direct the browser to some external 029 * URL, like Google etc. or if you want to redirect to a Wicket page, but with a delay. 030 * 031 * @author Eelco Hillenius 032 */ 033public class RedirectPage extends WebPage 034{ 035 private static final long serialVersionUID = 1L; 036 037 /** 038 * Constructor. The page will immediately redirect to the given url. 039 * 040 * @param url 041 * The url to redirect to 042 */ 043 public RedirectPage(final CharSequence url) 044 { 045 this(url, 0); 046 } 047 048 /** 049 * Constructor. The page will redirect to the given url after waiting for the given number of 050 * seconds. 051 * 052 * @param url 053 * The url to redirect to 054 * @param waitBeforeRedirectInSeconds 055 * The number of seconds the browser should wait before redirecting 056 */ 057 public RedirectPage(final CharSequence url, final int waitBeforeRedirectInSeconds) 058 { 059 final WebMarkupContainer redirect = new WebMarkupContainer("redirect"); 060 final String content = waitBeforeRedirectInSeconds + ";URL=" + url; 061 redirect.add(new AttributeModifier("content", new Model<>(content))); 062 add(redirect); 063 } 064 065 /** 066 * Construct. The page will redirect to the given Page. 067 * 068 * @param page 069 * The page to redirect to. 070 */ 071 public RedirectPage(final Page page) 072 { 073 this(page, 0); 074 } 075 076 /** 077 * Construct. The page will redirect to the given Page after waiting for the given number of 078 * seconds. 079 * 080 * @param page 081 * The page to redirect to. 082 * @param waitBeforeRedirectInSeconds 083 * The number of seconds the browser should wait before redirecting 084 */ 085 public RedirectPage(final Page page, final int waitBeforeRedirectInSeconds) 086 { 087 this(page.urlFor(new RenderPageRequestHandler(new PageProvider(page))), 088 waitBeforeRedirectInSeconds); 089 } 090 091 /** 092 * @see org.apache.wicket.Component#isVersioned() 093 */ 094 @Override 095 public boolean isVersioned() 096 { 097 return false; 098 } 099}