DhHTMLGenerator Class

DhHTMLGenerator Class

This Package | All Packages

public class DhHTMLGenerator

Represents a base class for HTML generation. Override this class to create alternate HTML generations from the package. Call DhElement.setHTMLGenerator with an instance of your override to enable. On each tag, style, and attribute, the appropriate function is called, and you can manipulate the element in any way you choose.

Fields
Name Description
UNKNOWN_KEY This value is returned by getNameKey if the name is not registered.

Methods
Name Description
addAttrString( String strAttr, String strValue ) Adds an attribute inside the current tag's less than (<) and greater than (>) brackets.
addEnclosingTag( String strTag, String strAttrs, boolean fClose ) Adds an enclosing tag around the current tag.
addInnerTag( String strTag, String strAttrs, boolean fClose ) Adds an inner tag inside the current tag, but encloses its contents.
addStyleString( String strStyle, String strValue ) Adds an attribute inside the current tag's "STYLE=" attribute.
generateHTML( DhElement e ) Generates browser-targeted HTML for the specified DhElement.
getAttributeValue( String strAttrName ) Retrieves the value of a specified attribute.
getContent() Retrieves the current content string.
getNameKey( String strName ) Returns the integer key associated with the given name.
getStyleValue( String strStyleName ) Retrieves the value of a specified style.
getSupportsCSS() Retrieves target's ability to support cascading style sheets.
getSupportsOM() Retrieves the target's ability to support the Document Object Model.
getTagName() Retreives the tag name for the current generation.
onAttrGenerate( String strName, String strValue ) Called for each attribute[,value] pair.
onAttrGenerate( int key, String strName, String strValue ) Topic under construction.
onStyleGenerate( int key, String strName, String strValue ) Called for each style-attribute[,value] pair.
onStyleGenerate( String strName, String strValue ) Topic under construction.
onTagGenerate( int key, String strTagName ) Called with the default name for the current tag.
onTagGenerate( String strTagName ) Topic under construction.
registerName( String strName, int key ) Use this function to associate an integer value with a style or attribute name or tag.
setContent( String strNewContent ) Replaces the current content, destroying any existing content.
setFormatItems( char cAttrAssign, char cAttrSeparator, char cAttrQuote, char cStyleAssign, char cStyleSeparator, char cStyleQuote ) Sets the delimeter items.
setSupportsCSS( boolean supportsCSS ) Specifies whether the target browser supports style sheets.
setSupportsOM( boolean supportsOM ) Specifies whether the target browser supports an object model.
setTagName( String strNewName ) Replaces the current tag name with the new value.

Fields

DhHTMLGenerator.UNKNOWN_KEY

Syntax
public static final int UNKNOWN_KEY;
Description
This value is returned by getNameKey if the name is not registered.

Methods

DhHTMLGenerator.addAttrString

Syntax
protected final synchronized void addAttrString( String strAttr, String strValue );
Parameters
strAttr
The name of the attribute to add.
strValue
The string value of the new attribute.
Description

Adds an attribute inside the current tag's less than (<) and greater than (>) brackets.

DhHTMLGenerator.addEnclosingTag

Syntax
protected synchronized final void addEnclosingTag( String strTag, String strAttrs, boolean fClose );
Parameters
strTag
The new enclosing tag name.
strAttrs
The new enclosing tag's attribute string or strings.
fClose
Set to true to additionally add the closing tag for this tag.
Description

Adds an enclosing tag around the current tag. This tag also encloses any existing enclosing tags.

DhHTMLGenerator.addInnerTag

Syntax
protected synchronized final void addInnerTag( String strTag, String strAttrs, boolean fClose );
Parameters
strTag
The new inner tag name.
strAttrs
The new inner tag's attribute string(s).
fClose
true
Description

Adds an inner tag inside the current tag, but encloses its contents. This tag appears between the contents and any existing inner tags.

DhHTMLGenerator.addStyleString

Syntax
protected final synchronized void addStyleString( String strStyle, String strValue );
Parameters
strAttr
The name of the style to add.
strValue
The String value of the new style.
Description

Adds an attribute inside the current tag's "STYLE=" attribute. These styles are emitted only if supportsCSS is true.

See Also
getSupportsCSS, setSupportsCSS

DhHTMLGenerator.generateHTML

Syntax
public synchronized StringBuffer generateHTML( DhElement e );
Parameters
e
The DhElement to generate code for based on this DhHTMLGenerator.
Return Value

Returns a StringBuffer with the generated HTML.

Description

Generates browser-targeted HTML for the specified DhElement.

DhHTMLGenerator.getAttributeValue

Syntax
protected final String getAttributeValue( String strAttrName );
Parameters
strAttrName
The name of the attribute.
Return Value

Returns s the value of the attribute, or returns null if it is not present.

Description

Retrieves the value of a specified attribute.

DhHTMLGenerator.getContent

Syntax
protected final String getContent();
Return Value

Returns the current content string.

Description

Retrieves the current content string.

DhHTMLGenerator.getNameKey

Syntax
protected int getNameKey( String strName );
Parameters
strName
The name of the tag, attribute, or style to retrieve a key for.
Return Value

Returns the key for the name, or returns UNKNOWN_KEY if it is not present.

Description

Returns the integer key associated with the given name. This function is not case sensitive.

See Also
registerName, UNKNOWN_KEY

DhHTMLGenerator.getStyleValue

Syntax
protected final String getStyleValue( String strStyleName );
Parameters
strStyleName
The name of the style.
Return Value

Returns s the value of the style, or returns null if it is not present.

Description

Retrieves the value of a specified style.

DhHTMLGenerator.getSupportsCSS

Syntax
public final boolean getSupportsCSS();
Return Value

Returns true if cascading style sheets are supported.

Description

Retrieves target's ability to support cascading style sheets.

DhHTMLGenerator.getSupportsOM

Syntax
public final boolean getSupportsOM();
Return Value

Returns true if the Document Object Model is supported (currently Microsoft Internet Explorer version 4.0 or later only)

Description

Retrieves the target's ability to support the Document Object Model.

DhHTMLGenerator.getTagName

Syntax
protected final String getTagName();
Return Value

Returns the current tag name string.

Description

Retreives the tag name for the current generation.

DhHTMLGenerator.onAttrGenerate

Syntax 1
public boolean onAttrGenerate( String strName, String strValue );
Parameters
strName
The default name of the attribute.
strValue
The default value for the attribute.
Return Value

Returns true to generate the default tag, or returns false to skip it.

Description

Called for each attribute[,value] pair. You can perform any desired additions or manipulations for the specified attribute. The following is an example of moving WIDTH attribute into style text:

  
if ( strName.equalsIgnoreCase( "WIDTH" ) ){
  addStyleString( "width", strValue );
  return false;
}

See Also
addEnclosingTag, addInnerTag, addStyleString, addAttrString



Syntax 2
public boolean onAttrGenerate( int key, String strName, String strValue );
Description

Topic under construction.

DhHTMLGenerator.onStyleGenerate

Syntax 1
public boolean onStyleGenerate( int key, String strName, String strValue );
Parameters
key
The key for this style, if registered; otherwise, -1.
strName
The default name of the attribute.
strValue
The default value for the attribute.
Return Value

Returns true to generate the default tag, or returns false to skip it.

Description

Called for each style-attribute[,value] pair. You can perform any desired additions or manipulations for the specified style.

The following is an example of non-CSS-compatible code for font color:

  
if ( strName.equalsIgnoreCase( "color" ) ){
  addEnclosingTag( "FONT", "COLOR=" + strValue );
  return false;
}

See Also
addEnclosingTag, addInnerTag, addStyleString, addAttrString



Syntax 2
public boolean onStyleGenerate( String strName, String strValue );
Description

Topic under construction.

DhHTMLGenerator.onTagGenerate

Syntax 1
public boolean onTagGenerate( int key, String strTagName );
Parameters
key
The key for this tag, if registered; otherwise, -1.
strTagName
The default name for the current tag.
Return Value

Returns true to use the default tag.

Description

Called with the default name for the current tag. You can perform any desired operations within your override.

The following is an example of replacing <STRONG> with <BOLD>

  
if ( strTagName.equalsIgnoreCase( "STRONG" ) ){
  setTagName( "BOLD" );
  return false;
}

See Also
setTagName, getTagName



Syntax 2
public boolean onTagGenerate( String strTagName );
Description

Topic under construction.

DhHTMLGenerator.registerName

Syntax
protected boolean registerName( String strName, int key );
Parameters
strName
The tag, attribute name, or style name.
key
The key you want to associate with that value. It cannot be -1.
Return Value

Returns true if the name was successfully registered, or returns false if -1 is used or the key is already assigned to another name.

Description

Use this function to associate an integer value with a style or attribute name or tag. If registered, you will receive this value with the name in calls to onTagGenerate, onAttrGenerate, and onStyleGenerate. Registering a key allows you to avoid string comparison in your handler functions.

Note: key cannot be -1;

Example:


public class MyHTMLGenerator{
		public final static TAG_BR = 0;
     public final static TAG_DIV = 1;
	 
		public MyHTMLGenerator(){
			registerName( "BR", TAG_BR );
			registerName( "DIV", TAG_DIV );
		}
			
		// ...
		public boolean onTagGenerate( int key, String strTagName ){
			switch ( key ){
				case TAG_BR:
				case TAG_DIV:
					setTagName( "P" );
					return false;
				break;
			}
			return true;
		}

		
}

DhHTMLGenerator.setContent

Syntax
protected final synchronized void setContent( String strNewContent );
Parameters
strNewContent
The new content string.
Description

Replaces the current content, destroying any existing content.

DhHTMLGenerator.setFormatItems

Syntax
public final synchronized void setFormatItems( char cAttrAssign, char cAttrSeparator, char cAttrQuote, char cStyleAssign, char cStyleSeparator, char cStyleQuote );
Parameters
cAttrAssign
Assignment character for attributes (default is '=').
cAttrSeparator
Separator character between attributes (default is ' ').
cAttrQuote
Delimiter to place around attribute values (default is '"').
cStyleAssign
Assignment character for styles (default is ':').
cStyleSeparator
Separator character between styles (default is ';').
cStyleQuote
Delimiter to place around style values (default is "'").
Description

Sets the delimeter items.

DhHTMLGenerator.setSupportsCSS

Syntax
public synchronized final void setSupportsCSS( boolean supportsCSS );
Parameters
supportsCSS
true
Description

Specifies whether the target browser supports style sheets. The default is false.

DhHTMLGenerator.setSupportsOM

Syntax
public synchronized final void setSupportsOM( boolean supportsOM );
Parameters
supportsOM
true
Description

Specifies whether the target browser supports an object model. The default is false.

DhHTMLGenerator.setTagName

Syntax
protected final synchronized void setTagName( String strNewName );
Parameters
strNewName
The replacement tag name, which can be null.
Description

Replaces the current tag name with the new value.