Methods | Fields | This Package | All Packages

DhHTMLGenerator Class

Represents a base class for Hypertext Markup Language (HTML) generation.

package com.ms.wfc.html

public class DhHTMLGenerator

Remarks

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.

The following is an example of a simple alternate generator that maps some cascading style sheet styles to format tags and changes any <DIV> tags to <P> tags:

public class MyHTMLGenerator {
    public final static STYLE_FONT_WEIGHT = 0;
    public final static STYLE_FONT_STYLE = 1;
    public final static TAG_DIV = 2;

    public MyHTMLGenerator(){
       registerName("font-weight", STYLE_FONT_WEIGHT );
       registerName("font-style", STYLE_FONT_STYLE );
       registerName( "DIV",TAG_DIV );
    }

    // Override this method to replace tags.
    public boolean onTagGenerate( int key, String strTagName ){
       switch ( key ){ 
          case TAG_DIV:
             setTagName( "P" );
             // Return false to cancel the default behavior.
             return false;
             break;
          }
        // Return true to proceed with the default behavior.
        return true;
    } 

    // Override this method to manipulate style output.
    public boolean onStyleGenerate( int key, String styleName, String styleValue ){
       switch ( key ){
          case STYLE_FONT_WEIGHT:
             if ( styleValue.indexOf( "BOLD" ) != -1 ){
                addEnclosingTag( "B", null, true );
                return false;
             }
             break;
          case STYLE_FONT_STYLE:
             if ( styleValue.equalsIgnoreCase( "ITALIC" ) ){
                addEnclosingTag( "I", null, true );
                return false;
             } 
             break;
       }
       return true;
    }
}