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.core.request.mapper; 018 019import java.util.function.Supplier; 020 021import org.apache.wicket.request.Request; 022import org.apache.wicket.request.Url; 023import org.apache.wicket.request.component.IRequestablePage; 024import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder; 025 026/** 027 * A mapper that is used when a request to the home page ("/") is made 028 */ 029public class HomePageMapper extends MountedMapper 030{ 031 032 /** 033 * Construct. 034 * 035 * @param pageClass 036 * the class of the page which should handle requests to "/" 037 */ 038 public HomePageMapper(final Class<? extends IRequestablePage> pageClass) 039 { 040 super("/", pageClass); 041 } 042 043 /** 044 * Construct. 045 * 046 * @param pageClassProvider 047 * the class of the page which should handle requests to "/" 048 */ 049 public HomePageMapper(Supplier<Class<? extends IRequestablePage>> pageClassProvider) 050 { 051 super("/", pageClassProvider); 052 } 053 054 /** 055 * Construct. 056 * 057 * @param pageClass 058 * the class of the page which should handle requests to "/" 059 * @param pageParametersEncoder 060 * the encoder that will be used to encode/decode the page parameters 061 */ 062 public HomePageMapper(Class<? extends IRequestablePage> pageClass, 063 IPageParametersEncoder pageParametersEncoder) 064 { 065 super("/", pageClass, pageParametersEncoder); 066 } 067 068 /** 069 * Matches only when there are no segments/indexed parameters 070 * 071 * @see AbstractBookmarkableMapper#parseRequest(org.apache.wicket.request.Request) 072 */ 073 @Override 074 protected UrlInfo parseRequest(Request request) 075 { 076 // get canonical url 077 final Url url = request.getUrl().canonical(); 078 079 if (url.getSegments().size() > 0) 080 { 081 // home page cannot have segments/indexed parameters 082 return null; 083 } 084 085 return super.parseRequest(request); 086 } 087 088 /** 089 * Use this mapper as a last option. Let all other mappers to try to handle the request 090 * 091 * @see MountedMapper#getCompatibilityScore(org.apache.wicket.request.Request) 092 */ 093 @Override 094 public int getCompatibilityScore(Request request) 095 { 096 return Integer.MIN_VALUE + 1; 097 } 098 099}