All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sdi.wap.State

java.lang.Object
   |
   +----com.sdi.wap.State

public abstract class State
extends Object
implements View
Concrete implementation of the View interface for dynamic servlet-based pages. Each instance encapsulates the servlet execution state via its servlet, request, and response variables, and publishes a controller() method that manages the client-server interaction within that state. Typically each concrete class will support controller operations with private view() methods which encapsulate the html code outside the controller's main flow of execution. Typically these view() methods are constructed with the aid of the MLS (multi-line string) preprocessor as documented in "Web Applications as Java Servlets" by Brad Cox.

See Also:
View

Variable Index

 o request
 o response
 o site

Constructor Index

 o State()
Constructor.

Method Index

 o composeArgList(String[], Validatable[])
Utility for encoding arguments into name=value&name2=value2 format.
 o controller()
Abstract controller method to be implemented by all subclasses
 o encodePageRef(Page, String[], Validatable[])
Return a string encoded for use as the action parameter of a form command.
 o encodeRedirectURL(String)
Utility for applying state.getResponse().encodeRedirectURL to urls session encoding into urols for browsers with disabled cookies
 o encodeURL(String)
Utility for applying state.getResponse().encodeURL to urls to support session encoding into urols for browsers with disabled cookies
 o forward(Page)
Forward this request to the designated page
 o forward(String)
Forward this request to the designated url
 o getAbsolutePath(Page, String[], Validatable[])
Return the absolute path of this page including the context name.
 o getAbsolutePathRelativeToContext(String)
Transform the argument string into an absolute url relative to the servlet context
 o getAttribute(String)
Get a session attribute.value by calling getSession().getAttribute(attributeName)
 o getCookie(String)
Get cookie value by calling request.getCookies().
 o getField(String, Field)
Get a field parameter by calling getParameter(key, defaultValue), which will return request.getParameter(key) unless that returns null or "", in which case it returns defaultValue.toString().
 o getNoun(Field)
The "noun" is a reserved request parameter.
 o getParameter(String, Field)
Get a request parameter.
 o getRelativePath(Page, String[], Validatable[])
Return the absolute path of this page relative to the servlet context.
 o getRequest()
Get the request object
 o getRequestDispatcher(String)
Return a requestDispatcher generated by calling servlet.getServletContext().getRequestDispatcher(url)
 o getResponse()
Get the response object
 o getSession()
Get the session object by calling request.getSession(true)
 o getVerb(Field)
The "verb" is a reserved request parameter that governs which state is requested by the browser.
 o getWriter()
Get a PrintWriter suitable for communicating with the client browser by calling response.getWRiter().
 o htmlFontRed(String)
Utility for highlighting text in red.
 o include(Page)
Include the designated page within the current output stream.
 o include(String)
Include the page at the designated context-relative path within the current output stream.
 o initialize(Site, HttpServletRequest, HttpServletResponse)
initialization involves a separate call.
 o redirect(Page)
Redirect the request to the designated page
 o redirect(String)
Redirect the request to the designated page
 o send(String)
Send the argument string to the client as html text by calling getWriter().println(s).
 o sendPage(String)
Send the argument string to the client as html text.
 o sendPageClose()
Emit site-specific html boilerplate that should appear as the closing text of every web page by calling Site.htmlPageClose() As a bare minimum, this page should send </body> and <html> commands but can be as elaborate as need be.
 o sendPageOpen()
Emit site-specific html boilerplate that should appear on every web page.
 o setAttribute(String, Object)
Set a session attribute to key/value
 o setCookie(String, String)
Set a cookie to the designated name/value

Variables

 o site
 protected Site site
 o request
 protected HttpServletRequest request
 o response
 protected HttpServletResponse response

Constructors

 o State
 public State()
Constructor. Beware: instances created here are not usable without first calling initialze(). This is a hack to avoid having to override the all-args constructor in every subclass.

Methods

 o composeArgList
 public static String composeArgList(String argNames[],
                                     Validatable argValues[])
Utility for encoding arguments into name=value&name2=value2 format. Returns null if argNames or argValues is null. CAUTION: WILL TOSS THROWABLES if lists aren't the same length.

Parameters:
String[] - argNames the argument names
Validatable[] - argValues: the argument values
Returns:
String
 o controller
 public abstract void controller() throws Exception
Abstract controller method to be implemented by all subclasses

 o encodePageRef
 public String encodePageRef(Page page,
                             String argNames[],
                             Validatable argValues[])
Return a string encoded for use as the action parameter of a form command.

 o encodeRedirectURL
 public String encodeRedirectURL(String url)
Utility for applying state.getResponse().encodeRedirectURL to urls session encoding into urols for browsers with disabled cookies

 o encodeURL
 public String encodeURL(String url)
Utility for applying state.getResponse().encodeURL to urls to support session encoding into urols for browsers with disabled cookies

 o forward
 public void forward(Page toPage) throws ServletException, IOException
Forward this request to the designated page

Parameters:
Page - toPage: the designated page.
 o forward
 public void forward(String relPath) throws ServletException, IOException
Forward this request to the designated url

Parameters:
String - relPath: the designated page.
 o getAbsolutePath
 public String getAbsolutePath(Page page,
                               String argNames[],
                               Validatable argValues[])
Return the absolute path of this page including the context name.

 o getAbsolutePathRelativeToContext
 private final String getAbsolutePathRelativeToContext(String relativeUrlPath)
Transform the argument string into an absolute url relative to the servlet context

Parameters:
String - relativeUrlPath
Returns:
argument minus servlet context prefix.

fixme: not sure this is really needed now.

 o getAttribute
 public Object getAttribute(String attributeName) throws IOException
Get a session attribute.value by calling getSession().getAttribute(attributeName)

Parameters:
String - attributeName
Returns:
Object
 o getCookie
 public String getCookie(String cookieName)
Get cookie value by calling request.getCookies().

Parameters:
String - cookieName
Returns:
the requested cookie or null if none found by that name.
 o getField
 public Field getField(String key,
                       Field defaultValue) throws Exception
Get a field parameter by calling getParameter(key, defaultValue), which will return request.getParameter(key) unless that returns null or "", in which case it returns defaultValue.toString(). This method generates a new instance of defaultValue's class initialized with the resulting string.

Parameters:
String - key the request parameter name
Field - defaultValue the value to be assigned if request.getParameter(key) returns null or "".
Returns:
Field
 o getNoun
 public Field getNoun(Field defaultValue) throws Exception
The "noun" is a reserved request parameter. Some states provide controllers that inspect the noun to determine which of multiple sub-controller's is requested. This convenience method is to reduce the number of places that need to know the name of this reserved parameter.

Parameters:
Field - defaultValue
Returns:
Field
 o getParameter
 public String getParameter(String key,
                            Field defaultValue) throws IOException
Get a request parameter. If null, return the defaultValue as a string.

Parameters:
String - key: the parameter desired
Field - defaultValue the default value desired if the desired parameter is null or "".
Returns:
String the requested parameter.
Throws: IOException
if request.getParameter(key) fails.
 o getRelativePath
 public String getRelativePath(Page page,
                               String argNames[],
                               Validatable argValues[])
Return the absolute path of this page relative to the servlet context. with the arguments provided.

Parameters:
String[] - argNames: The argument names
Field[] - argValues: The argument values
 o getRequest
 public HttpServletRequest getRequest()
Get the request object

Returns:
javax.servlet.http.HttpServletRequest
 o getRequestDispatcher
 public RequestDispatcher getRequestDispatcher(String url)
Return a requestDispatcher generated by calling servlet.getServletContext().getRequestDispatcher(url)

Parameters:
String - url relative to the servlet context
Returns:
RequestDispatcher
 o getResponse
 public HttpServletResponse getResponse()
Get the response object

Returns:
javax.servlet.http.HttpServletResponse
 o getSession
 public HttpSession getSession()
Get the session object by calling request.getSession(true)

Returns:
javax.servlet.http.HttpSession
 o getVerb
 public Field getVerb(Field defaultValue) throws Exception
The "verb" is a reserved request parameter that governs which state is requested by the browser. This convenience method is provided to minimize the number of places that need to know the name of that reserved parameter.

Parameters:
Field - defaultValue
Returns:
Field
 o getWriter
 public PrintWriter getWriter() throws IOException
Get a PrintWriter suitable for communicating with the client browser by calling response.getWRiter().

Returns:
PrintWriter
Throws: IOException
if response.getWriter() fails
 o htmlFontRed
 public static String htmlFontRed(String s)
Utility for highlighting text in red.

 o include
 public void include(Page toPage) throws ServletException, IOException
Include the designated page within the current output stream.

Parameters:
Page - toPage: the designated page.
 o include
 public void include(String relPath) throws ServletException, IOException
Include the page at the designated context-relative path within the current output stream.

Parameters:
String - relPath: the context-relative path to be included..
 o initialize
 protected final void initialize(Site site,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
initialization involves a separate call. This is so initialization can be inherited, so that subclasses need only implement the noarg constroctor.

Parameters:
Site - site: the site that this state is a part of.
HttpServlet - servlet: the servlet that is handling this request
HttpServletRequest - request: the servlet request object
HttpServletResponse - response: the servlet response object
 o redirect
 public void redirect(Page toPage) throws ServletException, IOException
Redirect the request to the designated page

Parameters:
Page - toPage the designated page
 o redirect
 public void redirect(String absPath) throws ServletException, IOException
Redirect the request to the designated page

Parameters:
String - absPath: context-relative path.
 o send
 public void send(String s) throws IOException
Send the argument string to the client as html text by calling getWriter().println(s). Normally sendPageOpen() should be called before this method, and sendPageClose() should be called after, so that site-specific leading/trailing text will be sent.

Parameters:
String - s the html text to be sent.
 o sendPage
 public void sendPage(String s) throws Exception
Send the argument string to the client as html text. This method calls calls sendPageOpen() before, and sendPageClose() after, the requested text so that site-specific leading/trailing text will be sent.

Parameters:
String - s the html text to be sent.
 o sendPageClose
 public void sendPageClose() throws Exception
Emit site-specific html boilerplate that should appear as the closing text of every web page by calling Site.htmlPageClose() As a bare minimum, this page should send </body> and <html> commands but can be as elaborate as need be.

See Also:
sendPageOpen, Site
 o sendPageOpen
 public void sendPageOpen() throws Exception
Emit site-specific html boilerplate that should appear on every web page. As a bare minimum, this page should send html, title, and body commands, but can be as elaborate as need be.

See Also:
sendPageClose
 o setAttribute
 public void setAttribute(String key,
                          Object value)
Set a session attribute to key/value

Parameters:
String - key: the attribute name
Object - value: the attribute value
 o setCookie
 public void setCookie(String cookieName,
                       String cookieValue)
Set a cookie to the designated name/value

Parameters:
String - cookieName: the name
String - cookieValue: the value

All Packages  Class Hierarchy  This Package  Previous  Next  Index