fc.web.page
Class PageImpl

java.lang.Object
  extended by fc.web.page.PageImpl
All Implemented Interfaces:
Page

public class PageImpl
extends Object
implements Page

A superclass for generated pages. All pages derive from this class.


Field Summary
 Log log
          The default application log, retrieved via WebApp.getAppLog.
 
Fields inherited from interface fc.web.page.Page
DEFAULT_BUFFER_SIZE, DEFAULT_ENCODING, DEFAULT_MIME_TYPE, PACKAGE_NAME
 
Constructor Summary
PageImpl()
           
 
Method Summary
 void bug(Writer writer, Object str1)
          Prints a debug statement if debugging is turned on for this page.
 void bug(Writer writer, Object str1, Object str2)
           
 void bug(Writer writer, Object str1, Object str2, Object str3)
           
 void bug(Writer writer, Object str1, Object str2, Object str3, Object... args)
           
 void clientRedirect(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String newLocation)
          Redirects the client to the new page location.
 void dbg(boolean val)
          Starts/stop debugging with no dbg_prefix/dbg_suffix.
 void dbgPrefix(String dbg_prefix)
          Sets the prefix for debugging output.
 void dbgSuffix(String dbg_suffix)
          Sets the suffix for debugging output.
 void debug(Writer writer, Object str1)
          Prints a debug statement if debugging is turned on for this page.
 void debug(Writer writer, Object str1, Object str2)
           
 void debug(Writer writer, Object str1, Object str2, Object str3)
           
 void debug(Writer writer, Object str1, Object str2, Object str3, Object... args)
           
 void destroy()
          This method is invoked whenever a page is destoryed/unloaded
 String getPagePath(javax.servlet.http.HttpServletRequest req)
          Returns the path to this page from the web servers document root.
 String getRealPath(javax.servlet.http.HttpServletRequest req)
          Returns the real absolute directory path for the PagePath.
 CharArrayWriter getThreadLocalWriter()
          Returns a thread specific CharArrayWriter that can be passed to this method as various points in the page.
 long getTime()
          Returns the time elapsed after invoking startTime method (in milliseconds)
 void init(PageServlet servlet, String contextRelativePagePath)
          This method is invoked whenever a page is created and before it is run.
 void render(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 void startTimer()
          If set to true, a timer to calculate page render time is started after this method call.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public Log log
The default application log, retrieved via WebApp.getAppLog. All molly pages can use this variable directly, for example log.info("test"). The log output level (and hence whether a logging statement at that level will be seen) is set by the WebApp configuration file. (If WebApp is not used or configured, then the log level will be set to the Log.DEFAULT_LEVEL)

Constructor Detail

PageImpl

public PageImpl()
Method Detail

render

public void render(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws Exception
Specified by:
render in interface Page
Throws:
Exception

init

public void init(PageServlet servlet,
                 String contextRelativePagePath)
          throws javax.servlet.ServletException
Description copied from interface: Page
This method is invoked whenever a page is created and before it is run.

Pages should override this method to instantiate/set-up page variables as needed. (pages have no-arg constructors so like most of the servlet API, setup and initialization of variables is done in a init method instead).

When overriding this class, you must remember to call: super.init

The page class is reloaded if the page is modified. Variables should therefore be cleaned up in the destory method as needed.

Specified by:
init in interface Page
Throws:
javax.servlet.ServletException

destroy

public void destroy()
Description copied from interface: Page
This method is invoked whenever a page is destoryed/unloaded

Specified by:
destroy in interface Page

getPagePath

public String getPagePath(javax.servlet.http.HttpServletRequest req)
Description copied from interface: Page
Returns the path to this page from the web servers document root.

So for example, if the page is at foo/bar.mp and is running under the webapp context of context1, then the page path will be: /context1/foo/bar.mp. If there is no specific web app (i.e., the most common case of a default "" webapp), then the page path will be /foo/bar.mp

This page path is essentially what needs to be typed in the browsers URL window to invoke the page. It's also useful as form action parameters. For example, in a molly page:

..
<form action="[=getPagePath(req)]" method="post">
..
</form>
This will submit the form to the same page where the form is defined. This can be hard coded of course but by using getPagePath, the html does not have to be changed if the name of the page changes on disk.

Specified by:
getPagePath in interface Page

getRealPath

public String getRealPath(javax.servlet.http.HttpServletRequest req)
Description copied from interface: Page
Returns the real absolute directory path for the PagePath.

So, for example, for a webserver document root at /web/sites/default/ and a page located in foo/bar.mp, the real path will be: /web/sites/default/foo/bar.mp

Specified by:
getRealPath in interface Page

clientRedirect

public void clientRedirect(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res,
                           String newLocation)
                    throws IOException
Description copied from interface: Page
Redirects the client to the new page location. This is a thin (possibly easier to remember) wrapper around the HttpServletResponse.sendRedirect method.

The location parameter can be relative to the specified request's URI or relative to the context root if it contains a leading '/'. The webapp name (if any) does not have to be specified, the redirect will creates a full URL (including the webapp context path) suitable for this purpose.

For example:

webapp context current page location parameter resulting page
default web app ("/") foo/bar.mp baz.mp foo/baz.mp
default web app ("/") foo/bar.mp /baz.mp baz.mp
/myapp foo/bar.mp baz.mp /myapp/foo/baz.mp
/myapp foo/bar.mp /baz.mp /myapp/baz.mp

Specified by:
clientRedirect in interface Page
Parameters:
req - the current request
res - the current response
Throws:
IOException

getThreadLocalWriter

public CharArrayWriter getThreadLocalWriter()
Description copied from interface: Page
Returns a thread specific CharArrayWriter that can be passed to this method as various points in the page. The contents of this writer can then be printed on the page when desired.

Note: The writer is not reset or flushed when it is retrieved. It must be reset manually via calling the CharArrayWriter.reset() method. This design-decision allows request threads to collect debugging data across multiple pages.

The suggested usage idiom is:

        dbg(true);
        CharArrayWriter cw = getThreadLocalWriter():
        bug(cw, "some message");
        ...
        bug(cw, "other message");
        ...
        
        cw.writeTo(out);
        cw.reset();
        

Specified by:
getThreadLocalWriter in interface Page

startTimer

public final void startTimer()
If set to true, a timer to calculate page render time is started after this method call. Page render time can then be displaying the value returned by invoking the getTime() method.


getTime

public final long getTime()
Returns the time elapsed after invoking startTime method (in milliseconds)


dbg

public final void dbg(boolean val)
Starts/stop debugging with no dbg_prefix/dbg_suffix.

Parameters:
val - true to enable debugging, false to disable.

dbgPrefix

public final void dbgPrefix(String dbg_prefix)
Sets the prefix for debugging output.

Parameters:
dbg_prefix - some html/text (such as <font color=red>) that is printed before each debug statement

dbgSuffix

public final void dbgSuffix(String dbg_suffix)
Sets the suffix for debugging output.

Parameters:
dbg_suffix - some html/text that is printed after each debug statement

bug

public final void bug(Writer writer,
                      Object str1)
               throws IOException
Prints a debug statement if debugging is turned on for this page.

Typically the implicit page printwriter (the out variable) will be passed to this method and debug statements will be printed at the point where they are lexically invoked at the page.

However, each page request thread can collect debugging information and print the output at some arbitrary location, such as the bottom of the page. The method getThreadLocalWriter() exists for this reason and can be used to collect thread-local output during page execution.

Throws:
IOException

bug

public final void bug(Writer writer,
                      Object str1,
                      Object str2)
               throws IOException
Throws:
IOException

bug

public final void bug(Writer writer,
                      Object str1,
                      Object str2,
                      Object str3)
               throws IOException
Throws:
IOException

bug

public final void bug(Writer writer,
                      Object str1,
                      Object str2,
                      Object str3,
                      Object... args)
               throws IOException
Throws:
IOException

debug

public final void debug(Writer writer,
                        Object str1)
                 throws IOException
Prints a debug statement if debugging is turned on for this page. Same as calling bug(Writer, Object).

Throws:
IOException

debug

public final void debug(Writer writer,
                        Object str1,
                        Object str2)
                 throws IOException
Throws:
IOException

debug

public final void debug(Writer writer,
                        Object str1,
                        Object str2,
                        Object str3)
                 throws IOException
Throws:
IOException

debug

public final void debug(Writer writer,
                        Object str1,
                        Object str2,
                        Object str3,
                        Object... args)
                 throws IOException
Throws:
IOException