NextApp Echo
App Container 1.0.5

nextapp.echoservlet
Class HtmlDocument

java.lang.Object
  extended bynextapp.echoservlet.HtmlDocument
All Implemented Interfaces:
java.io.Serializable

public class HtmlDocument
extends java.lang.Object
implements java.io.Serializable

A representation of an HTML document. This class functions as the root node for the tree of HTMLElements that make up a renderable document.

See Also:
Serialized Form

Field Summary
private  Element body
           
private  Connection conn
           
private  boolean cursorOnNewLine
           
private static java.lang.String DOCTYPE_HTML401_TRANS
          A document header for an HTML 4.01 Transitional document.
static int EVENT_INITIALIZE
          A script event type for "initialization" tasks.
static int EVENT_ONLOAD
          A script event type for "onload" tasks.
static int EVENT_ONUNLOAD
          A script event type for "onunload" tasks.
private  Element head
           
private  java.util.List initializationEvents
           
private static Element META_GENERATOR
          The generator meta tag.
private  int nextId
           
private  java.util.List onloadEvents
           
private  java.util.List onunloadEvents
           
private  java.util.List rootScripts
           
private  java.util.Set scriptIncludes
           
private static Service SERVICE_INIT_FRAME_SCRIPT
           
private  java.util.Map styles
           
private  int xScrollBarPosition
           
private  int yScrollBarPosition
           
 
Constructor Summary
protected HtmlDocument(Connection conn, Element body)
          Creates a new instance rendered through the specified connection and containing body as its root content element.
 
Method Summary
 void addScript(java.lang.String script)
          Adds a line of JavaScript that will be invoked as the document is rendered.
 void addScript(java.lang.String script, int eventType)
          Adds a line of JavaScript that will be invoked when an event occurs.
 void addScriptInclude(Service service)
          Adds a referenced JavaScript include.
 java.lang.String addStyle(ComponentStyle componentStyle)
          Adds a component style to the document.
static HtmlDocument create(Connection conn)
          Creates a normal document (not a frameset).
static HtmlDocument createFrameSet(Connection conn)
          Creates a frameset document.
 Element getBodyElement()
          Returns the "body" element of the document.
 Element getHeadElement()
          Returns the <head> element of the document.
 boolean isCursorOnNewLine()
          Returns the if the browser's "rendering cursor" is at the beginning of a new line.
 void render(java.io.PrintWriter pw)
          Renders the entire document to the specified PrintWriter.
 void setCursorOnNewLine(boolean cursorOnNewLine)
          Sets whether the browser's rendering cursor is on a new line.
 void setScrollBarPositions(int x, int y)
          Sets the intial scroll bar positions of the document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCTYPE_HTML401_TRANS

private static final java.lang.String DOCTYPE_HTML401_TRANS
A document header for an HTML 4.01 Transitional document.

See Also:
Constant Field Values

META_GENERATOR

private static final Element META_GENERATOR
The generator meta tag.


EVENT_INITIALIZE

public static final int EVENT_INITIALIZE
A script event type for "initialization" tasks. This constant is a suitable value for the eventName parameter of the addScript method. A script added with this event type will be executed once its document's frame's parents have executed their initialization scripts.

See Also:
Constant Field Values

EVENT_ONLOAD

public static final int EVENT_ONLOAD
A script event type for "onload" tasks. This constant is a suitable value for the eventName parameter of the addScript method. A script added with this event type will be executed once its document's frame's child frames have executed their onload scripts.

See Also:
Constant Field Values

EVENT_ONUNLOAD

public static final int EVENT_ONUNLOAD
A script event type for "onunload" tasks. This constant is a suitable value for the evetName parameter of the addScript method. A script added with this event type will be executed when a document is removed from service, such as in the event that its content is changed or its window is closed or reloaded.

See Also:
Constant Field Values

SERVICE_INIT_FRAME_SCRIPT

private static final Service SERVICE_INIT_FRAME_SCRIPT

body

private Element body

head

private Element head

scriptIncludes

private java.util.Set scriptIncludes

initializationEvents

private java.util.List initializationEvents

onloadEvents

private java.util.List onloadEvents

onunloadEvents

private java.util.List onunloadEvents

styles

private java.util.Map styles

conn

private Connection conn

cursorOnNewLine

private boolean cursorOnNewLine

rootScripts

private java.util.List rootScripts

xScrollBarPosition

private int xScrollBarPosition

yScrollBarPosition

private int yScrollBarPosition

nextId

private int nextId
Constructor Detail

HtmlDocument

protected HtmlDocument(Connection conn,
                       Element body)
Creates a new instance rendered through the specified connection and containing body as its root content element.

Parameters:
conn - The connection for which this document is being put into service.
body - The element that will be used as the root content element of this document (a <body> or <frame> element).
Method Detail

create

public static HtmlDocument create(Connection conn)
Creates a normal document (not a frameset).

Parameters:
conn - The connection to which the document will be rendered.
Returns:
An HTML document that whose body is a <body> tag.

createFrameSet

public static HtmlDocument createFrameSet(Connection conn)
Creates a frameset document.

Parameters:
conn - The connection to which the document will be rendered.
Returns:
An HTML document that whose body is a <frameset> tag.

addScript

public void addScript(java.lang.String script)
Adds a line of JavaScript that will be invoked as the document is rendered. Such scripts may invoked before all resources are available, and thus most script calls should be added using the addScript(script, eventName) method. This method is only useful for adding global script variables to the document body.

Parameters:
script - A line of JavaScript code.

addScript

public void addScript(java.lang.String script,
                      int eventType)
Adds a line of JavaScript that will be invoked when an event occurs. These lines of JavaScript will be executed in the order that they were added.

Parameters:
script - A line of JavaScript code.
eventType - The name of the event, one of the following values:
  • EVENT_INITIALIZE execute the script when all frames have loaded.
  • EVENT_ONLOAD execute the script when all child frames have loaded.
  • EVENT_ONUNLOAD execute the script when the frame unloads.

addScriptInclude

public void addScriptInclude(Service service)
Adds a referenced JavaScript include.

Parameters:
service - The service that renders the JavaScript include.

addStyle

public java.lang.String addStyle(ComponentStyle componentStyle)
Adds a component style to the document. Returns the name of the style in the document.

Parameters:
componentStyle - The component style to add to the document.
Returns:
The document-specific name of the style. The document-specific name of the style is not necessarily identical to the style's name. The name of the style provided here must be used in all element "class" attributes that use the style to guarantee proper rendering.

getBodyElement

public Element getBodyElement()
Returns the "body" element of the document. This will either be a <body> element in the case of a content-holding document or a <frameset> element in the case of a frameset document.

Returns:
The "body" tag of the document.

getHeadElement

public Element getHeadElement()
Returns the <head> element of the document.

Returns:
The <head> element of the document.

isCursorOnNewLine

public boolean isCursorOnNewLine()
Returns the if the browser's "rendering cursor" is at the beginning of a new line. This is used to inform a component that is being rendered whether the last component will automatically move the browser's rendering cursor to the start of a new line, as is the case after a <br> or closing </table> tag is encountered.

Returns:
True if the cursor is on a new line.

render

public void render(java.io.PrintWriter pw)
Renders the entire document to the specified PrintWriter.

Parameters:
pw - A PrintWriter to render the document to.

setCursorOnNewLine

public void setCursorOnNewLine(boolean cursorOnNewLine)
Sets whether the browser's rendering cursor is on a new line.

Parameters:
cursorOnNewLine - True if the browser's rendering cursor is on a new line.
See Also:
isCursorOnNewLine()

setScrollBarPositions

public void setScrollBarPositions(int x,
                                  int y)
Sets the intial scroll bar positions of the document.

Parameters:
x - The initial horizontal scroll bar position (0 is the default).
y - The initial vertical scroll bar position (0 is the default).

NextApp Echo
App Container 1.0.5