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        private final String stringId;
033
034        /**
035         * Construct.
036         *
037         * @param pageId
038         */
039        public PageInfo(final Integer pageId)
040        {
041                this.pageId = pageId;
042                stringId = (pageId == null) ? "" : pageId.toString();
043        }
044
045        /**
046         * Construct.
047         */
048        public PageInfo()
049        {
050                this(null);
051        }
052
053        /**
054         * @return page id
055         */
056        public Integer getPageId()
057        {
058                return pageId;
059        }
060
061        /**
062         * The {@link #pageId} as string
063         */
064        @Override
065        public String toString()
066        {
067                return stringId;
068        }
069
070
071        /**
072         * @param src
073         * @return page info instance or <code>null</code> if the string couldn't have been parsed
074         */
075        public static PageInfo parse(final String src)
076        {
077                if (Strings.isEmpty(src))
078                {
079                        return new PageInfo();
080                }
081                else
082                {
083                        try
084                        {
085                                return new PageInfo(Integer.valueOf(src));
086                        }
087                        catch (NumberFormatException e)
088                        {
089                                return null;
090                        }
091                }
092        }
093}