org.dmonix.xml.html
Class HTMLGenerator

java.lang.Object
  extended byorg.dmonix.xml.XMLUtil
      extended byorg.dmonix.xml.html.HTMLGenerator

public class HTMLGenerator
extends XMLUtil

Utility class for creating HTML-formatted documents.
The output documents are based on standard XML, thus all elements will be correctly formatted.

Copyright: Copyright (c) 2004

Company: dmonix.org

Version:
1.0
Author:
Peter Nerg

Field Summary
protected  org.w3c.dom.Element bodyNode
           
protected  org.w3c.dom.Document doc
           
protected  org.w3c.dom.Element headNode
           
protected  org.w3c.dom.Element htmlNode
           
 
Constructor Summary
HTMLGenerator()
          Creates a new empty HTML document.
HTMLGenerator(java.io.File file)
          Creates a HTML document using an existing HTML document.
HTMLGenerator(java.net.URL url)
          Creates a HTML document using an existing HTML document.
 
Method Summary
 org.w3c.dom.Element addAnchor(org.w3c.dom.Element parent, java.lang.String href, java.lang.String text)
          Adds a hyper link.
 org.w3c.dom.Element addBR()
          Adds a <BR/> to the document body.
 org.w3c.dom.Element addBR(org.w3c.dom.Element parent)
          Adds a <BR/> to the provided element.
 org.w3c.dom.Element addElement(org.w3c.dom.Element parent, java.lang.String name)
          Add a new element.
 org.w3c.dom.Element addElement(org.w3c.dom.Element parent, java.lang.String name, ClassAttribute classAttribute)
          Add a new element.
 org.w3c.dom.Element addElement(org.w3c.dom.Element parent, java.lang.String name, ClassAttribute classAttribute, java.lang.String text)
          Add a new element.
 org.w3c.dom.Element addElement(org.w3c.dom.Element parent, java.lang.String name, java.lang.String text)
          Add a new element.
 org.w3c.dom.Element addElementToBody(java.lang.String name)
          Add a new element to the document body.
 org.w3c.dom.Element addElementToBody(java.lang.String name, ClassAttribute classAttribute)
          Add a new element to the document body.
 org.w3c.dom.Element addHR()
          Adds a <HR/> to the document body.
 org.w3c.dom.Element addHR(org.w3c.dom.Element parent)
          Adds a <HR/> to the provided element.
 org.w3c.dom.Element addIMG(org.w3c.dom.Element parent, java.lang.String src)
          Adds a <IMG/> to the document body.
 org.w3c.dom.Element addIMG(org.w3c.dom.Element parent, java.lang.String src, java.lang.String border)
          Adds a <IMG/> to the document body.
 org.w3c.dom.Element addMetaTag()
          Adds a <META/> to the document head.
 org.w3c.dom.Element addMetaTag(java.lang.String name, java.lang.String content)
          Adds a <META/> to the document head.
 void addMetaTagForNoCache()
          Add the meta tags for no cache.
 org.w3c.dom.Element addTable(org.w3c.dom.Element parent)
          Adds a <TABLE/> to the provided element.
 org.w3c.dom.Element addTable(org.w3c.dom.Element parent, ClassAttribute classAttribute)
          Add a table element.
 org.w3c.dom.Element addTD()
          Adds a <TD/> to the document body.
 org.w3c.dom.Element addTD(org.w3c.dom.Element parent)
          Adds a <TD/> to the provided element.
 org.w3c.dom.Element addTD(org.w3c.dom.Element parent, ClassAttribute classAttribute)
          Adds a <TD CLASS="[classAttribute]"/> to the provided element.
 org.w3c.dom.Element addTR()
          Adds a <TR/> to the document body.
 org.w3c.dom.Element addTR(org.w3c.dom.Element parent)
          Adds a <TR/> to the provided element.
 org.w3c.dom.Element createElement(java.lang.String name, ClassAttribute classAttribute)
          Create a new element.
 org.w3c.dom.Element getBodyElement()
          Get the <body> element;
 org.w3c.dom.Element getHeadElement()
          Get the <head> element;
 boolean getUseUpperCase()
          Returns if all the HTML tags are to be in upper case or not.
 void setClass(org.w3c.dom.Element parent, ClassAttribute classAttribute)
          Set the class attribute for the element.
 void setDocument(java.io.File file)
           
 void setDocument(java.net.URL url)
           
 void setText(org.w3c.dom.Element parent, java.lang.String text)
          Set the text content for a give element.
 void setUseUpperCase(boolean upperCase)
          Sets if all the HTML tags are to be in upper case or not.
 boolean toFile(java.io.File file)
          Write the HTML to a file.
 java.lang.String toString()
          Write the HTML to a string.
 
Methods inherited from class org.dmonix.xml.XMLUtil
appendChildElement, appendChildElement, appendChildElement, documentToFile, documentToFile, documentToHashtable, documentToStream, documentToStream, documentToString, documentToWriter, getChildElementByTagName, getCreateChildElementByTagName, getDocument, getDocument, getDocument, getDocument, getDocument, getElement, getElement, getElementValue, getElementValue, getElementValue, getElementValue, getFirstParameterValue, getFirstParameterValue, getParameters, getParameters, getTransformerProperty, isBlank, loadFromResource, newDocument, newDocument, nodeToStream, nodeToString, nodeToWriter, normalizeDocument, removeAllChildElements, saveToFile, saveToFile, setElementValue, setRootElement, setTransformerProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

doc

protected org.w3c.dom.Document doc

htmlNode

protected org.w3c.dom.Element htmlNode

headNode

protected org.w3c.dom.Element headNode

bodyNode

protected org.w3c.dom.Element bodyNode
Constructor Detail

HTMLGenerator

public HTMLGenerator()
Creates a new empty HTML document.


HTMLGenerator

public HTMLGenerator(java.io.File file)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Creates a HTML document using an existing HTML document.

Parameters:
file - The HTML document
Throws:
java.io.IOException
org.xml.sax.SAXException

HTMLGenerator

public HTMLGenerator(java.net.URL url)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Creates a HTML document using an existing HTML document.

Parameters:
url - The HTML document
Throws:
java.io.IOException
org.xml.sax.SAXException
Method Detail

setDocument

public void setDocument(java.io.File file)
                 throws java.io.IOException,
                        org.xml.sax.SAXException
Throws:
java.io.IOException
org.xml.sax.SAXException

setDocument

public void setDocument(java.net.URL url)
                 throws java.io.IOException,
                        org.xml.sax.SAXException
Throws:
java.io.IOException
org.xml.sax.SAXException

getUseUpperCase

public boolean getUseUpperCase()
Returns if all the HTML tags are to be in upper case or not.

Returns:
true if all tags are written in uppercase, false otherwise

setUseUpperCase

public void setUseUpperCase(boolean upperCase)
Sets if all the HTML tags are to be in upper case or not.

Parameters:
upperCase - true = upper case

addAnchor

public org.w3c.dom.Element addAnchor(org.w3c.dom.Element parent,
                                     java.lang.String href,
                                     java.lang.String text)
Adds a hyper link.
<A HREF="[href]">[text]</A>

Parameters:
parent - The parent element
href - The url
text - The text to display
Returns:
The new element

addBR

public org.w3c.dom.Element addBR()
Adds a <BR/> to the document body.

Returns:
The new element

addBR

public org.w3c.dom.Element addBR(org.w3c.dom.Element parent)
Adds a <BR/> to the provided element.

Parameters:
parent - The parent element
Returns:
The new element

addHR

public org.w3c.dom.Element addHR()
Adds a <HR/> to the document body.

Returns:
The new element

addHR

public org.w3c.dom.Element addHR(org.w3c.dom.Element parent)
Adds a <HR/> to the provided element.

Parameters:
parent - The parent element
Returns:
The new element

addIMG

public org.w3c.dom.Element addIMG(org.w3c.dom.Element parent,
                                  java.lang.String src)
Adds a <IMG/> to the document body.

Parameters:
parent - The parent element
src - The URL to the image
Returns:
The new element

addIMG

public org.w3c.dom.Element addIMG(org.w3c.dom.Element parent,
                                  java.lang.String src,
                                  java.lang.String border)
Adds a <IMG/> to the document body.

Parameters:
parent - The parent element
src - The URL to the image
border - The of the image
Returns:
The new element

addTD

public org.w3c.dom.Element addTD()
Adds a <TD/> to the document body.

Returns:
The new element

addTD

public org.w3c.dom.Element addTD(org.w3c.dom.Element parent)
Adds a <TD/> to the provided element.

Parameters:
parent - The parent element
Returns:
The new element

addTD

public org.w3c.dom.Element addTD(org.w3c.dom.Element parent,
                                 ClassAttribute classAttribute)
Adds a <TD CLASS="[classAttribute]"/> to the provided element.

Parameters:
parent - The parent element
classAttribute - the CLASS attribute
Returns:
The new element

addTR

public org.w3c.dom.Element addTR()
Adds a <TR/> to the document body.

Returns:
The new element

addTR

public org.w3c.dom.Element addTR(org.w3c.dom.Element parent)
Adds a <TR/> to the provided element.

Parameters:
parent - The parent element
Returns:
The new element

addMetaTag

public org.w3c.dom.Element addMetaTag()
Adds a <META/> to the document head.

Returns:
The new element

addMetaTag

public org.w3c.dom.Element addMetaTag(java.lang.String name,
                                      java.lang.String content)
Adds a <META/> to the document head.
<META name="[name]" content="[content]">

Parameters:
name - The name
content - The content
Returns:
The new element

addMetaTagForNoCache

public void addMetaTagForNoCache()
Add the meta tags for no cache.
These meta tags will force the browser to load the page for each access.
<META Http-Equiv="Cache-Control" Content="no-cache"/>
<META Http-Equiv="Pragma" Content="no-cache"/>
<META Http-Equiv="Expires" Content="0"/>


addElementToBody

public org.w3c.dom.Element addElementToBody(java.lang.String name)
Add a new element to the document body.

Parameters:
name - The name of the element
Returns:
The new element

addElementToBody

public org.w3c.dom.Element addElementToBody(java.lang.String name,
                                            ClassAttribute classAttribute)
Add a new element to the document body.

Parameters:
name - The name of the element
classAttribute - The CLASS attribute
Returns:
The new element

addElement

public org.w3c.dom.Element addElement(org.w3c.dom.Element parent,
                                      java.lang.String name)
Add a new element.

Parameters:
parent - The parent element
name - The name of the element
Returns:
The new element

addElement

public org.w3c.dom.Element addElement(org.w3c.dom.Element parent,
                                      java.lang.String name,
                                      java.lang.String text)
Add a new element.

Parameters:
parent - The parent element
name - The name of the element
text - The text content
Returns:
The new element

addElement

public org.w3c.dom.Element addElement(org.w3c.dom.Element parent,
                                      java.lang.String name,
                                      ClassAttribute classAttribute)
Add a new element.

Parameters:
parent - The parent element
name - The name of the element
classAttribute - The CLASS attribute
Returns:
The new element

addElement

public org.w3c.dom.Element addElement(org.w3c.dom.Element parent,
                                      java.lang.String name,
                                      ClassAttribute classAttribute,
                                      java.lang.String text)
Add a new element.

Parameters:
parent - The parent element
name - The name of the element
classAttribute - The CLASS attribute
text - The text content
Returns:
The new element

addTable

public org.w3c.dom.Element addTable(org.w3c.dom.Element parent)
Adds a <TABLE/> to the provided element.

Parameters:
parent - The parent element
Returns:
The new element

addTable

public org.w3c.dom.Element addTable(org.w3c.dom.Element parent,
                                    ClassAttribute classAttribute)
Add a table element.
<TABLE CLASS="[classAttribute]"/>

Parameters:
parent - The parent element
classAttribute - The CLASS attribute
Returns:
The new element

createElement

public org.w3c.dom.Element createElement(java.lang.String name,
                                         ClassAttribute classAttribute)
Create a new element.
<[name] CLASS="[classAttribute]"/>

Parameters:
name - The name of the element
classAttribute - The class attribute
Returns:
The new element

getBodyElement

public org.w3c.dom.Element getBodyElement()
Get the <body> element;

Returns:
The element

getHeadElement

public org.w3c.dom.Element getHeadElement()
Get the <head> element;

Returns:
The element

setClass

public void setClass(org.w3c.dom.Element parent,
                     ClassAttribute classAttribute)
Set the class attribute for the element.
<FOO CLASS="[classAttribute]"/>

Parameters:
parent - The element
classAttribute - The class attribute

setText

public void setText(org.w3c.dom.Element parent,
                    java.lang.String text)
Set the text content for a give element. <FOO>[text]</FOO>

Parameters:
parent - The element
text - The text to set

toString

public java.lang.String toString()
Write the HTML to a string.

Returns:
The String

toFile

public boolean toFile(java.io.File file)
Write the HTML to a file.

Parameters:
file - The output file
Returns:
The result of the operation, true if successful false otherwise


Copyright © 1998-2005 dmonix.org Peter Nerg, All Rights Reserved.