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.request.mapper.info; 018 019import org.apache.wicket.util.string.Strings; 020 021/** 022 * Possible string representation of PageInfo: 023 * <ul> 024 * <li>pageId 025 * </ul> 026 * 027 * @author Matej Knopp 028 */ 029public class PageInfo 030{ 031 private final Integer pageId; 032 033 /** 034 * Construct. 035 * 036 * @param pageId 037 */ 038 public PageInfo(final Integer pageId) 039 { 040 this.pageId = pageId; 041 } 042 043 /** 044 * Construct. 045 */ 046 public PageInfo() 047 { 048 this(null); 049 } 050 051 /** 052 * @return page id 053 */ 054 public Integer getPageId() 055 { 056 return pageId; 057 } 058 059 /** 060 * The {@link #pageId} as string 061 */ 062 @Override 063 public String toString() 064 { 065 if (getPageId() == null) 066 { 067 return ""; 068 } 069 else 070 { 071 return getPageId().toString(); 072 } 073 } 074 075 076 /** 077 * @param src 078 * @return page info instance or <code>null</code> if the string couldn't have been parsed 079 */ 080 public static PageInfo parse(final String src) 081 { 082 if (Strings.isEmpty(src)) 083 { 084 return new PageInfo(); 085 } 086 else 087 { 088 try 089 { 090 return new PageInfo(Integer.valueOf(src)); 091 } 092 catch (NumberFormatException e) 093 { 094 return null; 095 } 096 } 097 } 098}