001: /*
002: * $Id: WebRequest.java 4194 2006-02-08 10:39:03 -0800 (Wed, 08 Feb 2006)
003: * jonathanlocke $ $Revision: 461858 $ $Date: 2006-02-08 10:39:03 -0800 (Wed, 08
004: * Feb 2006) $
005: *
006: * ==============================================================================
007: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
008: * use this file except in compliance with the License. You may obtain a copy of
009: * the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
015: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
016: * License for the specific language governing permissions and limitations under
017: * the License.
018: */
019: package wicket.protocol.http;
020:
021: import java.util.Locale;
022: import java.util.Map;
023:
024: import javax.servlet.http.Cookie;
025: import javax.servlet.http.HttpServletRequest;
026:
027: import wicket.Request;
028: import wicket.util.lang.Bytes;
029:
030: /**
031: * Subclass of Request for HTTP protocol requests which holds an underlying
032: * HttpServletRequest object. A variety of convenience methods are available
033: * that operate on the HttpServletRequest object. These methods do things such
034: * as providing access to parameters, cookies, URLs and path information.
035: *
036: * @author Jonathan Locke
037: */
038: public abstract class WebRequest extends Request {
039: /**
040: * Gets the application context path.
041: *
042: * @return application context path
043: */
044: public abstract String getContextPath();
045:
046: /**
047: * Get the requests' cookies
048: *
049: * @return Cookies
050: */
051: public Cookie[] getCookies() {
052: return getHttpServletRequest().getCookies();
053: }
054:
055: /**
056: * Gets the wrapped http servlet request object.
057: * <p>
058: * WARNING: it is usually a bad idea to depend on the http servlet request
059: * directly. Please use the classes and methods that are exposed by Wicket
060: * (such as {@link wicket.Session} instead. Send an email to the mailing
061: * list in case it is not clear how to do things or you think you miss
062: * functionality which causes you to depend on this directly.
063: * </p>
064: *
065: * @return the wrapped http serlvet request object.
066: */
067: public abstract HttpServletRequest getHttpServletRequest();
068:
069: /**
070: * Returns the preferred <code>Locale</code> that the client will accept
071: * content in, based on the Accept-Language header. If the client request
072: * doesn't provide an Accept-Language header, this method returns the
073: * default locale for the server.
074: *
075: * @return the preferred <code>Locale</code> for the client
076: */
077: public abstract Locale getLocale();
078:
079: /**
080: * Gets the request parameter with the given key.
081: *
082: * @param key
083: * Parameter name
084: * @return Parameter value
085: */
086: public abstract String getParameter(final String key);
087:
088: /**
089: * Gets the request parameters.
090: *
091: * @return Map of parameters
092: */
093: public abstract Map getParameterMap();
094:
095: /**
096: * Gets the request parameters with the given key.
097: *
098: * @param key
099: * Parameter name
100: * @return Parameter values
101: */
102: public abstract String[] getParameters(final String key);
103:
104: /**
105: * Gets the servlet path.
106: *
107: * @return Servlet path
108: */
109: public abstract String getServletPath();
110:
111: /**
112: * Retrieves the URL of this request for local use.
113: *
114: * @return The request URL for local use, which is the context path + the
115: * relative url
116: */
117: public String getURL() {
118: /*
119: * Servlet 2.3 specification : Context Path: The path prefix associated
120: * with the ServletContext that this servlet is a part of. If this
121: * context is the default context rooted at the base of the web server's
122: * URL namespace, this path will be an empty string. Otherwise, this
123: * path starts with a "/" character but does not end with a "/"
124: * character.
125: */
126: return getContextPath() + '/' + getRelativeURL();
127: }
128:
129: /**
130: * Create a runtime context type specific (e.g. Servlet or Portlet)
131: * MultipartWebRequest wrapper for handling multipart content uploads.
132: *
133: * @param maxSize
134: * the maximum size this request may be
135: * @return new WebRequest wrapper implementing MultipartWebRequest
136: */
137: public abstract WebRequest newMultipartWebRequest(Bytes maxSize);
138:
139: /**
140: * Is the request an ajax request?
141: *
142: * @return True if the ajax is an ajax request. False if it's not.
143: */
144: public abstract boolean isAjax();
145: }
|