Modifier and Type | Field and Description |
---|---|
Log |
log
The default application log, retrieved via
WebApp.getAppLog . |
DEFAULT_BUFFER_SIZE, DEFAULT_ENCODING, DEFAULT_MIME_TYPE, DEFAULT_SRC_ENCODING, PACKAGE_NAME
Constructor and Description |
---|
PageImpl() |
Modifier and Type | Method and Description |
---|---|
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.
|
public Log log
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
)public PageImpl()
public void render(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws Exception
public void init(PageServlet servlet, String contextRelativePagePath) throws javax.servlet.ServletException
Page
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.
public void destroy()
Page
public String getPagePath(javax.servlet.http.HttpServletRequest req)
Page
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:
This will submit the form to the same page where the form is defined. This can be hard coded of course but by using.. <form action="[=getPagePath(req)]" method="post"> .. </form>
getPagePath
, the html
does not have to be changed if the name of the page changes on disk.getPagePath
in interface Page
public String getRealPath(javax.servlet.http.HttpServletRequest req)
Page
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
getRealPath
in interface Page
public void clientRedirect(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String newLocation) throws IOException
Page
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 |
clientRedirect
in interface Page
req
- the current requestres
- the current responseIOException
public CharArrayWriter getThreadLocalWriter()
Page
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();
getThreadLocalWriter
in interface Page
public final void startTimer()
getTime()
method.public final long getTime()
startTime
method (in milliseconds)public final void dbg(boolean val)
val
- true to enable debugging, false to disable.public final void dbgPrefix(String dbg_prefix)
dbg_prefix
- some html/text (such as public final void dbgSuffix(String dbg_suffix)
dbg_suffix
- some html/text that is printed after each debug statementpublic final void bug(Writer writer, Object str1) throws IOException
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.
IOException
public final void bug(Writer writer, Object str1, Object str2) throws IOException
IOException
public final void bug(Writer writer, Object str1, Object str2, Object str3) throws IOException
IOException
public final void bug(Writer writer, Object str1, Object str2, Object str3, Object... args) throws IOException
IOException
public final void debug(Writer writer, Object str1) throws IOException
bug(Writer, Object)
.IOException
public final void debug(Writer writer, Object str1, Object str2) throws IOException
IOException
public final void debug(Writer writer, Object str1, Object str2, Object str3) throws IOException
IOException
public final void debug(Writer writer, Object str1, Object str2, Object str3, Object... args) throws IOException
IOException