com.waveset.ui.util
Class PageProcessor

java.lang.Object
  extended bycom.waveset.ui.util.PageProcessor
Direct Known Subclasses:
GenericEditForm

public abstract class PageProcessor
extends java.lang.Object

The base class for objects that perform HttpRequest processing and generate HTML responses. Instances of these classes are typically instantiated by a JSP, and then allowed to process the request. The JSP typically does a small amount of customization like setting titles and navigation options.

The end result is not unlike writing a servlet, but using JSP launchers means you don't have to register servlets, and allow some amount of customiztion.

You should assume that you are already within an page generated by a higher level processor, usually a JSP. So "page" processor may be a bit of a misnomer, since the generated HTML is destined for a compartment within the page, it isn't the entire page.


Field Summary
protected  java.lang.String _command
          The value of the "command" parameter extracted from the post data or URL query string.
protected  boolean _trace
          Debug flag
protected static Trace trace
           
 
Constructor Summary
PageProcessor()
           
 
Method Summary
 void addComment(java.lang.String msg)
          Add a comment to the list.
 void addComments(java.util.List msgs)
          Add a list of comments.
 void addError(java.lang.Object msg)
          Add an error message to the list.
 void addErrors(java.util.List msgs)
          Add a list of errors.
 void addMessage(java.lang.Object msg)
          Add an informational message to the list.
 void addMessages(java.util.List msgs)
          Add a list of messages.
 void clearErrors()
          Clear the error message list.
 void clearMessages()
          Clear the informational message list.
 com.waveset.ui.util.html.HtmlPage generate()
          Generate the page as an HtmlPage object.
 java.lang.String generateHTML()
          Generate the page as HTML text.
 java.lang.String generateHTML(com.waveset.ui.util.html.Component root)
          Generate the HTML for a component, normally an HtmlPage.
 java.lang.String generateHTML(java.lang.Throwable t)
          If an exception is caught during HTML generation, render the text of the exception.
 java.lang.String getAppBaseURL()
          gets application base url to specify which application we are currently running under.
 java.lang.String getCancelURL()
           
 java.lang.String getCommand()
           
 java.util.List getComments()
           
 java.util.List getErrors()
           
 java.lang.String getHtmlFormName()
          Bug #13751 Return the String name of the HTML form as rendered by HtmlPage.
 java.util.List getMessages()
           
 java.lang.String getNextURL()
           
static ObjectRef getObjectRef(java.util.Map map, java.lang.String key, Type type)
           
 java.lang.String getParameter(java.lang.String name)
          Get an HttpRequest parameter.
 java.lang.String getPostURL()
           
 RequestState getRequestState()
           
 java.lang.String getSubTitle()
           
 java.lang.String getTitle()
           
 boolean isCommand(java.lang.String cmd)
          Tests a command string.
 boolean isErrors()
          Return true if there are any error messages.
protected static void println(java.lang.Object o)
          Ubiquitous "macro"
 java.lang.String process(RequestState state)
          Page processing method.
 void setAppBaseURL(java.lang.String appBase)
          Sets the application base url string to be used in hard-coded relative urls for new applications such as auditor.
 void setCancelURL(java.lang.String url)
          Set the URL that we will POST to when the generated form is canceled.
 void setCommand(java.lang.String cmd)
          Change the command.
 void setHiddenId(java.lang.String id)
           
 void setHtmlFormName(java.lang.String n)
          Bug #13751 Set the name of the HTML FORM tag when it is rendered by HtmlPage.
 void setNextURL(java.lang.String url)
           
 void setPostURL(java.lang.String url)
          Set the URL that we will normally POST to when the generated form is submitted.
protected  void setRequestState(RequestState state)
           
 void setSubTitle(java.lang.String subTitle)
           
 void setTitle(java.lang.String title)
           
 void setTrace(boolean b)
           
static java.lang.String stripDirectory(java.lang.String src)
          Kludge to strip the directory prefix from a post URL.
 void transferPageState(com.waveset.ui.util.html.HtmlPage page)
          The com.waveset.ui.util.html.HtmlPage classes need some of the same information that was given to the PageProcessor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

trace

protected static Trace trace

_command

protected java.lang.String _command
The value of the "command" parameter extracted from the post data or URL query string. Almost all of the our generated forms will use this parameter to specify the name of the button pressed to submit the form.


_trace

protected boolean _trace
Debug flag

Constructor Detail

PageProcessor

public PageProcessor()
Method Detail

setTrace

public void setTrace(boolean b)

setTitle

public void setTitle(java.lang.String title)

setSubTitle

public void setSubTitle(java.lang.String subTitle)

setPostURL

public void setPostURL(java.lang.String url)
Set the URL that we will normally POST to when the generated form is submitted. The URL is expected to have already been processed with encodeURL() if necessary.


setCancelURL

public void setCancelURL(java.lang.String url)
Set the URL that we will POST to when the generated form is canceled. The URL is expected to have already been processed with encodeURL() if necessary.


setNextURL

public void setNextURL(java.lang.String url)

setHiddenId

public void setHiddenId(java.lang.String id)

setCommand

public void setCommand(java.lang.String cmd)
Change the command. Called only by GenericEditForm to allow the form and/or view handler to cause a different command to be processed than the one that was posted.


setAppBaseURL

public void setAppBaseURL(java.lang.String appBase)
Sets the application base url string to be used in hard-coded relative urls for new applications such as auditor.

Parameters:
appBase -

setHtmlFormName

public void setHtmlFormName(java.lang.String n)
Bug #13751 Set the name of the HTML FORM tag when it is rendered by HtmlPage.


clearErrors

public void clearErrors()
Clear the error message list.


addError

public void addError(java.lang.Object msg)
Add an error message to the list. Usually a string, but may also be a Message or FieldMessage.


addErrors

public void addErrors(java.util.List msgs)
Add a list of errors.


isErrors

public boolean isErrors()
Return true if there are any error messages.


clearMessages

public void clearMessages()
Clear the informational message list.


addMessage

public void addMessage(java.lang.Object msg)
Add an informational message to the list.


addMessages

public void addMessages(java.util.List msgs)
Add a list of messages.


addComment

public void addComment(java.lang.String msg)
Add a comment to the list.


addComments

public void addComments(java.util.List msgs)
Add a list of comments.


getTitle

public java.lang.String getTitle()

getSubTitle

public java.lang.String getSubTitle()

getPostURL

public java.lang.String getPostURL()

getCancelURL

public java.lang.String getCancelURL()

getNextURL

public java.lang.String getNextURL()

getAppBaseURL

public java.lang.String getAppBaseURL()
gets application base url to specify which application we are currently running under. For example: "auditor/"

Returns:

getErrors

public java.util.List getErrors()

getMessages

public java.util.List getMessages()

getComments

public java.util.List getComments()

getRequestState

public RequestState getRequestState()

setRequestState

protected void setRequestState(RequestState state)

getCommand

public java.lang.String getCommand()

getHtmlFormName

public java.lang.String getHtmlFormName()
Bug #13751 Return the String name of the HTML form as rendered by HtmlPage.


isCommand

public boolean isCommand(java.lang.String cmd)
Tests a command string.


process

public java.lang.String process(RequestState state)
                         throws WavesetException
Page processing method.

The JSP is expected to call this first after setting any customization options.

The method may return a string, which is treated as a URL fragment for the next page. The JSP is expected to obey this. If the return string is null, the JSP is expected to call the either the generate() or generateHTML() method, and emit the HTML result.

You normally want to overload this but for very simple forms, we just save state and fall in to generate().

Throws:
WavesetException

generate

public com.waveset.ui.util.html.HtmlPage generate()
                                           throws WavesetException
Generate the page as an HtmlPage object.

The JSP is expected to call this after calling process(), but only if process() returns a null URL.

There are two variants of this, one that returns an HtmlPage object, and the other a completely rendered string of HTML. You would use generate() if the JSP needed to inspect or modify the HtmlPage object before the HTML was generated. If you have no processing to do, use generateHTML.

Throws:
WavesetException

generateHTML

public java.lang.String generateHTML(com.waveset.ui.util.html.Component root)
Generate the HTML for a component, normally an HtmlPage. This may be used if you have called the generate() method to obtain the HtmlPage object for post-processing and now wish to render it.


generateHTML

public java.lang.String generateHTML(java.lang.Throwable t)
If an exception is caught during HTML generation, render the text of the exception.


generateHTML

public java.lang.String generateHTML()
Generate the page as HTML text.

The default implementation is just to call generate() and format the result.


getParameter

public java.lang.String getParameter(java.lang.String name)
Get an HttpRequest parameter.


transferPageState

public void transferPageState(com.waveset.ui.util.html.HtmlPage page)
The com.waveset.ui.util.html.HtmlPage classes need some of the same information that was given to the PageProcessor. This provides a convenient way to move the relevant information.

NOTE: We always pass along URLs, but we will not trash the title or subtitle if the page already has one. Titles are better specified in the Form, while URLs are better set by the JSP.


println

protected static void println(java.lang.Object o)
Ubiquitous "macro"


stripDirectory

public static java.lang.String stripDirectory(java.lang.String src)
Kludge to strip the directory prefix from a post URL. e.g. "user/workItemEdit.jsp" becomes "workItemEdit.jsp".

This is necessary because we want to redirect back to a URL that was specified as the "post URL in the JSP. Post URLs have a directory prefix because it will be embedded in HTML. Redirect URLs however are always relative to the current page, so the directory is already implicit in the redirect.

This qualified vs. unqualified URL nonesense is a constant source of confusion, think about having all urls in PageProcessors be unqualified, then have an additional attribute for the directory prefix, to be used only when a url is being inserted into HTML.

UPDATE: With David's recent changes for URL formatting, this method is no longer necessary. All URLs must have a directory prefix.


getObjectRef

public static ObjectRef getObjectRef(java.util.Map map,
                                     java.lang.String key,
                                     Type type)
Returns:
an ObjectRef coerced from the value of a map entry, or null if that is impossible.