001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.internal; 014 015import java.util.Collections; 016import java.util.Set; 017import java.util.stream.Collectors; 018import java.util.stream.Stream; 019 020import org.apache.tapestry5.EventConstants; 021import org.apache.tapestry5.annotations.PublishEvent; 022import org.apache.tapestry5.annotations.RequestBody; 023import org.apache.tapestry5.annotations.RequestParameter; 024import org.apache.tapestry5.commons.util.CommonsUtils; 025import org.apache.tapestry5.commons.util.TimeInterval; 026import org.apache.tapestry5.dom.MarkupModel; 027import org.apache.tapestry5.http.ContentType; 028import org.apache.tapestry5.http.TapestryHttpConstants; 029import org.apache.tapestry5.http.internal.TapestryHttpInternalConstants; 030import org.apache.tapestry5.model.ComponentModel; 031import org.apache.tapestry5.services.javascript.JavaScriptStack; 032 033public final class InternalConstants 034{ 035 /** 036 * Init parameter used to identify the package from which application classes are loaded. Such 037 * classes are in the 038 * pages, components and mixins sub-packages. 039 * @deprecated Use {@link TapestryHttpInternalConstants#TAPESTRY_APP_PACKAGE_PARAM} instead 040 */ 041 public static final String TAPESTRY_APP_PACKAGE_PARAM = TapestryHttpInternalConstants.TAPESTRY_APP_PACKAGE_PARAM; 042 043 /** 044 * Turns off loading of default modules (as driven by JAR file Manifest entries). 045 * @deprecated Use {@link TapestryHttpInternalConstants#DISABLE_DEFAULT_MODULES_PARAM} instead 046 */ 047 public static final String DISABLE_DEFAULT_MODULES_PARAM = TapestryHttpInternalConstants.DISABLE_DEFAULT_MODULES_PARAM; 048 049 /** 050 * The name of the query parameter that stores the page activation context inside an action 051 * request. 052 */ 053 public static final String PAGE_CONTEXT_NAME = "t:ac"; 054 055 /** 056 * Name of event triggered by Grid sub-components when an in-place Grid is updated. 057 */ 058 public static final String GRID_INPLACE_UPDATE = "inplaceupdate"; 059 060 /** 061 * The name of a query parameter that stores the containing page (used in action links when the 062 * page containing the 063 * component is not the same as the page that was rendering). The active page (the page which 064 * initiated the render) 065 * is encoded into the URL, and the containing page is tacked on as this query parameter. 066 */ 067 public static final String CONTAINER_PAGE_NAME = "t:cp"; 068 069 public static final String MIXINS_SUBPACKAGE = "mixins"; 070 071 public static final String COMPONENTS_SUBPACKAGE = "components"; 072 073 public static final String PAGES_SUBPACKAGE = "pages"; 074 075 public static final String BASE_SUBPACKAGE = "base"; 076 077 /** 078 * Used in some Ajax scenarios to set the content type for the response early, when the Page 079 * instance (the authority 080 * on content types) is known. The value is of type {@link org.apache.tapestry5.http.ContentType}. 081 */ 082 public static final String CONTENT_TYPE_ATTRIBUTE_NAME = "content-type"; 083 084 /** 085 * @deprecated Use {@link TapestryHttpInternalConstants#CHARSET_CONTENT_TYPE_PARAMETER} instead 086 */ 087 public static final String CHARSET_CONTENT_TYPE_PARAMETER = TapestryHttpInternalConstants.CHARSET_CONTENT_TYPE_PARAMETER; 088 089 /** 090 * As above but to store the name of the page. Necessary for determining the correct 091 * {@link MarkupModel} for the response. 092 */ 093 public static final String PAGE_NAME_ATTRIBUTE_NAME = "page-name"; 094 095 /** 096 * Required MIME type for JSON responses. If this MIME type is not used, the client-side 097 * Prototype code will not 098 * recognize the response as JSON, and the Ajax.Response.responseJSON property will be null. 099 */ 100 public static final String JSON_MIME_TYPE = "application/json"; 101 102 /** 103 * Request attribute key; if non-null, then automatic GZIP compression of response stream is 104 * suppressed. This is 105 * useful when the code opening the response stream wants to explicitly control whether GZIP 106 * compression occurs or 107 * not. Alias to {@link TapestryHttpConstants#SUPPRESS_COMPRESSION}. 108 * 109 * @since 5.1.0.0 110 */ 111 public static final String SUPPRESS_COMPRESSION = TapestryHttpConstants.SUPPRESS_COMPRESSION; 112 113 /** 114 * Name of response header for content encoding. 115 * 116 * @since 5.1.0.0 117 * @deprecated Use {@link TapestryHttpInternalConstants#CONTENT_ENCODING_HEADER} instead 118 */ 119 public static final String CONTENT_ENCODING_HEADER = TapestryHttpInternalConstants.CONTENT_ENCODING_HEADER; 120 121 /** 122 * Response content encoding value indicating use of GZIP compression. 123 * 124 * @since 5.1.0.0 125 * @deprecated Use {@link TapestryHttpInternalConstants#GZIP_CONTENT_ENCODING} instead 126 */ 127 public static final String GZIP_CONTENT_ENCODING = TapestryHttpInternalConstants.GZIP_CONTENT_ENCODING; 128 129 /** 130 * Identifies the start of an expansion inside a template. 131 */ 132 public static final String EXPANSION_START = "${"; 133 134 /** 135 * Special prefix for parameters that are inherited from named parameters of their container. 136 */ 137 public static final String INHERIT_BINDING_PREFIX = "inherit:"; 138 139 public static final long TEN_YEARS = new TimeInterval("10y").milliseconds(); 140 141 /** 142 * @deprecated Use {@link CommonsUtils#EMPTY_STRING_ARRAY} instead 143 */ 144 public static final String[] EMPTY_STRING_ARRAY = CommonsUtils.EMPTY_STRING_ARRAY; 145 146 /** 147 * Name of the core {@link JavaScriptStack}, which supplies the basic JavaScript infrastructure 148 * on the client. 149 * 150 * @since 5.2.0 151 */ 152 public static final String CORE_STACK_NAME = "core"; 153 154 /** 155 * Virtual folder name for the core library. The core library is special as any component not present in another 156 * library (including the application library) is searched for inside core. 157 * 158 * @since 5.3 159 */ 160 public static final String CORE_LIBRARY = "core"; 161 162 /** 163 * The names of the standard controlled subpackages. 164 * 165 * @since 5.3 166 */ 167 public static final String[] SUBPACKAGES = 168 {PAGES_SUBPACKAGE, COMPONENTS_SUBPACKAGE, MIXINS_SUBPACKAGE, BASE_SUBPACKAGE}; 169 170 /** 171 * The element name for a submit input element used to cancel the form (rather than 172 * submit it normally). 173 * 174 * @since 5.3 175 */ 176 public static final String CANCEL_NAME = "cancel"; 177 178 /** 179 * Request attribute that can be set to bypass page activation. 180 * 181 * @see org.apache.tapestry5.internal.services.StreamPageContentResultProcessor 182 * @see org.apache.tapestry5.internal.services.PageRenderRequestHandlerImpl 183 * @since 5.4 184 */ 185 public static final String BYPASS_ACTIVATION = "tapestry.bypass-page-activation"; 186 187 /** 188 * Key inside the response that contains the partial page render keys that are used 189 * to update the client. 190 * 191 * @since 5.4 192 */ 193 public static final String PARTIAL_KEY = "_tapestry"; 194 195 /** 196 * Request attribute, set to true once the active page (as identified in the incoming 197 * component event or page render request) has been successfully loaded. This is very important 198 * to the {@link org.apache.tapestry5.corelib.pages.ExceptionReport} page, which can possibly 199 * fail (resulting in a servlet container 500 response) if the page can't be loaded (because 200 * if the page can't be loaded, then a link to the page can't be created). 201 * 202 * @since 5.4 203 */ 204 public static final String ACTIVE_PAGE_LOADED = "tapestry.active-page-loaded"; 205 206 /** 207 * Used to suppress the stylesheets from the 'core' stack; this is used on certain pages 208 * that want to work around application-specific overrides to the core stack stylesheets. 209 * 210 * @since 5.4 211 */ 212 public static final String SUPPRESS_CORE_STYLESHEETS = "tapestry.suppress-core-stylesheets"; 213 214 /** 215 * A bit of a hack that allows, in production mode, for a component event request to "unwind" when 216 * the component referenced in the URL does not exist. This is related to TAP5-1481. This situation 217 * can most likely occur when a web spider, such as Google, uses an old component event URI from 218 * a prior deployment, which no longer works in a new deployment, due to structural changes. Since 219 * changing the APIs that significantly is forbidden, a non-null value is added as an 220 * {@link org.apache.tapestry5.http.services.Request} attribute. 221 * 222 * @since 5.4 223 */ 224 public static final String REFERENCED_COMPONENT_NOT_FOUND = "tapestry.referenced-component-not-found"; 225 226 /** 227 * Name of request parameter that suppresses the logic that injects a random-ish namespace into allocated ids when rending partial page 228 * responses. This, of course, requires a lot of testing to ensure that there are no resulting name clashes, 229 * and should not be used inside Zones containing an {@link org.apache.tapestry5.corelib.components.AjaxFormLoop}. 230 * 231 * @since 5.4 232 */ 233 public static final String SUPPRESS_NAMESPACED_IDS = "t:suppress-namespaced-ids"; 234 235 /** 236 * @since 5.4 237 */ 238 public static final ContentType JAVASCRIPT_CONTENT_TYPE = new ContentType("text/javascript"); 239 240 /** 241 * Name of the {@linkplain ComponentModel} metadata key whiche stores the {@linkplain PublishEvent} 242 * data. 243 * @since 5.4.2 244 */ 245 public static final String PUBLISH_COMPONENT_EVENTS_META = "meta.publish-component-events"; 246 247 /** 248 * Name of the JSONObject key name which holds the name of the event to be published. 249 * 250 * @since 5.4.2 251 */ 252 public static final String PUBLISH_COMPONENT_EVENTS_URL_PROPERTY = "url"; 253 254 /** 255 * The prefix used to create the names of the events triggered for REST endpoint 256 * event handler methods. 257 * 258 * @since 5.8.0 259 */ 260 public static final String HTTP_METHOD_EVENT_PREFIX = "http"; 261 262 /** 263 * The name of the {@link ComponentModel} meta attribute which tells whether 264 * REST endpoint event handler methods are present 265 * 266 * @since 5.8.0 267 */ 268 public static final String REST_ENDPOINT_EVENT_HANDLER_METHOD_PRESENT = "restEndpointEventHandlerMethodsPresent"; 269 270 /** 271 * The name of the {@link ComponentModel} meta attribute which lists the 272 * REST endpoint event handler methods. 273 * 274 * @since 5.8.0 275 */ 276 public static final String REST_ENDPOINT_EVENT_HANDLER_METHODS = "restEndpointEventHandlerMethods"; 277 278 /** 279 * Constant for a true boolean value to be used in {@link ComponentModel} meta attributes. 280 */ 281 public static final String TRUE = "true"; 282 283 /** 284 * Constant for a false boolean value to be used in {@link ComponentModel} meta attributes. 285 */ 286 public static final String FALSE = "false"; 287 288 /** 289 * Annotation types for event handler method parameters which have injected values, not ones 290 * provided by the URL. 291 */ 292 public static Class<?>[] INJECTED_PARAMETERS = new Class<?>[]{ 293 RequestParameter.class, RequestBody.class 294 }; 295 296 /** 297 * 298 */ 299 public static final Set<String> SUPPORTED_HTTP_METHOD_EVENTS; 300 301 public static final Set<String> SUPPORTED_HTTP_METHOD_EVENT_HANDLER_METHOD_NAMES; 302 303 static 304 { 305 306 String[] httpEvents = new String[] 307 { 308 EventConstants.HTTP_GET, 309 EventConstants.HTTP_POST, 310 EventConstants.HTTP_PUT, 311 EventConstants.HTTP_DELETE, 312 EventConstants.HTTP_HEAD, 313 EventConstants.HTTP_PATCH 314 }; 315 316 SUPPORTED_HTTP_METHOD_EVENTS = Collections.unmodifiableSet( 317 Stream.of(httpEvents) 318 .map(String::toLowerCase) 319 .collect(Collectors.toSet())); 320 321 SUPPORTED_HTTP_METHOD_EVENT_HANDLER_METHOD_NAMES = Collections.unmodifiableSet( 322 Stream.of(httpEvents) 323 .map(s -> "on" + s.toLowerCase()) 324 .collect(Collectors.toSet())); 325 326 } 327 328}