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
-
request
-
-
response
-
-
site
-
-
State()
- Constructor.
-
composeArgList(String[], Validatable[])
- Utility for encoding arguments into name=value&name2=value2 format.
-
controller()
- Abstract controller method to be implemented by all subclasses
-
encodePageRef(Page, String[], Validatable[])
- Return a string encoded for use as the action parameter of a
form command.
-
encodeRedirectURL(String)
- Utility for applying state.getResponse().encodeRedirectURL to urls
session encoding into urols for browsers with disabled cookies
-
encodeURL(String)
- Utility for applying state.getResponse().encodeURL to urls to support
session encoding into urols for browsers with disabled cookies
-
forward(Page)
- Forward this request to the designated page
-
forward(String)
- Forward this request to the designated url
-
getAbsolutePath(Page, String[], Validatable[])
- Return the absolute path of this page including the context name.
-
getAbsolutePathRelativeToContext(String)
- Transform the argument string into an absolute url relative to the servlet context
-
getAttribute(String)
- Get a session attribute.value by calling getSession().getAttribute(attributeName)
-
getCookie(String)
- Get cookie value by calling request.getCookies().
-
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().
-
getNoun(Field)
- The "noun" is a reserved request parameter.
-
getParameter(String, Field)
- Get a request parameter.
-
getRelativePath(Page, String[], Validatable[])
- Return the absolute path of this page relative to the servlet context.
-
getRequest()
- Get the request object
-
getRequestDispatcher(String)
- Return a requestDispatcher generated by calling servlet.getServletContext().getRequestDispatcher(url)
-
getResponse()
- Get the response object
-
getSession()
- Get the session object by calling request.getSession(true)
-
getVerb(Field)
- The "verb" is a reserved request parameter that governs
which state is requested by the browser.
-
getWriter()
- Get a PrintWriter suitable for communicating with the client browser
by calling response.getWRiter().
-
htmlFontRed(String)
- Utility for highlighting text in red.
-
include(Page)
- Include the designated page within the current output stream.
-
include(String)
- Include the page at the designated context-relative path
within the current output stream.
-
initialize(Site, HttpServletRequest, HttpServletResponse)
- initialization involves a separate call.
-
redirect(Page)
- Redirect the request to the designated page
-
redirect(String)
- Redirect the request to the designated page
-
send(String)
- Send the argument string to the client as html text by calling getWriter().println(s).
-
sendPage(String)
- Send the argument string to the client as html text.
-
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.
-
sendPageOpen()
- Emit site-specific html boilerplate that should appear on every web page.
-
setAttribute(String, Object)
- Set a session attribute to key/value
-
setCookie(String, String)
- Set a cookie to the designated name/value
site
protected Site site
request
protected HttpServletRequest request
response
protected HttpServletResponse response
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.
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
controller
public abstract void controller() throws Exception
- Abstract controller method to be implemented by all subclasses
encodePageRef
public String encodePageRef(Page page,
String argNames[],
Validatable argValues[])
- Return a string encoded for use as the action parameter of a
form command.
encodeRedirectURL
public String encodeRedirectURL(String url)
- Utility for applying state.getResponse().encodeRedirectURL to urls
session encoding into urols for browsers with disabled cookies
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
forward
public void forward(Page toPage) throws ServletException, IOException
- Forward this request to the designated page
- Parameters:
- Page - toPage: the designated page.
forward
public void forward(String relPath) throws ServletException, IOException
- Forward this request to the designated url
- Parameters:
- String - relPath: the designated page.
getAbsolutePath
public String getAbsolutePath(Page page,
String argNames[],
Validatable argValues[])
- Return the absolute path of this page including the context name.
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.
getAttribute
public Object getAttribute(String attributeName) throws IOException
- Get a session attribute.value by calling getSession().getAttribute(attributeName)
- Parameters:
- String - attributeName
- Returns:
- Object
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.
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
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
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.
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
getRequest
public HttpServletRequest getRequest()
- Get the request object
- Returns:
- javax.servlet.http.HttpServletRequest
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
getResponse
public HttpServletResponse getResponse()
- Get the response object
- Returns:
- javax.servlet.http.HttpServletResponse
getSession
public HttpSession getSession()
- Get the session object by calling request.getSession(true)
- Returns:
- javax.servlet.http.HttpSession
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
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
htmlFontRed
public static String htmlFontRed(String s)
- Utility for highlighting text in red.
include
public void include(Page toPage) throws ServletException, IOException
- Include the designated page within the current output stream.
- Parameters:
- Page - toPage: the designated page.
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..
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
redirect
public void redirect(Page toPage) throws ServletException, IOException
- Redirect the request to the designated page
- Parameters:
- Page - toPage the designated page
redirect
public void redirect(String absPath) throws ServletException, IOException
- Redirect the request to the designated page
- Parameters:
- String - absPath: context-relative path.
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.
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.
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
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
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
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