net.sf.jolene.dom
Class Document

java.lang.Object
  extended by net.sf.jolene.dom.Document

public final class Document
extends java.lang.Object

HTML Document object.

Since:
Sep 21, 2003 5:22:33 PM
Author:
Dan Howard

Constructor Summary
Document(java.lang.String fileName)
           
Document(java.lang.String fileName, java.lang.String contextPath, java.lang.String uri)
           
 
Method Summary
 boolean addHeader(Header header)
          Adds a header element to the document.
 Document clone()
          This is a custom clone implementation which ensures the document is cleanly and safely cloned.
 HTMLElement elements(java.lang.String id)
          Returns a object by searching all forms in the document.
 Form forms(int index)
          Returns the form object specified by the number.
 Form forms(java.lang.String name)
          Returns a form object specified by name.
 IAttributes getBody()
          Retrives the body attributes.
 java.lang.String getDoctype()
          Gets the doc type of the document.
 int getFormCount()
           
 int getHeaderCount()
          Returns the number of Header elements in the document.
 java.lang.String getTitle()
          Gets the document title.
 java.lang.String getUri()
           
 Header headers(int header)
          Return the Header element specified by the index based on document order.
 boolean isTranslated()
          Indicator for labels being translated.
 Header removeHeader(int index)
          Remove the headers
 void setDoctype(java.lang.String doctype)
          Sets the doc type of the document.
 void setTitle(java.lang.String string)
          Set the document title.
 void setTranslated(boolean translated)
          Indicator for labels being translated.
 void stream(java.lang.String filename)
          Writes the document to the specified fileName.
 void stream(java.io.Writer out)
          Writes the document to the specified Writer object and closes the Writer.
 java.lang.String toString()
          Returns the document file name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Document

public Document(java.lang.String fileName,
                java.lang.String contextPath,
                java.lang.String uri)
         throws java.io.IOException,
                MalformedHTMLException
Parameters:
fileName -
contextPath -
uri -
Throws:
java.io.IOException
MalformedHTMLException - - runtime exception

Document

public Document(java.lang.String fileName)
         throws java.io.IOException,
                MalformedHTMLException
Parameters:
fileName - - file name of the document.
Throws:
java.io.IOException - - if an IOException occurs
MalformedHTMLException - - runtime exception
Method Detail

addHeader

public boolean addHeader(Header header)
Adds a header element to the document.

Parameters:
header - a Header object.
Returns:
boolean to indicate success.

clone

public Document clone()
This is a custom clone implementation which ensures the document is cleanly and safely cloned. Used by the DocumentFactory.

Overrides:
clone in class java.lang.Object
Returns:
Document

elements

public HTMLElement elements(java.lang.String id)
Returns a object by searching all forms in the document.

Parameters:
id - The id of the element.
Returns:
HTMLElement

forms

public Form forms(int index)
Returns the form object specified by the number.

Parameters:
index - form number (starting with 0)
Returns:
Form a Form object
Throws:
java.lang.IndexOutOfBoundsException - - if the index is out of range (index < 0 || index >= size()).

forms

public Form forms(java.lang.String name)
Returns a form object specified by name. For the form to be found it will require a 'name' attribute.

Parameters:
name - name of the form in the document (case insensitive).
Returns:
Form a Form object or null if not found.

getBody

public IAttributes getBody()
Retrives the body attributes.

Returns:
IAttributes

getDoctype

public java.lang.String getDoctype()
Gets the doc type of the document.

Returns:
String

getFormCount

public int getFormCount()
Returns:
Number of forms in the document.

getHeaderCount

public int getHeaderCount()
Returns the number of Header elements in the document.

Returns:
int number of Header elements.

getTitle

public java.lang.String getTitle()
Gets the document title.

Returns:
title

getUri

public java.lang.String getUri()
Returns:
uri string for this document.

headers

public Header headers(int header)
Return the Header element specified by the index based on document order.

Parameters:
header - to the Header (starting with 0).
Returns:
Header element.

isTranslated

public boolean isTranslated()
Indicator for labels being translated. We do not do the translations here. We expect that the translation is done at the application level. This can therefore be used to decide if the document is already translated (so you don't need to do it over again.

see net.sf.jolene.struts.DomletAction for the struts implementation

Returns:
true if this document is translated

removeHeader

public Header removeHeader(int index)
Remove the headers

Parameters:
index - to the header in the document. Zero based in document order.
Returns:
The removed header object.

setDoctype

public void setDoctype(java.lang.String doctype)
Sets the doc type of the document.

Parameters:
doctype - The HTML doctype string.

setTitle

public void setTitle(java.lang.String string)
Set the document title.

Parameters:
string - The document title.

setTranslated

public void setTranslated(boolean translated)
Indicator for labels being translated. We do not do the translations here. We expect that the translation is done at the application level. This can therefore be used to decide if the document is already translated (so you don't need to do it over again. see net.sf.jolene.struts.DomletAction for the struts implementation

Parameters:
translated - set to true if the doc has been translated.

stream

public void stream(java.lang.String filename)
            throws java.io.IOException
Writes the document to the specified fileName.

Parameters:
filename - The filename to write to.
Throws:
java.io.IOException - if there's an IOException

stream

public void stream(java.io.Writer out)
            throws java.io.IOException
Writes the document to the specified Writer object and closes the Writer.

Parameters:
out - an output Writer to write to.
Throws:
java.io.IOException - it there's an IOException

toString

public java.lang.String toString()
Returns the document file name.

Overrides:
toString in class java.lang.Object
Returns:
String