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: */
017: package org.apache.wicket.request;
018:
019: import java.util.Iterator;
020: import java.util.Map;
021: import java.util.Map.Entry;
022:
023: import org.apache.wicket.IClusterable;
024: import org.apache.wicket.RequestListenerInterface;
025: import org.apache.wicket.markup.html.link.ILinkListener;
026: import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
027:
028: /**
029: * <p>
030: * Object that abstracts common request parameters. It consists of possible
031: * optional parameters that can be translated from e.g. servlet request
032: * parameters and serves of a strongly typed variant of these that is to be
033: * created by the {@link org.apache.wicket.request.IRequestCycleProcessor}'s
034: * {@link org.apache.wicket.request.IRequestCodingStrategy}.
035: * </p>
036: * <p>
037: * Though this object can be extended and hence more parameter options can be
038: * used, anything other than in this implementation must be supported by
039: * specific {@link org.apache.wicket.request.IRequestCycleProcessor}
040: * implementations and thus are not supported by default implementations.
041: * </p>
042: *
043: * @author Eelco Hillenius
044: */
045: public class RequestParameters implements IClusterable {
046: private static final long serialVersionUID = 1L;
047:
048: /** the full path to a component (might be just the page). */
049: private String componentPath;
050:
051: /** any name of the page map. */
052: private String pageMapName;
053:
054: /** any version number; 0 for no version. */
055: private int versionNumber;
056:
057: private boolean onlyProcessIfPathActive = false;
058:
059: /** any callable interface name (e.g. {@link ILinkListener}). */
060: private String interfaceName;
061:
062: /**
063: * in case this request points to a dispatched call to a behavior that is
064: * coupled to a component, this is the registration id of the behavior.
065: */
066: private String behaviorId;
067:
068: /** any id of a non-page target component. */
069: private String componentId;
070:
071: /** any bookmarkable page class. */
072: private String bookmarkablePageClass;
073:
074: /** free-to-use map of non-reserved parameters. */
075: private Map parameters;
076:
077: /** any resource key. */
078: private String resourceKey;
079:
080: /** the path info. */
081: private String path;
082:
083: /** depth of the page for relative URLs. */
084: private int urlDepth = -1;
085:
086: /**
087: * Construct.
088: */
089: public RequestParameters() {
090:
091: }
092:
093: /**
094: * Gets the component registration id of any behavior.
095: *
096: * @return behaviorId the id
097: */
098: public String getBehaviorId() {
099: return behaviorId;
100: }
101:
102: /**
103: * Gets any bookmarkable page class.
104: *
105: * @return any bookmarkable page class
106: */
107: public String getBookmarkablePageClass() {
108: return bookmarkablePageClass;
109: }
110:
111: /**
112: * Gets any id of a non-page target component.
113: *
114: * @return any id of a non-page target component
115: */
116: public String getComponentId() {
117: return componentId;
118: }
119:
120: /**
121: * Gets the full path to a component (might be just the page)..
122: *
123: * @return the full path to a component (might be just the page).
124: */
125: public String getComponentPath() {
126: return componentPath;
127: }
128:
129: /**
130: * @return The interface named by these request parameters
131: */
132: public RequestListenerInterface getInterface() {
133: return RequestListenerInterface.forName(getInterfaceName());
134: }
135:
136: /**
137: * Gets any callable interface name (e.g. {@link ILinkListener}).
138: *
139: * @return any callable interface name (e.g. {@link ILinkListener})
140: */
141: public String getInterfaceName() {
142: return interfaceName;
143: }
144:
145: /**
146: * Gets any name of the page map.
147: *
148: * @return any name of the page map
149: */
150: public String getPageMapName() {
151: return pageMapName;
152: }
153:
154: /**
155: * Gets free-to-use map of non-reserved parameters.
156: *
157: * @return free-to-use map of non-reserved parameters
158: */
159: public Map getParameters() {
160: return parameters;
161: }
162:
163: /**
164: * Gets path info.
165: *
166: * @return path info
167: */
168: public String getPath() {
169: return path;
170: }
171:
172: /**
173: * Gets any resource key.
174: *
175: * @return any resource key
176: */
177: public String getResourceKey() {
178: return resourceKey;
179: }
180:
181: /**
182: * Gets any version information string.
183: *
184: * @return any version information string
185: */
186: public int getVersionNumber() {
187: return versionNumber;
188: }
189:
190: /**
191: * Tells wicket whether this request should only be processed if the page +
192: * version specified are pointing to the last page the user accessed.
193: *
194: * @see WebRequestCodingStrategy#IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME
195: *
196: * @return the only-process-if-path-active flag
197: */
198: public boolean isOnlyProcessIfPathActive() {
199: return onlyProcessIfPathActive;
200: }
201:
202: /**
203: * Sets the component registration id of any behavior.
204: *
205: * @param behaviorId
206: * the id
207: */
208: public void setBehaviorId(String behaviorId) {
209: this .behaviorId = behaviorId;
210: }
211:
212: /**
213: * Sets any bookmarkable page class.
214: *
215: * @param bookmarkablePageClass
216: * any bookmarkable page class
217: */
218: public void setBookmarkablePageClass(String bookmarkablePageClass) {
219: this .bookmarkablePageClass = bookmarkablePageClass;
220: }
221:
222: /**
223: * Sets any id of a non-page target component.
224: *
225: * @param componentId
226: * any id of a non-page target component
227: */
228: public void setComponentId(String componentId) {
229: this .componentId = componentId;
230: }
231:
232: /**
233: * Sets the full path to a component (might be just the page)..
234: *
235: * @param componentPath
236: * the full path to a component (might be just the page).
237: */
238: public void setComponentPath(String componentPath) {
239: this .componentPath = componentPath;
240: }
241:
242: /**
243: * Sets any callable interface name (e.g. {@link ILinkListener}).
244: *
245: * @param interfaceName
246: * any callable interface name (e.g. {@link ILinkListener})
247: */
248: public void setInterfaceName(String interfaceName) {
249: this .interfaceName = interfaceName;
250: }
251:
252: /**
253: * Sets the only-process-if-path-active flag
254: *
255: * @param onlyProcessIfPathActive
256: *
257: * @see #isOnlyProcessIfPathActive()
258: */
259: public void setOnlyProcessIfPathActive(
260: boolean onlyProcessIfPathActive) {
261: this .onlyProcessIfPathActive = onlyProcessIfPathActive;
262: }
263:
264: /**
265: * Sets any name of the page map.
266: *
267: * @param pageMapName
268: * any name of the page map
269: */
270: public void setPageMapName(String pageMapName) {
271: // this should be done in coding strategies, but its here as a
272: // precaution
273: this .pageMapName = WebRequestCodingStrategy
274: .decodePageMapName(pageMapName);
275: }
276:
277: /**
278: * Sets free-to-use map of non-reserved parameters.
279: *
280: * @param parameters
281: * free-to-use map of non-reserved parameters
282: */
283: public void setParameters(Map parameters) {
284: this .parameters = parameters;
285: }
286:
287: /**
288: * Sets path info.
289: *
290: * @param pathInfo
291: * path info
292: */
293: public void setPath(String pathInfo) {
294: this .path = pathInfo;
295: }
296:
297: /**
298: * Sets any resource key.
299: *
300: * @param resourceKey
301: * any resource key
302: */
303: public void setResourceKey(String resourceKey) {
304: this .resourceKey = resourceKey;
305: }
306:
307: /**
308: * Sets any version information string.
309: *
310: * @param versionNumber
311: * any version information string
312: */
313: public void setVersionNumber(int versionNumber) {
314: this .versionNumber = versionNumber;
315: }
316:
317: /**
318: * Gets the depth for relative URLs. Used in AJAX requests.
319: *
320: * @return depth (number of slashes)
321: */
322: public int getUrlDepth() {
323: return urlDepth;
324: }
325:
326: /**
327: * Sets the depth for relative URLs. Used in AJAX requests.
328: *
329: * @param urlDepth
330: * Number of slashes deep the page is that an AJAX request is
331: * made from.
332: */
333: public void setUrlDepth(int urlDepth) {
334: this .urlDepth = urlDepth;
335: }
336:
337: /**
338: * @see java.lang.Object#toString()
339: */
340: public String toString() {
341: StringBuffer b = new StringBuffer("[RequestParameters ");
342: if (getComponentPath() != null) {
343: b.append(" componentPath=").append(getComponentPath());
344: b.append(" pageMapName=").append(getPageMapName());
345: b.append(" versionNumber=").append(getVersionNumber());
346: b.append(" interfaceName=").append(getInterfaceName());
347: b.append(" componentId=").append(getComponentId());
348: b.append(" behaviorId=").append(getBehaviorId());
349: b.append(" urlDepth=").append(getUrlDepth());
350: }
351: if (getBookmarkablePageClass() != null) {
352: b.append(" bookmarkablePageClass=").append(
353: getBookmarkablePageClass());
354: }
355: if (getParameters() != null) {
356: b.append(" parameters={");
357: for (Iterator i = getParameters().entrySet().iterator(); i
358: .hasNext();) {
359: Entry entry = (Entry) i.next();
360: Object value = entry.getValue();
361: b.append(entry.getKey()).append("=");
362: if (value != null && value instanceof Object[]) {
363: Object[] values = (Object[]) value;
364: if (values.length > 1) {
365: b.append("{");
366: for (int j = 0; j < values.length; j++) {
367: b.append(values[j]);
368: if (j < values.length) {
369: b.append(",");
370: }
371: }
372: b.append("}");
373: } else {
374: b.append((values.length == 1) ? values[0] : "");
375: }
376: } else {
377: b.append(value);
378: }
379: if (i.hasNext()) {
380: b.append(",");
381: }
382: }
383: b.append("}");
384: }
385: if (getResourceKey() != null) {
386: b.append(" resourceKey=").append(getResourceKey());
387: }
388: b.append(" onlyProcessIfPathActive=").append(
389: isOnlyProcessIfPathActive());
390:
391: b.append("]");
392: return b.toString();
393: }
394:
395: }
|