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.settings;
018
019import java.util.List;
020
021import org.apache.wicket.IRequestListener;
022import org.apache.wicket.markup.resolver.IComponentResolver;
023import org.apache.wicket.util.lang.Generics;
024
025/**
026 * Class for page related settings.
027 *
028 * @author Jonathan Locke
029 * @author Chris Turner
030 * @author Eelco Hillenius
031 * @author Juergen Donnerstag
032 * @author Johan Compagner
033 * @author Igor Vaynberg (ivaynberg)
034 * @author Martijn Dashorst
035 * @author James Carman
036 */
037public class PageSettings
038{
039        /** List of (static) ComponentResolvers */
040        private final List<IComponentResolver> componentResolvers = Generics.newArrayList();
041
042        /** Determines if pages should be managed by a version manager by default */
043        private boolean versionPagesByDefault = true;
044
045        /** determines if bookmarkable pages should be recreated after expiry */
046        private boolean recreateBookmarkablePagesAfterExpiry = true;
047
048        /**
049         * determines whether an {@link IRequestListener} can be executed
050         * when its owning page is freshly created after expiration
051         */
052        private boolean callListenerAfterExpiry = false;
053
054        /**
055         * Adds a component resolver to the list.
056         *
057         * @param resolver
058         *            The {@link IComponentResolver} that is added
059         * @return {@code this} object for chaining
060         */
061        public PageSettings addComponentResolver(IComponentResolver resolver)
062        {
063                componentResolvers.add(resolver);
064                return this;
065        }
066
067        /**
068         * Get the (modifiable) list of IComponentResolvers.
069         *
070         * @return List of ComponentResolvers
071         */
072        public List<IComponentResolver> getComponentResolvers()
073        {
074                return componentResolvers;
075        }
076
077        /**
078         * @return whether all pages should should update their page id when their component hierarchy
079         *      changes somehow
080         */
081        public boolean getVersionPagesByDefault()
082        {
083                return versionPagesByDefault;
084        }
085
086        /**
087         * A global setting that tells the pages to update their page id if their component
088         * hierarchy changes somehow. This way versioned pages can have several versions
089         * stored in the page stores and the user can go back and forth through the different
090         * versions. If a page is not versioned then only its last state is keep in the page
091         * stores and going back will lead the user to the page before the current one, not
092         * to the previous state of the current one.
093         *
094         * @param pagesVersionedByDefault
095         *      a flag that indicates whether pages should increase their page id when
096         *      their component hierarchy changes somehow.
097         * @return {@code this} object for chaining
098         */
099        public PageSettings setVersionPagesByDefault(boolean pagesVersionedByDefault)
100        {
101                versionPagesByDefault = pagesVersionedByDefault;
102                return this;
103        }
104
105        /**
106         * When enabled (default), urls on mounted pages will contain the full mount path, including
107         * PageParameters, allowing wicket to reinstantiate the page if got expired. When disabled, urls
108         * only use the page id. If this setting is enabled, you should take care that names form fields
109         * on mounted pages do not clash with the page parameters.
110         *
111         * @return if urls on mounted pages should be the full mount path
112         * @see <a href="https://issues.apache.org/jira/browse/WICKET-4014">WICKET-4014</a>
113         * @see <a href="https://issues.apache.org/jira/browse/WICKET-4290">WICKET-4290</a>
114         */
115        public boolean getRecreateBookmarkablePagesAfterExpiry()
116        {
117                return recreateBookmarkablePagesAfterExpiry;
118        }
119
120        /**
121         * Sets the recreateBookmarkablePagesAfterExpiry setting
122         *
123         * @param recreateBookmarkablePagesAfterExpiry
124         * @return {@code this} object for chaining
125         */
126        public PageSettings setRecreateBookmarkablePagesAfterExpiry(boolean recreateBookmarkablePagesAfterExpiry)
127        {
128                this.recreateBookmarkablePagesAfterExpiry = recreateBookmarkablePagesAfterExpiry;
129                return this;
130        }
131
132        /**
133         * @return {@code true} if Wicket should execute an {@link IRequestListener} on a component
134         *      which owning page is freshly created after expiration of the old one
135         * @see #getRecreateBookmarkablePagesAfterExpiry()
136         * @see org.apache.wicket.request.component.IRequestableComponent#canCallListenerAfterExpiry()
137         */
138        public boolean getCallListenerAfterExpiry()
139        {
140                return recreateBookmarkablePagesAfterExpiry && callListenerAfterExpiry;
141        }
142
143        /**
144         * Sets a setting that determines whether Wicket should execute the {@link IRequestListener} on a component
145         * which owner page is freshly created after expiration of the old one
146         *
147         * @param callAfterExpiry
148         *          {@code true} if Wicket should execute the listener
149         * @see #setRecreateBookmarkablePagesAfterExpiry(boolean)
150         * @see org.apache.wicket.request.component.IRequestableComponent#canCallListenerAfterExpiry()
151         * @return {@code this} object for chaining
152         */
153        public PageSettings setCallListenerAfterExpiry(boolean callAfterExpiry)
154        {
155                this.callListenerAfterExpiry = callAfterExpiry;
156                return this;
157        }
158}