com.sitemesh.parser
Class AbstractPage

java.lang.Object
  |
  +--com.sitemesh.parser.AbstractPage
Direct Known Subclasses:
AbstractHTMLPage, UnParsedPage

public abstract class AbstractPage
extends java.lang.Object
implements Page

Abstract implementation of Page .

Contains base methods for storing and accessing page properties. Also stores pageData as byte[] and implements write???() methods.

Concrete implementations need only set the pageData and call addProperty(java.lang.String,java.lang.String) to add all the required information.

Version:
$Revision: 1.7 $
Author:
Joe Walnes
See Also:
Page

Field Summary
protected  byte[] pageData
          Date of page contents.
 javax.servlet.http.HttpServletRequest request
          RequestURI of original Page.
 
Constructor Summary
AbstractPage()
           
 
Method Summary
protected  void addProperty(java.lang.String name, java.lang.String value)
          Add a property to the properties list.
 boolean getBooleanProperty(java.lang.String name)
          Get a property embedded into the Page as a boolean.
 int getContentLength()
          Length of the Page, in the format before it was parsed.
 int getIntProperty(java.lang.String name)
          Get a property embedded into the Page as an int.
 long getLongProperty(java.lang.String name)
          Get a property embedded into the Page as a long.
 java.lang.String[] getProperties(java.lang.String name)
          Get properties embedded into the Page as a String[].
 java.lang.String getProperty(java.lang.String name)
          Get a property embedded into the Page as a String.
 java.lang.String[] getPropertyKeys()
          Get all available property keys for the Page.
 int getPropertySize(java.lang.String name)
          Determine the number of properties embedded into the Page with a given name.
 javax.servlet.http.HttpServletRequest getRequest()
          Return the request of the original page.
 boolean isPropertySet(java.lang.String name)
          Determine whether a property embedded into the Page has been set.
protected  java.lang.String noNull(java.lang.String in)
          Return String as is, or "" if null.
 void setRequest(javax.servlet.http.HttpServletRequest request)
          Create snapshot of Request.
 boolean shouldCache()
          Returns false.
 void writePage(java.io.OutputStream out)
          Write the entire contents of the Page, in the format before it was parsed, to the OutputStream.
 void writePage(java.io.Writer out)
          Write the entire contents of the Page, in the format before it was parsed, to the Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageData

protected byte[] pageData
Date of page contents.

request

public javax.servlet.http.HttpServletRequest request
RequestURI of original Page.
Constructor Detail

AbstractPage

public AbstractPage()
Method Detail

writePage

public void writePage(java.io.OutputStream out)
               throws java.io.IOException
Description copied from interface: Page
Write the entire contents of the Page, in the format before it was parsed, to the OutputStream.
Specified by:
writePage in interface Page
Tags copied from interface: Page
Parameters:
out - OutputStream to write to.
Throws:
java.io.IOException - Rethrown if cannot write to stream.
See Also:
Page.writePage(java.io.Writer)

writePage

public void writePage(java.io.Writer out)
               throws java.io.IOException
Description copied from interface: Page
Write the entire contents of the Page, in the format before it was parsed, to the Writer.
Specified by:
writePage in interface Page
Tags copied from interface: Page
Parameters:
out - Writer to write to.
Throws:
java.io.IOException - Rethrown if cannot write to writer.
See Also:
Page.writePage(java.io.OutputStream)

getContentLength

public int getContentLength()
Description copied from interface: Page
Length of the Page, in the format before it was parsed.
Specified by:
getContentLength in interface Page
Tags copied from interface: Page
Returns:
Length of page data (in number of bytes).

getProperty

public java.lang.String getProperty(java.lang.String name)
Description copied from interface: Page
Get a property embedded into the Page as a String.
Specified by:
getProperty in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Property value

getIntProperty

public int getIntProperty(java.lang.String name)
Description copied from interface: Page
Get a property embedded into the Page as an int. Returns 0 if property not specified or not valid number.
Specified by:
getIntProperty in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Property value

getLongProperty

public long getLongProperty(java.lang.String name)
Description copied from interface: Page
Get a property embedded into the Page as a long. Returns 0L if property not specified or not valid number.
Specified by:
getLongProperty in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Property value

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name)
Description copied from interface: Page
Get a property embedded into the Page as a boolean. Returns true if value starts with '1', 't' or 'y' (case-insensitive) - otherwise returns false.
Specified by:
getBooleanProperty in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Property value

getProperties

public java.lang.String[] getProperties(java.lang.String name)
Description copied from interface: Page
Get properties embedded into the Page as a String[]. Returns zero length array if no properties set.
Specified by:
getProperties in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Property values

isPropertySet

public boolean isPropertySet(java.lang.String name)
Description copied from interface: Page
Determine whether a property embedded into the Page has been set.
Specified by:
isPropertySet in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Whether it has been set

getPropertySize

public int getPropertySize(java.lang.String name)
Description copied from interface: Page
Determine the number of properties embedded into the Page with a given name.
Specified by:
getPropertySize in interface Page
Tags copied from interface: Page
Parameters:
name - Name of property
Returns:
Number of properties set with given name.

getPropertyKeys

public java.lang.String[] getPropertyKeys()
Description copied from interface: Page
Get all available property keys for the Page.
Specified by:
getPropertyKeys in interface Page
Tags copied from interface: Page
Returns:
Property keys

shouldCache

public boolean shouldCache()
Returns false. Override as necessary.
Specified by:
shouldCache in interface Page
See Also:
Page.shouldCache()

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Description copied from interface: Page
Return the request of the original page.
Specified by:
getRequest in interface Page
See Also:
Page.getRequest()

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
Create snapshot of Request.
Specified by:
setRequest in interface Page
See Also:
Page.getRequest()

addProperty

protected void addProperty(java.lang.String name,
                           java.lang.String value)
Add a property to the properties list.

Duplicate keys are allowed... property will be given multiple values. Sub-classes should use this for adding properties to the page.

Parameters:
name - Name of property
value - Value of property

noNull

protected java.lang.String noNull(java.lang.String in)
Return String as is, or "" if null. (Prevents NullPointerExceptions)