creamtec.webcream.rendering.html
Class HTMLPage

java.lang.Object
  extended by java.util.Observable
      extended by creamtec.webcream.rendering.html.HTMLPage
All Implemented Interfaces:
Document
Direct Known Subclasses:
PositionedHTMLPage

public class HTMLPage
extends java.util.Observable
implements Document

Represents HTML page that will be sent to the browser. The page stores the HTML code in a buffer and provides methods to access and modify it. Each page is associated with a client agent for which the rendering is performed, and a rendering context which stores the rendering attributes and can be used to set flags during rendering. HTMLPage is different from StringBuffer in that it maintains an indent making reading HTML easier. Notice that to decrease the size of rendered HTML page you can opt not to maintain indents.

The page has a current output stream which can be either the header or the body. By default it is body when renderers are invoked. Page uses Observable pattern to support listeners on page rendering state. When the page is cleared either right before the processing of a new HTTP request or when the client agent is being shutdown, it notifies all registered listeners allowing them to do resource cleanup and other tasks. The parameter to Observer's update method is the page itself.


Constructor Summary
HTMLPage()
          Creates an empty page with default parameters
HTMLPage(ClientAgent agent)
          Creates an empty page with default parameters and associates it with the given client agent
HTMLPage(ClientAgent agent, int bufferSize)
          Creates an empty page with the given buffer size and associates it with the client agent
HTMLPage(HTMLPage page)
          Creates a page that has the same indents as the given page and is associated with the same client agent
 
Method Summary
 void append(char ch)
          Appends a character
 void append(int i)
          Appends an integer
 void append(java.lang.String s)
          Appends a string
 void appendCommonScripts()
          Appends scripts that are commont to all WebCream generated pages
 void appendEventHandler(java.lang.String eventName, java.awt.Component comp)
          Appends a JavaScript event handler to the component HTML tag.
 void appendHTMLText(java.lang.String htmlText, boolean noBreak)
          Appends text which can have HTML tags in it.
 void appendHTMLText(java.lang.String htmlText, boolean noBreak, boolean ignoreAllTags)
          Appends text which can have HTML tags in it.
 void appendJavaScript(java.lang.String script)
          Use to append JavaScript to the HTML page header together with other WebCream's JavaScripts.
 void appendln(java.lang.String s)
          Appends a string and an end-of-line character
 void appendOnLoadScriptBody(java.lang.String onLoadFunctionBody)
          Appends JavaScript statements to the body of onLoad function.
 void appendOnSubmitScript(java.lang.String script)
          Use to append code to the function that is called when WebCream page is submitted (any action is taken by the user)
 void appendText(java.lang.String text)
          Appends the given text to the page with parameters noBreak as false and ignoreHTMLTags as false.
 void appendText(java.lang.String text, boolean noBreak, boolean ignoreAllHTMLTags)
          Appends the given text to the page.
 void appendText(java.lang.String text, boolean noBreak, java.awt.Component comp)
          Appends the given text to HTML page.
 void appendText(java.lang.String text, java.awt.Component comp)
          Appends the given text as non-breakable spaced text.
 void appendTrailerScript(java.lang.String script)
          Appends a JavaScript to the end of the HTML page
 void appendTreeScripts()
          Appends tree scripts to the page buffer
 void beginTable(int border)
          Helper method that appends the tags that start HTML table
 void beginTable(int border, int cellPadding)
          Helper method that appends the tags that start HTML table
 void beginTable(int border, int cellPadding, java.lang.String props)
          Helper method that appends the tags that start HTML table
 void beginTable(int border, int cellPadding, java.lang.String props, java.lang.Object component)
          Helper method that appends the tags that start HTML table
 void beginTable(int border, int cellPadding, java.lang.String props, java.lang.Object component, java.lang.String style)
          Helper method that appends the tags that start HTML table.
 void beginTable(int border, java.lang.String props)
          Helper method that appends the tags that start HTML table
 void beginTableCell()
          Helper method to begin table cell
 void beginTableCell(java.lang.String props)
          Helper method to begin table cell
 void beginTableRow()
          Helper method to begin HTML table row
 void beginTableRow(java.lang.String props)
          Helper method to begin HTML table row using <tr> tag
 java.lang.String cleanupImageUrl(java.lang.String url)
          Helper function used by getImageUrl to clean up the image URL in case it originated from a jar or from a file
 void decreaseIndent()
          Decreases the indent on the page
 void endTable()
          Helper method to end HTML table
 void endTableCell()
          Helper method to end table cell
 void endTableRow()
          Helper method to end table row
static java.lang.String generateName(java.lang.Object obj)
          Delegates the generation of component name to WindowUpdater
 FormattedStringBuffer getBody()
          Returns the buffer representing the page body (HTML between <body> and </body> tags)
 ClientAgent getClientAgent()
          Returns the client agent, associated with this page.
 java.lang.String getComponentName(java.awt.Component comp)
          By default, names are generated based on the component type and the hashCode If a component has a name and renderContext forces names to be used, the component name is returned
static java.lang.String getComponentName(java.awt.MenuBar comp)
          If a component has a name, it is returned.
 java.lang.String getDocsURL()
          Returns the URL that specifies the location of the documents for the current application.
 FormattedStringBuffer getHeader()
          Returns the buffer representing the page header (HTML between <header> and </header> tags)
 java.lang.String getImageUrl(javax.swing.Icon icon, java.awt.Component component)
          Helper function that can be used to obtain a URL that should be used on a page for a given Icon.
 java.lang.String getImageUrl(java.awt.Image image)
          Helper function that can be used to obtain a URL that should be used on a page for a given Image.
 int getIndent()
          Returns the current indent as the number of spaces before the line text starts
 int getNextComponentNameIndex(java.lang.Object obj)
           
 java.lang.String getOnLoadScriptBody()
           
 FormattedStringBuffer getOutput()
          Returns the buffer (body/header) that the page is currently outputing to
 HTMLPageRenderer getPageRenderer()
          Returns the page renderer associated with the page.
 java.util.Map getProps()
          Properties map can be used to store a list of standard and user-defined properties
 java.lang.String getRedirectURL()
          Returns the redirection URL
 RenderContext getRenderContext()
          Returns the rendering context associated with this page
 int getSnapshotImageIndex()
          Returns an index for generating the snapshot name
 java.lang.String getSubmitURL()
          Returns the URL
 java.lang.String getThemeDocsURL()
          Returns the URL that specifies the location of the theme-specificdocuments for the current application.
 java.lang.String getThemeName()
          Returns the name of the application HTML theme.
 java.lang.String getTitle()
          Returns page title
 FormattedStringBuffer getWindowFooter()
          Returns the buffer representing the end of the page body.
 void includeJavaScript(java.lang.String srcUrl)
          Includes an external JavaScript file identified by the source URL Behaves correctly if called multiple times for the same URL
 void includeStylesheet(java.lang.String srcUrl)
          Includes an external JavaScript file identified by the source URL Behaves correctly if called multiple times for the same URL
 void increaseIndent()
          Increases the indent on the page
 void incSnapshotIndex()
          Increments an index for generating the snapshot name by one
 void insertMarked(java.lang.String string)
          Inserts the given string into the buffer at the positioned that was previously marked with markPosition.
 void markPosition()
          Saves the end of the buffer as the current marked position.
static java.lang.String nameToHTML(java.lang.String str)
          Converts the given name to HTML manageable name that can be used for HTML and JavaScript elements
 void newLine()
          Ensure that next text appended will be written on the new line.
 void outputBody()
          Instructs the page to append all text to the body
 void outputHeader()
          Instructs the page to append all text to the header
 void prependJavaScript(java.lang.String script)
          Use to insert a JavaScript to the HTML page header before any other JavaScript functions.
 void reset(boolean complete)
          Clears the page and its buffers.
 void resetComponentNameIndexes()
           
 void setClientAgent(ClientAgent agent)
          Used by WebCream to associate an agent with the page.
 void setIndent(int indent)
          Sets the current indent as the number of spaces before the line text starts
 void setNoBreak(boolean noBreak)
          If noBreak is set to true, the current HTML is wrapped with tags.
 void setNoBreak(boolean noBreak, java.awt.Component comp)
          If component is passed in, <nobr> tag will be styled/positioned according to component position
 void setOutput(FormattedStringBuffer output)
          Sets the buffer (body/header) that the page is currently outputing to
 void setPageRenderer(HTMLPageRenderer pageRenderer)
          Used by WebCream to associate a page renderer with the page.
 void setRedirectURL(java.lang.String url)
          Sets the URL that WebCream should redirect browser to
 void setRenderContext(RenderContext context)
          Sets rendering context
 void setTitle(java.lang.String title)
          Sets page title
 void setUseOnLoad(boolean useOnLoad)
          Sets weather or not the page should have onLoad function specified for the tag
 boolean shouldIgnoreTag(java.lang.String tag)
          Returns true if the tag should be skipped
 java.lang.String toString()
          Returns stringified representation of the page
 void writeTrailer()
          Writes the trailer script the to page output
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HTMLPage

public HTMLPage()
Creates an empty page with default parameters


HTMLPage

public HTMLPage(ClientAgent agent)
Creates an empty page with default parameters and associates it with the given client agent


HTMLPage

public HTMLPage(ClientAgent agent,
                int bufferSize)
Creates an empty page with the given buffer size and associates it with the client agent


HTMLPage

public HTMLPage(HTMLPage page)
Creates a page that has the same indents as the given page and is associated with the same client agent

Method Detail

setClientAgent

public void setClientAgent(ClientAgent agent)
Used by WebCream to associate an agent with the page. Generally should not be called by renderers


setPageRenderer

public void setPageRenderer(HTMLPageRenderer pageRenderer)
Used by WebCream to associate a page renderer with the page. Generally should not be called by renderers


getPageRenderer

public HTMLPageRenderer getPageRenderer()
Returns the page renderer associated with the page. PageRenderer can be used to render components and containers


appendln

public void appendln(java.lang.String s)
Appends a string and an end-of-line character


newLine

public void newLine()
Ensure that next text appended will be written on the new line. If the buffer already ends with a new line character, nothing is done. Otherwise an end-of-line is appended.


append

public void append(java.lang.String s)
Appends a string


append

public void append(char ch)
Appends a character


append

public void append(int i)
Appends an integer


appendText

public void appendText(java.lang.String text,
                       java.awt.Component comp)
Appends the given text as non-breakable spaced text. appendText is different from append(String) in that the text is treated that readable text on the page. It can be rendered as a <span> and have different attributes such as font and color. Internally appendText uses append(String) to write to the page buffer.

Parameters:
text - text to append
comp - component that will be used to determine the style of the text such as the color and font

appendText

public void appendText(java.lang.String text)
Appends the given text to the page with parameters noBreak as false and ignoreHTMLTags as false.

Parameters:
text - text to append

appendText

public void appendText(java.lang.String text,
                       boolean noBreak,
                       boolean ignoreAllHTMLTags)
Appends the given text to the page.

Parameters:
text - text to append
noBreak - if set to true, the text will be enclosed in HTML <nobreak> tags
ignoreAllHTMLTags - if set to true, all HTML tags will be removed from the text

appendText

public void appendText(java.lang.String text,
                       boolean noBreak,
                       java.awt.Component comp)
Appends the given text to HTML page. appendText is different from append(String) in that the text is treated that readable text on the page. It can be rendered as a <span> and have different attributes such as font and color. Internally appendText uses append(String) to write to the page buffer.

Parameters:
text - text to append
noBreak - if true, the text will not wrap on the HTML page even if it does not fit into the area
comp - component that will be used to determine the style of the text such as the color and font

appendHTMLText

public void appendHTMLText(java.lang.String htmlText,
                           boolean noBreak)
Appends text which can have HTML tags in it. No processing of color or font is performed and the string is appended as-is, except that some tags are stripped out. For example, if the passed string has a <body> tag it will not be appended.

Parameters:
htmlText - HTML buffer to append
noBreak - if true then the passed text will not wrap on the page even if the display area is too small

appendHTMLText

public void appendHTMLText(java.lang.String htmlText,
                           boolean noBreak,
                           boolean ignoreAllTags)
Appends text which can have HTML tags in it. No processing of color or font is performed and the string is appended as-is, except that some tags are stripped out. For example, if the passed string has a <body> tag it will not be appended.

Parameters:
htmlText - HTML buffer to append
noBreak - if true then the passed text will not wrap on the page even if the display area is too small
ignoreAllTags - if true all HTML tags in the text will be skipped while appending

shouldIgnoreTag

public boolean shouldIgnoreTag(java.lang.String tag)
Returns true if the tag should be skipped


appendEventHandler

public void appendEventHandler(java.lang.String eventName,
                               java.awt.Component comp)
Appends a JavaScript event handler to the component HTML tag. The output would have the syntax: <eventName>="doSubmit('/event/<componentName>') Example: onClick="doSubmit('/event/JCheckBox12345')"

Parameters:
eventName - name of the JavaScript event
comp - component who's name will be used to submit the event

increaseIndent

public void increaseIndent()
Increases the indent on the page


decreaseIndent

public void decreaseIndent()
Decreases the indent on the page


getIndent

public int getIndent()
Returns the current indent as the number of spaces before the line text starts


setIndent

public void setIndent(int indent)
Sets the current indent as the number of spaces before the line text starts


beginTable

public void beginTable(int border)
Helper method that appends the tags that start HTML table

See Also:
beginTable(int, int, String, Object)

beginTable

public void beginTable(int border,
                       int cellPadding)
Helper method that appends the tags that start HTML table

See Also:
beginTable(int, int, String, Object)

beginTable

public void beginTable(int border,
                       java.lang.String props)
Helper method that appends the tags that start HTML table

See Also:
beginTable(int, int, String, Object)

beginTable

public void beginTable(int border,
                       int cellPadding,
                       java.lang.String props)
Helper method that appends the tags that start HTML table

See Also:
beginTable(int, int, String, Object, String)

beginTable

public void beginTable(int border,
                       int cellPadding,
                       java.lang.String props,
                       java.lang.Object component)
Helper method that appends the tags that start HTML table

See Also:
beginTable(int, int, String, Object, String)

beginTable

public void beginTable(int border,
                       int cellPadding,
                       java.lang.String props,
                       java.lang.Object component,
                       java.lang.String style)
Helper method that appends the tags that start HTML table. Specifically, it adds <table> tag and attributes such as border and cell padding.

Parameters:
border - thickness of table border in pixels
cellPadding - the value of cellpadding table attribute
props - if not null, will be inserted into the <table> tag
component - if not null, the style of the component will be inserted into <table> tag using getPageRenderer().appendComponentStyle
style - if not null, will be inserted into the style property of <table> tag

endTable

public void endTable()
Helper method to end HTML table


beginTableRow

public void beginTableRow()
Helper method to begin HTML table row


beginTableRow

public void beginTableRow(java.lang.String props)
Helper method to begin HTML table row using <tr> tag

Parameters:
props - if not null, will be inserted into <tr> tag

endTableRow

public void endTableRow()
Helper method to end table row


beginTableCell

public void beginTableCell()
Helper method to begin table cell


beginTableCell

public void beginTableCell(java.lang.String props)
Helper method to begin table cell

Parameters:
props - if not null, the properties will be inserted into <td> tag

endTableCell

public void endTableCell()
Helper method to end table cell


markPosition

public void markPosition()
Saves the end of the buffer as the current marked position. There is only one marked position and calling markPosition again will override it.


insertMarked

public void insertMarked(java.lang.String string)
Inserts the given string into the buffer at the positioned that was previously marked with markPosition. Can be used to insert strings in the middle of the HTML page buffer


appendJavaScript

public void appendJavaScript(java.lang.String script)
Use to append JavaScript to the HTML page header together with other WebCream's JavaScripts. The script should represent a JavaScript function without <script> tags.


prependJavaScript

public void prependJavaScript(java.lang.String script)
Use to insert a JavaScript to the HTML page header before any other JavaScript functions. The script should represent a JavaScript function without <script> tags.


appendOnSubmitScript

public void appendOnSubmitScript(java.lang.String script)
Use to append code to the function that is called when WebCream page is submitted (any action is taken by the user)


appendTrailerScript

public void appendTrailerScript(java.lang.String script)
Appends a JavaScript to the end of the HTML page


includeJavaScript

public void includeJavaScript(java.lang.String srcUrl)
Includes an external JavaScript file identified by the source URL Behaves correctly if called multiple times for the same URL

Parameters:
srcUrl -

includeStylesheet

public void includeStylesheet(java.lang.String srcUrl)
Includes an external JavaScript file identified by the source URL Behaves correctly if called multiple times for the same URL

Parameters:
srcUrl -

writeTrailer

public void writeTrailer()
Writes the trailer script the to page output


getRenderContext

public RenderContext getRenderContext()
Returns the rendering context associated with this page


getProps

public java.util.Map getProps()
Properties map can be used to store a list of standard and user-defined properties


setRenderContext

public void setRenderContext(RenderContext context)
Sets rendering context


getBody

public FormattedStringBuffer getBody()
Returns the buffer representing the page body (HTML between <body> and </body> tags)


getWindowFooter

public FormattedStringBuffer getWindowFooter()
Returns the buffer representing the end of the page body. It is appended after all rendering is done but before </body> tag


getHeader

public FormattedStringBuffer getHeader()
Returns the buffer representing the page header (HTML between <header> and </header> tags)


toString

public java.lang.String toString()
Returns stringified representation of the page

Overrides:
toString in class java.lang.Object

getSubmitURL

public java.lang.String getSubmitURL()
Returns the URL


getDocsURL

public java.lang.String getDocsURL()
Returns the URL that specifies the location of the documents for the current application. The documents URL starts with "http:" and normally ends with WebCream web application context folder on the web server, for instance "http://localhost:8040/webcream". This value can be set in application properties file using "html.docsURL" property

Returns:
the URL used to access HTML documents such as scripts and images

getThemeDocsURL

public java.lang.String getThemeDocsURL()
Returns the URL that specifies the location of the theme-specificdocuments for the current application. The documents URL starts with "http:" and normally ends with WebCream theme documents folder on the web server, for instance "http://localhost:8040/webcream/Windows_docs". This value is derived from getDocsURL()

Returns:
the URL used to access theme documents such as scripts and images

getThemeName

public java.lang.String getThemeName()
Returns the name of the application HTML theme. Can be set in application properties using html.theme property.

Returns:
theme name

setRedirectURL

public void setRedirectURL(java.lang.String url)
Sets the URL that WebCream should redirect browser to

Parameters:
url - URL

getRedirectURL

public java.lang.String getRedirectURL()
Returns the redirection URL

Returns:
String

generateName

public static java.lang.String generateName(java.lang.Object obj)
Delegates the generation of component name to WindowUpdater

Parameters:
obj - UI element
Returns:
name

getTitle

public java.lang.String getTitle()
Returns page title

Returns:
title

setTitle

public void setTitle(java.lang.String title)
Sets page title

Parameters:
title - title

setNoBreak

public void setNoBreak(boolean noBreak)
If noBreak is set to true, the current HTML is wrapped with tags. Calling this method multiple times has no cumulative effect

Parameters:
noBreak - boolean

setNoBreak

public void setNoBreak(boolean noBreak,
                       java.awt.Component comp)
If component is passed in, <nobr> tag will be styled/positioned according to component position


getClientAgent

public ClientAgent getClientAgent()
Returns the client agent, associated with this page. This is the preferred way of obtaining a reference to the client age for a given page


reset

public void reset(boolean complete)
Clears the page and its buffers. Resets indexes and counters to their defaults Observers are notified before the page state is reset


appendCommonScripts

public void appendCommonScripts()
Appends scripts that are commont to all WebCream generated pages


getComponentName

public java.lang.String getComponentName(java.awt.Component comp)
By default, names are generated based on the component type and the hashCode If a component has a name and renderContext forces names to be used, the component name is returned


getComponentName

public static java.lang.String getComponentName(java.awt.MenuBar comp)
If a component has a name, it is returned. Otherwise, a name is generated based on the component type, the request number and the index of the component in the container (for example, MenuBar11)


outputBody

public void outputBody()
Instructs the page to append all text to the body


outputHeader

public void outputHeader()
Instructs the page to append all text to the header


getOutput

public FormattedStringBuffer getOutput()
Returns the buffer (body/header) that the page is currently outputing to


setOutput

public void setOutput(FormattedStringBuffer output)
Sets the buffer (body/header) that the page is currently outputing to


getImageUrl

public java.lang.String getImageUrl(javax.swing.Icon icon,
                                    java.awt.Component component)
                             throws java.lang.Exception
Helper function that can be used to obtain a URL that should be used on a page for a given Icon. WebCream tries to locate the URL from which the Icon was loaded. If it is absolute URL such as http://mysite.com/images/myimage.gif then it is returned as is. If it is relative or file based, this function will prepend the URL with the themeURL and return the composite absolute URL

Throws:
java.lang.Exception

getImageUrl

public java.lang.String getImageUrl(java.awt.Image image)
Helper function that can be used to obtain a URL that should be used on a page for a given Image. WebCream tries to locate the URL from which the Icon was loaded. If it is absolute URL such as http://mysite.com/images/myimage.gif then it is returned as is. If it is relative or file based, this function will prepend the URL with the themeURL and return the composite absolute URL


cleanupImageUrl

public java.lang.String cleanupImageUrl(java.lang.String url)
Helper function used by getImageUrl to clean up the image URL in case it originated from a jar or from a file


appendTreeScripts

public void appendTreeScripts()
Appends tree scripts to the page buffer


appendOnLoadScriptBody

public void appendOnLoadScriptBody(java.lang.String onLoadFunctionBody)
Appends JavaScript statements to the body of onLoad function.

Parameters:
onLoadFunctionBody - statements to appear inside the body of function onLoad()

getOnLoadScriptBody

public java.lang.String getOnLoadScriptBody()

setUseOnLoad

public void setUseOnLoad(boolean useOnLoad)
Sets weather or not the page should have onLoad function specified for the tag


getSnapshotImageIndex

public int getSnapshotImageIndex()
Returns an index for generating the snapshot name

Returns:
index

incSnapshotIndex

public void incSnapshotIndex()
Increments an index for generating the snapshot name by one


nameToHTML

public static java.lang.String nameToHTML(java.lang.String str)
Converts the given name to HTML manageable name that can be used for HTML and JavaScript elements


getNextComponentNameIndex

public int getNextComponentNameIndex(java.lang.Object obj)

resetComponentNameIndexes

public void resetComponentNameIndexes()


Copyright © 2000-2006 CreamTec LLC. All Rights Reserved.