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
019/**
020 * Settings class for various debug settings
021 * <p>
022 * <i>componentUseCheck </i> (defaults to true in development mode) - causes the framework to do a
023 * check after rendering each page to ensure that each component was used in rendering the markup.
024 * If components are found that are not referenced in the markup, an appropriate error will be
025 * displayed
026 *
027 * @author Jonathan Locke
028 * @author Chris Turner
029 * @author Eelco Hillenius
030 * @author Juergen Donnerstag
031 * @author Johan Compagner
032 * @author Igor Vaynberg (ivaynberg)
033 * @author Martijn Dashorst
034 * @author James Carman
035 */
036public class DebugSettings
037{
038        /** ajax debug mode status */
039        private boolean ajaxDebugModeEnabled = false;
040
041        /** True to check that each component on a page is used */
042        private boolean componentUseCheck = true;
043
044        /**
045         * whether wicket should track line precise additions of components for error reporting.
046         */
047        private boolean linePreciseReportingOnAddComponentEnabled = false;
048
049        /**
050         * whether wicket should track line precise instantiations of components for error reporting.
051         */
052        private boolean linePreciseReportingOnNewComponentEnabled = false;
053
054        /**
055         * Whether the container's class name should be printed to response (in a html comment).
056         */
057        private boolean outputMarkupContainerClassName = false;
058
059        private String componentPathAttributeName = null;
060
061        private boolean developmentUtilitiesEnabled = false;
062
063        /**
064         * @return true if componentUseCheck is enabled
065         */
066        public boolean getComponentUseCheck()
067        {
068                return componentUseCheck;
069        }
070
071        /**
072         * Returns status of ajax debug mode.
073         *
074         * @return true if ajax debug mode is enabled, false otherwise
075         */
076        public boolean isAjaxDebugModeEnabled()
077        {
078                return ajaxDebugModeEnabled;
079        }
080
081        /**
082         * Returns status of line precise error reporting for added components that are not present in
083         * the markup: it points to the line where the component was added to the hierarchy in your Java
084         * classes. This can cause a significant decrease in performance, do not use in customer facing
085         * applications.
086         *
087         * @return true if the line precise error reporting is enabled
088         */
089        public boolean isLinePreciseReportingOnAddComponentEnabled()
090        {
091                return linePreciseReportingOnAddComponentEnabled;
092        }
093
094        /**
095         * Returns status of line precise error reporting for new components that are not present in the
096         * markup: it points to the line where the component was created in your Java classes. This can
097         * cause a significant decrease in performance, do not use in customer facing applications.
098         *
099         * @return true if the line precise error reporting is enabled
100         */
101        public boolean isLinePreciseReportingOnNewComponentEnabled()
102        {
103                return linePreciseReportingOnNewComponentEnabled;
104        }
105
106        /**
107         * Returns whether the output of markup container's should be wrapped by comments containing the
108         * container's class name.
109         *
110         * @return true if the markup container's class name should be written to response
111         */
112        public boolean isOutputMarkupContainerClassName()
113        {
114                return outputMarkupContainerClassName;
115        }
116
117        /**
118         * Enables or disables ajax debug mode.
119         *
120         * @param enable
121         * @return {@code this} object for chaining
122         */
123        public DebugSettings setAjaxDebugModeEnabled(boolean enable)
124        {
125                ajaxDebugModeEnabled = enable;
126                return this;
127        }
128
129        /**
130         * Sets componentUseCheck debug settings
131         *
132         * @param componentUseCheck
133         * @return {@code this} object for chaining
134         */
135        public DebugSettings setComponentUseCheck(final boolean componentUseCheck)
136        {
137                this.componentUseCheck = componentUseCheck;
138                return this;
139        }
140
141        /**
142         * Enables line precise error reporting for added components that are not present in the markup:
143         * it points to the line where the component was added to the hierarchy in your Java classes.
144         * This can cause a significant decrease in performance, do not use in customer facing
145         * applications.
146         *
147         * @param enable
148         * @return {@code this} object for chaining
149         */
150        public DebugSettings setLinePreciseReportingOnAddComponentEnabled(boolean enable)
151        {
152                linePreciseReportingOnAddComponentEnabled = enable;
153                return this;
154        }
155
156        /**
157         * Enables line precise error reporting for new components that are not present in the markup:
158         * it points to the line where the component was created in your Java classes. This can cause a
159         * significant decrease in performance, do not use in customer facing applications.
160         *
161         * @param enable
162         * @return {@code this} object for chaining
163         */
164        public DebugSettings setLinePreciseReportingOnNewComponentEnabled(boolean enable)
165        {
166                linePreciseReportingOnNewComponentEnabled = enable;
167                return this;
168        }
169
170        /**
171         * Enables wrapping output of markup container in html comments that contain markup container's
172         * class name. (Useful for determining which part of page belongs to which markup file).
173         *
174         * @param enable
175         * @return {@code this} object for chaining
176         */
177        public DebugSettings setOutputMarkupContainerClassName(boolean enable)
178        {
179                outputMarkupContainerClassName = enable;
180                return this;
181        }
182
183        /**
184         * If the parameter value is non-empty then Wicket will use it as the name of an attribute of the
185         * component tag to print the {@link org.apache.wicket.Component}'s path.
186         * This can be useful for debugging and automating tests.
187         *
188         * For example: if {@code componentPathAttributeName} is 'data-wicket-path' then Wicket will add
189         * an attribute to the {@link org.apache.wicket.markup.ComponentTag} for each component with name
190         * 'data-wicket-path' and as a value the component's
191         * {@link org.apache.wicket.Component#getPageRelativePath() page relative path}.
192         *
193         * @param componentPathAttributeName
194         *          The name of the attribute for the {@link org.apache.wicket.markup.ComponentTag}.
195         *          If {@code null} or empty then the attribute won't be rendered
196         * @return {@code this} object for chaining
197         */
198        public DebugSettings setComponentPathAttributeName(String componentPathAttributeName)
199        {
200                this.componentPathAttributeName = componentPathAttributeName;
201                return this;
202        }
203
204        /**
205         * @see #setComponentPathAttributeName(String)
206         * @return The name of the attribute for the {@link org.apache.wicket.markup.ComponentTag}.
207         *         If {@code null} or empty then the attribute won't be rendered
208         */
209        public String getComponentPathAttributeName()
210        {
211                return componentPathAttributeName;
212        }
213
214
215        /**
216         * Enables all of the panels and pages, etc, from wicket-devutils package.
217         *
218         * @param enable
219         * @return {@code this} object for chaining
220         */
221        public DebugSettings setDevelopmentUtilitiesEnabled(boolean enable)
222        {
223                developmentUtilitiesEnabled = enable;
224                return this;
225        }
226
227        /**
228         * Are all of the panels and pages, etc, from wicket-devutils package enabled?
229         *
230         * @return true if all of the panels and pages, etc, from wicket-devutils package are enabled
231         */
232        public boolean isDevelopmentUtilitiesEnabled()
233        {
234                return developmentUtilitiesEnabled;
235        }
236}