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;
018
019import org.apache.wicket.core.request.mapper.IMapperContext;
020import org.apache.wicket.markup.MarkupParser;
021import org.apache.wicket.page.IManageablePage;
022import org.apache.wicket.request.component.IRequestablePage;
023import org.apache.wicket.request.mapper.parameter.PageParameters;
024import org.apache.wicket.request.resource.ResourceReferenceRegistry;
025
026/**
027 * Wicket's default implementation for the mapper context
028 */
029public class DefaultMapperContext implements IMapperContext
030{
031        private final Application application;
032
033        /**
034         * Constructor.
035         *
036         * Uses the thread local Application
037         */
038        public DefaultMapperContext()
039        {
040                this(Application.get());
041        }
042
043        /**
044         * Constructor.
045         *
046         * @param application
047         *      the application instance to use
048         */
049        public DefaultMapperContext(final Application application)
050        {
051                this.application = application;
052        }
053
054        @Override
055        public String getBookmarkableIdentifier()
056        {
057                return "bookmarkable";
058        }
059
060        @Override
061        public String getNamespace()
062        {
063                return MarkupParser.WICKET;
064        }
065
066        @Override
067        public String getPageIdentifier()
068        {
069                return "page";
070        }
071
072        @Override
073        public String getResourceIdentifier()
074        {
075                return "resource";
076        }
077
078        @Override
079        public ResourceReferenceRegistry getResourceReferenceRegistry()
080        {
081                return application.getResourceReferenceRegistry();
082        }
083
084        @Override
085        public IRequestablePage newPageInstance(final Class<? extends IRequestablePage> pageClass,
086                final PageParameters pageParameters)
087        {
088                if (pageParameters == null)
089                {
090                        return application.getPageFactory().newPage(pageClass);
091                }
092                else
093                {
094                        return application.getPageFactory().newPage(pageClass, pageParameters);
095                }
096        }
097
098        @Override
099        public IRequestablePage getPageInstance(final int pageId)
100        {
101                IManageablePage manageablePage = Session.get().getPageManager().getPage(pageId);
102                IRequestablePage requestablePage = null;
103                if (manageablePage instanceof IRequestablePage)
104                {
105                        requestablePage = (IRequestablePage)manageablePage;
106                }
107                return requestablePage;
108        }
109
110        @Override
111        public Class<? extends IRequestablePage> getHomePageClass()
112        {
113                return application.getHomePage();
114        }
115}