com.aoindustries.website.framework
Class WebSiteRequest

java.lang.Object
  extended by javax.servlet.ServletRequestWrapper
      extended by javax.servlet.http.HttpServletRequestWrapper
          extended by com.aoindustries.website.framework.WebSiteRequest
All Implemented Interfaces:
com.oreilly.servlet.multipart.FileRenamePolicy, javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class WebSiteRequest
extends javax.servlet.http.HttpServletRequestWrapper
implements com.oreilly.servlet.multipart.FileRenamePolicy

A WebSiteSettings contains all the values that a user may customize while they view the web site.

Author:
AO Industries, Inc.

Field Summary
protected  WebPage sourcePage
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
WebSiteRequest(WebPage sourcePage, javax.servlet.http.HttpServletRequest req)
           
 
Method Summary
protected static boolean appendParams(java.lang.StringBuilder SB, java.lang.Object optParam, java.util.List<java.lang.String> finishedParams, boolean alreadyAppended)
          Appends the parameters to a URL.
protected  boolean appendSettings(java.util.List<java.lang.String> finishedParams, boolean alreadyAppended, java.lang.StringBuilder SB)
           
 java.lang.String getParameter(java.lang.String name)
           
 java.util.Enumeration getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String name)
           
 java.util.Random getRandom()
          Gets the random number generator used for this request.
static UploadedFile getUploadedFile(WebSiteUser owner, long id, javax.servlet.ServletContext context, LoggerAccessor loggerAccessor)
          Gets a file that was uploaded given its ID.
 java.util.List<UploadedFile> getUploadedFiles()
           
 java.lang.String getURL(java.lang.Class<? extends WebPage> clazz)
           
 java.lang.String getURL(java.lang.Class<? extends WebPage> clazz, java.lang.Object param)
          Gets the absolute URL to a web page.
 java.lang.String getURL(java.lang.String classAndParams)
          Gets a relative URL from a String containing a classname and optional parameters.
 java.lang.String getURL(java.lang.String url, boolean useEncryption, java.lang.Object optParam)
          Gets the URL String with the given parameters embedded, keeping the current settings.
 java.lang.String getURL(java.lang.String url, boolean useEncryption, java.lang.Object optParam, boolean keepSettings)
          Gets the absolute URL String, optionally with the settings embedded.
 java.lang.String getURL(java.lang.String classname, java.lang.String params)
          Gets a relative URL given its classname and optional parameters.
 java.lang.String getURL(WebPage page)
          Gets the absolute URL to a web page.
 java.lang.String getURL(WebPage page, boolean useEncryption, java.lang.Object optParam)
          Gets the absolute URL to a web page.
 java.lang.String getURL(WebPage page, java.lang.Object optParam)
          Gets the absolute URL to a web page.
 WebSiteUser getWebSiteUser(javax.servlet.http.HttpServletResponse resp)
          Gets the person who is logged in or null if no login is performed for this request.
 boolean isBlackBerry()
          Determines if the request is for a BlackBerry browser
 boolean isLinux()
          Determines if the request is for a Linux browser
 boolean isLoggedIn()
          Determines if the user is currently logged in.
 boolean isLynx()
          Determines if the request is for a Lynx browser
 boolean isSecure()
           
 void logout(javax.servlet.http.HttpServletResponse resp)
          Logs out the current user or does nothing if not logged in.
 void printFormFields(com.aoindustries.io.ChainWriter out, int indent)
          Prints the hidden variables that contain all of the current settings.
protected static void printHiddenField(com.aoindustries.io.ChainWriter out, int indent, java.lang.String name, java.lang.String value)
          Prints the hidden variables that contain all of the current settings.
 java.io.File rename(java.io.File file)
           
 
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
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 class javax.servlet.ServletRequestWrapper
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameterMap, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, removeAttribute, setAttribute, setCharacterEncoding, setRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameterMap, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, removeAttribute, setAttribute, setCharacterEncoding
 

Field Detail

sourcePage

protected final WebPage sourcePage
Constructor Detail

WebSiteRequest

public WebSiteRequest(WebPage sourcePage,
                      javax.servlet.http.HttpServletRequest req)
               throws java.io.IOException,
                      java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException
Method Detail

getRandom

public java.util.Random getRandom()
                           throws java.io.IOException
Gets the random number generator used for this request.

Throws:
java.io.IOException

appendParams

protected static boolean appendParams(java.lang.StringBuilder SB,
                                      java.lang.Object optParam,
                                      java.util.List<java.lang.String> finishedParams,
                                      boolean alreadyAppended)
Appends the parameters to a URL. Parameters should already be URL encoded and have & as separator.


getURL

public java.lang.String getURL(java.lang.String classAndParams)
                        throws java.io.IOException,
                               java.sql.SQLException
Gets a relative URL from a String containing a classname and optional parameters. Parameters should already be URL encoded and have & as separator.

Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(java.lang.String classname,
                               java.lang.String params)
                        throws java.io.IOException,
                               java.sql.SQLException
Gets a relative URL given its classname and optional parameters. Parameters should already be URL encoded and have & as separator.

Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(java.lang.String url,
                               boolean useEncryption,
                               java.lang.Object optParam,
                               boolean keepSettings)
                        throws java.io.IOException
Gets the absolute URL String, optionally with the settings embedded. (&amp; instead of standalone & as parameter separator) Parameters should already be URL encoded and have & as separator.

Throws:
java.io.IOException

appendSettings

protected boolean appendSettings(java.util.List<java.lang.String> finishedParams,
                                 boolean alreadyAppended,
                                 java.lang.StringBuilder SB)

getParameter

public java.lang.String getParameter(java.lang.String name)
Specified by:
getParameter in interface javax.servlet.ServletRequest
Overrides:
getParameter in class javax.servlet.ServletRequestWrapper

getParameterNames

public java.util.Enumeration getParameterNames()
Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Overrides:
getParameterNames in class javax.servlet.ServletRequestWrapper

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Overrides:
getParameterValues in class javax.servlet.ServletRequestWrapper

getURL

public java.lang.String getURL(WebPage page)
                        throws java.io.IOException,
                               java.sql.SQLException
Gets the absolute URL to a web page.

Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(WebPage page,
                               java.lang.Object optParam)
                        throws java.io.IOException,
                               java.sql.SQLException
Gets the absolute URL to a web page. Parameters should already be URL encoded and have & as separator.

Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(WebPage page,
                               boolean useEncryption,
                               java.lang.Object optParam)
                        throws java.io.IOException,
                               java.sql.SQLException
Gets the absolute URL to a web page. Parameters should already be URL encoded and have & as separator.

Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(java.lang.Class<? extends WebPage> clazz,
                               java.lang.Object param)
                        throws java.io.IOException,
                               java.sql.SQLException
Gets the absolute URL to a web page. Parameters should already be URL encoded and have & as separator.

Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(java.lang.Class<? extends WebPage> clazz)
                        throws java.io.IOException,
                               java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

getURL

public java.lang.String getURL(java.lang.String url,
                               boolean useEncryption,
                               java.lang.Object optParam)
                        throws java.io.IOException
Gets the URL String with the given parameters embedded, keeping the current settings.

Parameters:
url - the URL from the top of the webapp, without any beginning slash
useEncryption - if true the link refers to an page that should be served over encryption
optParam - any number of additional parameters. This parameter can accept several types of objects. The following is a list of supported objects and a brief description of its behavior. Parameters should already be URL encoded and have & as separator.
  • String - appended to the end of the parameters, assumed to be in the format name=value
  • String[] - name and value pairs, the first element of each pair is the name, the second is the value
Throws:
java.lang.IllegalArgumentException - if optParam is not a supported object
java.io.IOException

isLynx

public boolean isLynx()
Determines if the request is for a Lynx browser


isBlackBerry

public boolean isBlackBerry()
Determines if the request is for a BlackBerry browser


isLinux

public boolean isLinux()
Determines if the request is for a Linux browser


isSecure

public boolean isSecure()
Specified by:
isSecure in interface javax.servlet.ServletRequest
Overrides:
isSecure in class javax.servlet.ServletRequestWrapper

printFormFields

public void printFormFields(com.aoindustries.io.ChainWriter out,
                            int indent)
                     throws java.io.IOException
Prints the hidden variables that contain all of the current settings.

Throws:
java.io.IOException

printHiddenField

protected static void printHiddenField(com.aoindustries.io.ChainWriter out,
                                       int indent,
                                       java.lang.String name,
                                       java.lang.String value)
                                throws java.io.IOException
Prints the hidden variables that contain all of the current settings.

Throws:
java.io.IOException

getUploadedFiles

public java.util.List<UploadedFile> getUploadedFiles()

getUploadedFile

public static UploadedFile getUploadedFile(WebSiteUser owner,
                                           long id,
                                           javax.servlet.ServletContext context,
                                           LoggerAccessor loggerAccessor)
                                    throws java.lang.SecurityException
Gets a file that was uploaded given its ID. The authentication credentials for this request must match those of the provided ID.

Returns:
the owner of the object
Throws:
java.lang.SecurityException - if the ID is not assigned to the person logged in

rename

public java.io.File rename(java.io.File file)
Specified by:
rename in interface com.oreilly.servlet.multipart.FileRenamePolicy

getWebSiteUser

public WebSiteUser getWebSiteUser(javax.servlet.http.HttpServletResponse resp)
                           throws java.io.IOException,
                                  java.sql.SQLException,
                                  com.aoindustries.security.LoginException
Gets the person who is logged in or null if no login is performed for this request.

Throws:
com.aoindustries.security.LoginException - if an invalid login attempt is made or the user credentials are not found
java.io.IOException
java.sql.SQLException

isLoggedIn

public boolean isLoggedIn()
                   throws java.io.IOException,
                          java.sql.SQLException
Determines if the user is currently logged in.

Throws:
java.io.IOException
java.sql.SQLException

logout

public void logout(javax.servlet.http.HttpServletResponse resp)
Logs out the current user or does nothing if not logged in.