Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

edu.virtualschool.jwaa.GenericPage Class Reference

Inheritance diagram for edu.virtualschool.jwaa.GenericPage:

edu.virtualschool.jwaa.xml.Controller Collaboration diagram for edu.virtualschool.jwaa.GenericPage:

Collaboration graph
[legend]
List of all members.

Detailed Description

Abstract superclass of all JWAA web page controller classes. Changed Jan-2003 to omit the JDBC Connection handling logic to close security hole when a controller must manage multiple JDBC connections such as JILE courses.

Definition at line 25 of file GenericPage.java.

Public Member Functions

void init (MetaPage meta, GenericServlet servlet, HttpServletRequest req, HttpServletResponse rsp) throws IOException, ServletException
abstract void run () throws Fault
void send (Object html) throws IOFault
final AccountAbstraction getAccount ()
final void setAccount (AccountAbstraction account)
RoleAbstraction getRequiredRole ()
void redirect (MetaPage meta) throws Fault
void forward (MetaPage meta) throws Fault
MetaPage getParent ()
Iterator children ()
String getTitle ()
String toString ()
final Validatable getField (String parameterName, Validatable defaultValue) throws Fault
final Validatable[] getFields (String parameterName, Validatable defaultValue) throws Fault
final HashMap getParameterMap ()
final String getParameter (Object key, Object defaultValue)
final Object getAttribute (String attributeName) throws IOFault
final String getContextName ()
final Validatable getCookie (String cookieName, Validatable defaultValue) throws Fault
final HttpServletRequest getHttpRequest ()
final HttpServletResponse getHttpResponse ()
final GenericServlet getServlet ()
final String getServletName ()
final HttpSession getSession ()
final PrintWriter getWriter () throws IOFault
final synchronized void setAttribute (String key, Object value)
final void setCookie (String cookieName, String cookieValue, int msec)
final String getArguments ()
String emitLink (MetaPage meta)
String emitLink (MetaPage meta, Object anchor)
String emitLink (MetaPage meta, Object anchor, Object title)
String emitLink (MetaPage meta, Object anchor, Object[] args)
String link (MetaPage meta, Object anchor, Object title, Object[] args)
String emitForm ()
String emitForm (MetaPage meta)
String emitForm (MetaPage meta, Object[] args)

Public Attributes

MetaPage meta
GenericServlet servlet
 The servlet that is handling this httpRequest.

HttpServletRequest httpRequest
 The servlet request that this instance is responding to.

HttpServletResponse httpResponse
 The servlet response that this instance is sending to.


Static Package Attributes

final Logger logger
final String SESSION_ATTRIBUTE_NAME = "_PERSON_"


Member Function Documentation

Iterator edu.virtualschool.jwaa.GenericPage.children  ) 
 

Return the children of this node in the page hierarchy

Returns:
Iterator

Definition at line 182 of file GenericPage.java.

References edu.virtualschool.jwaa.TreeNode.childrenIterator().

00183   {
00184     return meta.childrenIterator();
00185   }

String edu.virtualschool.jwaa.GenericPage.emitForm MetaPage  meta,
Object[]  args
 

Composes a <form> command for accessing the specified pageClass instance with the specified parameter list. The closing </form> must be sent manually.

Returns:
String
Parameters:
meta: the metapage of the target page
args: argument list

Definition at line 484 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitForm().

00485   {
00486     return meta.emitForm(this, args);
00487   }

String edu.virtualschool.jwaa.GenericPage.emitForm MetaPage  meta  ) 
 

Composes a <form> command for accessing the specified pageClass instance

Returns:
String
Parameters:
meta: the metapage of the target page; i.e. the page whose run method is to process this form's submission.

Definition at line 471 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitForm().

00472   {
00473     return meta.emitForm(this, null);
00474   }

String edu.virtualschool.jwaa.GenericPage.emitForm  ) 
 

Composes a <form> command for accessing the receiver page.

Returns:
String

Definition at line 459 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitForm().

00460   {
00461     return meta.emitForm(this, null);
00462   }

String edu.virtualschool.jwaa.GenericPage.emitLink MetaPage  meta,
Object  anchor,
Object[]  args
 

Returns an <a href="..."> command as a string

Returns:
String
Parameters:
meta: the target page.
anchor: use the provided anchor text instead of the default anchor from the metapage.
args: append these as hard-coded arguments.

Definition at line 447 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitLink().

00448   {
00449     return meta.emitLink(this, anchor, null, args);
00450   }

String edu.virtualschool.jwaa.GenericPage.emitLink MetaPage  meta,
Object  anchor,
Object  title
 

Returns an <a href="..."> command as a string

Returns:
String
Parameters:
meta: the target page.
anchor: use the provided anchor text instead of the default anchor from the metapage.
title: use this instead of the default title

Definition at line 435 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitLink().

00436   {
00437     return meta.emitLink(this, anchor, title, null);
00438   }

String edu.virtualschool.jwaa.GenericPage.emitLink MetaPage  meta,
Object  anchor
 

Returns an <a href="..."> command as a string

Returns:
String
Parameters:
meta: the target page.
anchor: use the provided anchor text instead of the default anchor from the metapage.

Definition at line 423 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitLink().

00424   {
00425     return meta.emitLink(this, anchor, null, null);
00426   }

String edu.virtualschool.jwaa.GenericPage.emitLink MetaPage  meta  ) 
 

Returns an <a href="..."> command as a string

Returns:
String
Parameters:
meta: the target page.

Definition at line 412 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.emitLink().

Referenced by edu.virtualschool.jwaa.GenericLookAndFeel.computeNavigationBar().

00413   {
00414     return meta.emitLink(this, null, null, null);
00415   }

void edu.virtualschool.jwaa.GenericPage.forward MetaPage  meta  )  throws Fault
 

Forward the httpRequest to the designated page and throw IgnorableFault so that control does not return to the caller.

Parameters:
meta: the desintation page.
Exceptions:
IgnorableFault: throws this to avoid returning to the caller

Definition at line 165 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.forward().

00166   {
00167     logger.debug("forward: " + meta);
00168     meta.forward(this);
00169   }

final AccountAbstraction edu.virtualschool.jwaa.GenericPage.getAccount  ) 
 

Return the person of the currently logged in user or null if the servlet's default person if this user has not logged in.

Returns:
AccountAbstraction person: the currently logged in person or defaultAccount if the viewer is not logged in or their session has expired.

Definition at line 100 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericServlet.getNullAccount(), edu.virtualschool.jwaa.GenericPage.getSession(), edu.virtualschool.jwaa.GenericPage.servlet, and edu.virtualschool.jwaa.GenericPage.SESSION_ATTRIBUTE_NAME.

Referenced by edu.virtualschool.jwaa.GenericLookAndFeel.computeNavigationBar(), and edu.virtualschool.jwaa.xml.Controller.run().

00101   {
00102     HttpSession session = getSession();
00103     if (session == null)
00104       return servlet.getNullAccount();
00105     AccountAbstraction person = (AccountAbstraction) session.getAttribute(SESSION_ATTRIBUTE_NAME);
00106     if (person == null)
00107       return servlet.getNullAccount();
00108     else
00109       return person;
00110   }

final String edu.virtualschool.jwaa.GenericPage.getArguments  ) 
 

Returns httpRequest arguments as a &-separate string

Returns:
String

Definition at line 395 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

00396   {
00397     StringBuffer buf = new StringBuffer();
00398     for (Enumeration e = httpRequest.getParameterNames(); e.hasMoreElements();)
00399     {
00400       String key = (String) e.nextElement();
00401       String[] values = httpRequest.getParameterValues(key);
00402       String value = StringUtil.join('&', values);
00403       buf.append(key + "=" + value + (e.hasMoreElements() ? "&" : ""));
00404     }
00405     return buf.toString();
00406   }

final Object edu.virtualschool.jwaa.GenericPage.getAttribute String  attributeName  )  throws IOFault
 

Get a session attribute.value by calling getSession().getAttribute(attributeName)

Parameters:
attributeName: the attribute name
Returns:
Object The value of this attribute or null if undefined.

Definition at line 270 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.getSession().

00271   {
00272     return getSession().getAttribute(attributeName);
00273   }

final String edu.virtualschool.jwaa.GenericPage.getContextName  ) 
 

Return the httpRequest's getContextPath() string.

Returns:
String

Definition at line 279 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

00280   {
00281     return httpRequest.getContextPath();
00282   }

final Validatable edu.virtualschool.jwaa.GenericPage.getCookie String  cookieName,
Validatable  defaultValue
throws Fault
 

Get cookie value by calling httpRequest.getCookies().

Parameters:
cookieName: The name of the desired cookie.
defaultValue: The value to return if the cookie is null.
Returns:
Validatable The default value to be returned if the cookie is undefined

Definition at line 291 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

00294   {
00295     Cookie[] cookies = httpRequest.getCookies();
00296     for (int i = 0; i < cookies.length; i++)
00297     {
00298       if (cookies[i].getName().equals(cookieName))
00299         return defaultValue.cloneWithValue(cookies[i].getValue());
00300     }
00301     return defaultValue;
00302   }

final Validatable edu.virtualschool.jwaa.GenericPage.getField String  parameterName,
Validatable  defaultValue
throws Fault
 

Get a single field of defaultValue's class initialized to the parameter's value if present else defaultValue's value

Parameters:
parameterName 
defaultValue 
Returns:
Validatable

Definition at line 202 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.getParameter().

00205   {
00206     String value = getParameter(parameterName, defaultValue.toString());
00207     return defaultValue.cloneWithValue(value);
00208   }

final Validatable [] edu.virtualschool.jwaa.GenericPage.getFields String  parameterName,
Validatable  defaultValue
throws Fault
 

Return an array of fields for the specified parameter name or an empty Validatable[0] if the field has no values.

Parameters:
parameterName 
defaultValue: the default value if the parameter is null.
Returns:
Validatable[]

Definition at line 217 of file GenericPage.java.

References edu.virtualschool.jwaa.field.Validatable.cloneWithValue(), and edu.virtualschool.jwaa.GenericPage.httpRequest.

00220   {
00221     String[] values = httpRequest.getParameterValues(parameterName);
00222     if (values == null)
00223       values = new String[0]; // paranoia
00224     Validatable[] array =
00225       (Validatable[]) java.lang.reflect.Array.newInstance(
00226         defaultValue.getClass(),
00227         values.length);
00228     for (int i = 0; i < values.length; i++)
00229       array[i] = defaultValue.cloneWithValue(values[i]);
00230     return array;
00231   }

final HttpServletRequest edu.virtualschool.jwaa.GenericPage.getHttpRequest  ) 
 

Get the httpRequest object

Returns:
HttpServletRequest

Definition at line 308 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

00309   {
00310     return httpRequest;
00311   }

final HttpServletResponse edu.virtualschool.jwaa.GenericPage.getHttpResponse  ) 
 

Get the httpResponse object

Returns:
javax.servlet.http.HttpServletResponse

Definition at line 317 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpResponse.

00318   {
00319     return httpResponse;
00320   }

final String edu.virtualschool.jwaa.GenericPage.getParameter Object  key,
Object  defaultValue
 

Get a httpRequest parameter. If null, return the defaultValue as a string.

Parameters:
key: the parameter desired
defaultValue: the value to be returned if the specified parameter is null.
Returns:
String the name of the servletRequested parameter.

Definition at line 255 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

Referenced by edu.virtualschool.jwaa.GenericPage.getField().

00256   {
00257     String value = httpRequest.getParameter(key.toString());
00258     if (value == null)
00259       return defaultValue.toString();
00260     else
00261       return value;
00262   }

final HashMap edu.virtualschool.jwaa.GenericPage.getParameterMap  ) 
 

Composes a parameter map as a Hashtable whose keys are names and values are Object[].

Definition at line 236 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

00237   {
00238     HashMap map = new HashMap();
00239     for (Enumeration e = httpRequest.getParameterNames(); e.hasMoreElements();)
00240     {
00241       String key = (String) e.nextElement();
00242       String value = httpRequest.getParameter(key);
00243       map.put(key, value);
00244     }
00245     return map;
00246   }

MetaPage edu.virtualschool.jwaa.GenericPage.getParent  ) 
 

Return the parent of this node in the page hierarchy

Returns:
PageElement

Definition at line 174 of file GenericPage.java.

References edu.virtualschool.jwaa.TreeNode.getParentNode().

00175   {
00176     return (MetaPage) meta.getParentNode();
00177   }

RoleAbstraction edu.virtualschool.jwaa.GenericPage.getRequiredRole  ) 
 

Return the role that an person must hold to be allowed to access this page. Navigation bars will only present links to this page, and Servlet will only dispatch requests to this page, if the person has the required role.

Returns:
GenericRole

Definition at line 132 of file GenericPage.java.

References edu.virtualschool.jwaa.MetaPage.requiredRole.

00133   {
00134     return meta.requiredRole;
00135   }

final GenericServlet edu.virtualschool.jwaa.GenericPage.getServlet  ) 
 

Get the Servlet

Returns:
GenericServlet

Definition at line 325 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.servlet.

00326   {
00327     return servlet;
00328   }

final String edu.virtualschool.jwaa.GenericPage.getServletName  ) 
 

Return the servlet name

Returns:
String

Definition at line 334 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

00335   {
00336     return httpRequest.getServletPath();
00337   }

final HttpSession edu.virtualschool.jwaa.GenericPage.getSession  ) 
 

Get the session object by calling httpRequest.getSession(true)

Returns:
HttpSession

Definition at line 343 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpRequest.

Referenced by edu.virtualschool.jwaa.GenericPage.getAccount(), edu.virtualschool.jwaa.GenericPage.getAttribute(), edu.virtualschool.jwaa.GenericPage.setAccount(), and edu.virtualschool.jwaa.GenericPage.setAttribute().

00344   {
00345     return httpRequest.getSession(true);
00346   }

final PrintWriter edu.virtualschool.jwaa.GenericPage.getWriter  )  throws IOFault
 

Get a PrintWriter suitable for communicating with the client browser by calling httpResponse.getWRiter().

Returns:
PrintWriter
Exceptions:
IOFault if httpResponse.getWriter() fails

Definition at line 354 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpResponse.

00355   {
00356     try
00357     {
00358       return httpResponse.getWriter();
00359     }
00360     catch (IOException e)
00361     {
00362       throw new IOFault(e);
00363     }
00364   }

void edu.virtualschool.jwaa.GenericPage.init MetaPage  meta,
GenericServlet  servlet,
HttpServletRequest  req,
HttpServletResponse  rsp
throws IOException, ServletException
 

Override to initialize page instance variables

Parameters:
meta: the metapage (information about) for this page
servlet: the servlet for this page
req: the request object for this page
rsp: the response object for this page
Exceptions:
IOException: misc errors
ServletException: misc errors

Definition at line 53 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.servlet.

Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest().

00059   {
00060     this.meta = meta;
00061     this.servlet = servlet;
00062     this.httpRequest = req;
00063     this.httpResponse = rsp;
00064     rsp.setContentType("text/html");
00065   }

void edu.virtualschool.jwaa.GenericPage.redirect MetaPage  meta  )  throws Fault
 

Redirect the httpRequest to the designated page and throw a IgnorableFault to ensure that control will not return to the caller. Redirects work by sending a redirect httpRequest to the browser, unlike forward, which works entirely within the server. IgnorableFault is caught and discarded here.

Parameters:
meta: the destination page.
Exceptions:
IgnorableFault: to avoid returning control to the caller

Definition at line 145 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericURI.getText(), edu.virtualschool.jwaa.GenericPage.httpResponse, and edu.virtualschool.jwaa.MetaPage.link.

00146   {
00147     try
00148     {
00149       String path = meta.link.getText();
00150       httpResponse.sendRedirect(httpResponse.encodeRedirectURL(path));
00151       throw new IgnorableFault();
00152     }
00153     catch (IOException e)
00154     {
00155       throw new IOFault("Fault redirecting to page " + meta);
00156     }
00157   }

abstract void edu.virtualschool.jwaa.GenericPage.run  )  throws Fault [pure virtual]
 

Servlet calls this to run the page. Every subclass overrides this to send html to the browser, to process form parameters, and so forth.

Exceptions:
IOFault upon IOException
ServletFault upon ServletException
DB.Fault upon all other exceptions

Implemented in edu.virtualschool.jwaa.xml.Controller.

Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest().

void edu.virtualschool.jwaa.GenericPage.send Object  html  )  throws IOFault
 

Send html text to the client as html text

Parameters:
html 
Exceptions:
IOFault 

Definition at line 81 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpResponse.

Referenced by edu.virtualschool.jwaa.xml.Controller.run().

00082   {
00083     try
00084     {
00085       PrintWriter writer = httpResponse.getWriter();
00086       writer.println(html.toString());
00087     }
00088     catch (IOException e)
00089     {
00090       throw new IOFault(e);
00091     }
00092   }

final void edu.virtualschool.jwaa.GenericPage.setAccount AccountAbstraction  account  ) 
 

Login the provided account by storing it as the session attribute SESSION_ATTRIBUTE_NAME.

Definition at line 115 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericServlet.getNullAccount(), edu.virtualschool.jwaa.GenericPage.getSession(), edu.virtualschool.jwaa.GenericPage.servlet, and edu.virtualschool.jwaa.GenericPage.SESSION_ATTRIBUTE_NAME.

00116   {
00117     if (account == null)
00118       account = servlet.getNullAccount();
00119     HttpSession session = getSession();
00120     if (session == null)
00121       throw new RuntimeFault("session is null. Should not happen");
00122     session.setAttribute(SESSION_ATTRIBUTE_NAME, account);
00123   }

final synchronized void edu.virtualschool.jwaa.GenericPage.setAttribute String  key,
Object  value
 

Set a session attribute to key/value

Parameters:
key: the attribute name
value: the attribute value

Definition at line 371 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.getSession().

00372   {
00373     HttpSession session = getSession();
00374     // if (session == null) Log.fault(this + " ignoring null session", null);
00375     session.setAttribute(key, value);
00376   }

final void edu.virtualschool.jwaa.GenericPage.setCookie String  cookieName,
String  cookieValue,
int  msec
 

Set a cookie to the designated name/value

Parameters:
cookieName: the cookie name
cookieValue: the cookie value
msec: the expiration time in msec.

Definition at line 384 of file GenericPage.java.

References edu.virtualschool.jwaa.GenericPage.httpResponse.

00385   {
00386     Cookie cookie = new Cookie(cookieName, cookieValue);
00387     cookie.setMaxAge(cookieValue == null ? 0 : msec);
00388     httpResponse.addCookie(cookie);
00389   }


Member Data Documentation

final Logger edu.virtualschool.jwaa.GenericPage.logger [static, package]
 

Initial value:

    Logger.getLogger(GenericPage.class.getName())

Definition at line 35 of file GenericPage.java.

final String edu.virtualschool.jwaa.GenericPage.SESSION_ATTRIBUTE_NAME = "_PERSON_" [static, package]
 

The name of the session attribute. This is reserved to hold the person of the currently logged in user. It is managed internally and should need no external attention other than to avoid using this name for other purposes.

Definition at line 42 of file GenericPage.java.

Referenced by edu.virtualschool.jwaa.GenericPage.getAccount(), and edu.virtualschool.jwaa.GenericPage.setAccount().


The documentation for this class was generated from the following file: