org.kohsuke.stapler
Interface StaplerRequest

All Superinterfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public interface StaplerRequest
extends javax.servlet.http.HttpServletRequest

Defines additional parameters/operations made available by Stapler.

Author:
Kohsuke Kawaguchi
See Also:
Stapler.getCurrentRequest()

Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Method Summary
<T> T
bindParameters(java.lang.Class<T> type, java.lang.String prefix)
          Instanciates a new object by injecting constructor parameters from the form parameters.
<T> T
bindParameters(java.lang.Class<T> type, java.lang.String prefix, int index)
          Works like bindParameters(Class, String) but uses n-th value of all the parameters.
 void bindParameters(java.lang.Object bean)
          Binds form parameters to a bean by using introspection.
 void bindParameters(java.lang.Object bean, java.lang.String prefix)
          Binds form parameters to a bean by using introspection.
<T> java.util.List<T>
bindParametersToList(java.lang.Class<T> type, java.lang.String prefix)
          Binds collection form parameters to beans by using introspection or constructor parameters injection.
 boolean checkIfModified(java.util.Calendar timestampOfResource, StaplerResponse rsp)
           
 boolean checkIfModified(java.util.Date timestampOfResource, StaplerResponse rsp)
           
 boolean checkIfModified(long timestampOfResource, StaplerResponse rsp)
          Checks "If-Modified-Since" header and returns false if the resource needs to be served.
 boolean checkIfModified(long timestampOfResource, StaplerResponse rsp, long expiration)
           
 java.util.List<Ancestor> getAncestors()
          Returns a list of ancestor objects that lead to the "it" object.
 java.lang.String getOriginalRequestURI()
          Gets the request URI of the original request, so that you can access the value even from JSP.
 java.lang.String getReferer()
          Gets the referer header (like "http://foobar.com/zot") or null.
 java.lang.String getRestOfPath()
          Returns the additional URL portion that wasn't used by the stapler, excluding the query string.
 java.lang.String getRootPath()
          Gets the part of the request URL from protocol up to the context path.
 javax.servlet.ServletContext getServletContext()
          Returns the ServletContext object given to the stapler dispatcher servlet.
 javax.servlet.RequestDispatcher getView(java.lang.Object it, java.lang.String viewName)
          Gets the RequestDispatcher that represents a specific view for the given object.
 
Methods inherited from interface javax.servlet.http.HttpServletRequest
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Method Detail

getRestOfPath

java.lang.String getRestOfPath()
Returns the additional URL portion that wasn't used by the stapler, excluding the query string.

For example, if the requested URL is "foo/bar/zot/abc?def=ghi" and "foo/bar" portion matched bar.jsp, this method returns "/zot/abc".

Returns:
can be empty string, but never null.

getServletContext

javax.servlet.ServletContext getServletContext()
Returns the ServletContext object given to the stapler dispatcher servlet.


getView

javax.servlet.RequestDispatcher getView(java.lang.Object it,
                                        java.lang.String viewName)
                                        throws java.io.IOException
Gets the RequestDispatcher that represents a specific view for the given object. This support both JSP and Jelly.

Parameters:
viewName - If this name is relative name like "foo.jsp" or "bar/zot.jelly", then the corresponding "side file" is searched by this name.

For Jelly, this also accepts absolute path name that starts with '/', such as "/foo/bar/zot.jelly". In this case, it.getClass().getClassLoader() is searched for this script.

Returns:
null if neither JSP nor Jelly is not found by the given name.
Throws:
java.io.IOException

getRootPath

java.lang.String getRootPath()
Gets the part of the request URL from protocol up to the context path. So typically it's something like http://foobar:8080/something


getReferer

java.lang.String getReferer()
Gets the referer header (like "http://foobar.com/zot") or null. This is just a convenience method.


getAncestors

java.util.List<Ancestor> getAncestors()
Returns a list of ancestor objects that lead to the "it" object. The returned list contains Ancestor objects sorted in the order from root to the "it" object.

For example, if the URL was "foo/bar/zot" and the "it" object was determined as root.getFoo().getBar("zot"), then this list will contain the following 3 objects in this order:

  1. the root object
  2. root.getFoo() object
  3. root.getFoo().getBar("zot") object (the "it" object)

Returns:
list of Ancestors. Can be empty, but always non-null.

getOriginalRequestURI

java.lang.String getOriginalRequestURI()
Gets the request URI of the original request, so that you can access the value even from JSP.


checkIfModified

boolean checkIfModified(long timestampOfResource,
                        StaplerResponse rsp)
Checks "If-Modified-Since" header and returns false if the resource needs to be served.

This method can behave in three ways.

  1. If timestampOfResource is 0 or negative, this method just returns false.
  2. If "If-Modified-Since" header is sent and if it's bigger than timestampOfResource, then this method sets HttpServletResponse.SC_NOT_MODIFIED as the response code and returns true.
  3. Otherwise, "Last-Modified" header is added with timestampOfResource value, and this method returns false.

This method sends out the "Expires" header to force browser to re-validate all the time.

Parameters:
timestampOfResource - The time stamp of the resource.
rsp - This object is updated accordingly to simplify processing.
Returns:
false to indicate that the caller has to serve the actual resource. true to indicate that the caller should just quit processing right there (and send back HttpServletResponse.SC_NOT_MODIFIED.

checkIfModified

boolean checkIfModified(java.util.Date timestampOfResource,
                        StaplerResponse rsp)
See Also:
checkIfModified(long, StaplerResponse)

checkIfModified

boolean checkIfModified(java.util.Calendar timestampOfResource,
                        StaplerResponse rsp)
See Also:
checkIfModified(long, StaplerResponse)

checkIfModified

boolean checkIfModified(long timestampOfResource,
                        StaplerResponse rsp,
                        long expiration)
Parameters:
expiration - The number of milliseconds until the resource will "expire". Until it expires the browser will be allowed to cache it and serve it without checking back with the server. After it expires, the client will send conditional GET to check if the resource is actually modified or not. If 0, it will immediately expire.
See Also:
checkIfModified(long, StaplerResponse)

bindParameters

void bindParameters(java.lang.Object bean)
Binds form parameters to a bean by using introspection. For example, if there's a parameter called 'foo' that has value 'abc', then bean.setFoo('abc') will be invoked. This will be repeated for all parameters. Parameters that do not have corresponding setters will be simply ignored.

Values are converted into the right type. See ConvertUtils.convert(String, Class).

Parameters:
bean - The object which will be filled out.
See Also:
BeanUtils.setProperty(Object, String, Object)

bindParameters

void bindParameters(java.lang.Object bean,
                    java.lang.String prefix)
Binds form parameters to a bean by using introspection. This method works like bindParameters(Object), but it performs a pre-processing on property names. Namely, only property names that start with the given prefix will be used for binding, and only the portion of the property name after the prefix is used. So for example, if the prefix is "foo.", then property name "foo.bar" with value "zot" will invoke bean.setBar("zot").


bindParametersToList

<T> java.util.List<T> bindParametersToList(java.lang.Class<T> type,
                                           java.lang.String prefix)
Binds collection form parameters to beans by using introspection or constructor parameters injection.

This method works like bindParameters(Object,String) and bindParameters(Class, String), but it assumes that form parameters have multiple-values, and use individual values to fill in multiple beans.

For example, if getParameterValues("foo")=={"abc","def"} and getParameterValues("bar")=={"5","3"}, then this method will return two objects (the first with "abc" and "5", the second with "def" and "3".)

Parameters:
type - Type of the bean to be created. This class must have the default no-arg constructor.
prefix - See bindParameters(Object, String) for details.
Returns:
Can be empty but never null.

bindParameters

<T> T bindParameters(java.lang.Class<T> type,
                     java.lang.String prefix)
Instanciates a new object by injecting constructor parameters from the form parameters.

The given class must have a constructor annotated with '@stapler-constructor', and must be processed by the maven-stapler-plugin, so that the parameter names of the constructor is available at runtime.

The prefix is used to control the form parameter name. For example, if the prefix is "foo." and if the constructor is define as Foo(String a, String b), then the constructor will be invoked as new Foo(getParameter("foo.a"),getParameter("foo.b")).


bindParameters

<T> T bindParameters(java.lang.Class<T> type,
                     java.lang.String prefix,
                     int index)
Works like bindParameters(Class, String) but uses n-th value of all the parameters.

This is useful for creating multiple instances from repeated form fields.



Copyright © 2007. All Rights Reserved.