Ontimize 5.2072EN

com.ontimize.printing
Class HTMLProcessor

java.lang.Object
  extended bycom.ontimize.printing.HTMLProcessor

public class HTMLProcessor
extends java.lang.Object

Class to parse HTML code. This class can use the html string or the path of a html file.
It allows to replace some keys in the text with other string values. It does not allow page break


Field Summary
static java.lang.String CELL_HEAD_TAG
           
static java.lang.String CELL_TAG
           
protected  java.lang.String code
           
static boolean DEBUG
           
protected  javax.swing.text.html.HTMLDocument document
           
protected  javax.swing.text.html.HTMLEditorKit editor
           
static java.lang.String END_CELL_HEAD_TAG
           
static java.lang.String END_CELL_TAG
           
static java.lang.String END_ROW_TAG
           
static java.lang.String END_TABLE_TAG
           
protected  java.lang.String footId
           
protected  java.lang.String headId
           
static java.lang.String ROW_TAG
           
static java.lang.String TABLE_TAG
           
protected  javax.swing.JTextPane textPane
           
 
Constructor Summary
HTMLProcessor(java.lang.String htmlCode, java.net.URL base)
          Creates a processor class using the html code
HTMLProcessor(java.net.URL fileURL)
          Builds a new processor using the html file with the specified URL
HTMLProcessor(java.net.URL fileURL, java.net.URL base)
          Builds a new processor using the file with the specified URL
 
Method Summary
 void advancedPrint(java.awt.print.PageFormat pf, int height)
           
 javax.swing.text.html.HTMLDocument getDocument()
          Get the document used for this processor to can use it in a text panel
 javax.swing.text.html.HTMLEditorKit getEditorKit()
          Get the EditorKit used for this processor to can use it in a text panel
 java.lang.String getHTML()
           
 javax.swing.JTextPane getJTextPane()
          Get a JTextPanel with the current document text The processor save a reference to the returned panel
 java.awt.print.Printable getPrintable(java.awt.print.PageFormat pf, int height)
           
 java.lang.String insertTable(java.lang.String text, java.util.Hashtable tableValues)
           
 java.lang.String insertTable(java.lang.String text, java.util.Hashtable tableValues, java.util.Vector sortColumns)
          Insert a table using its values, replacing in the html code the key word text with the table HTML equivalence.
 void print(java.awt.print.PageFormat pf, int height)
           
 void replaceTextInHTML(java.lang.String text, byte[] imageBytes, int width, int height)
          Replace the text in the html code with the image represented by the bytes array.
 void replaceTextInHTML(java.lang.String text, java.lang.String newText)
          Replaces the text in the string HTML with the newText
This replaces the code in the same html code and this method must be used carefully.
 void reset()
          Undo all the changes in the html code and set the original value again
 void setFoot(java.lang.String id)
          Fixes the element with attribute id as footer in the template for all the pages.If the element has children the children will be in the footer too.
 void setHead(java.lang.String id)
          Fixes the element with attribute id as header in the template for all the pages.
 java.util.Vector toPages(java.awt.print.PageFormat pageFormat)
          Gets a vector of JTextPane with the document separated by pages with the specified page format.
 void updateTextPane()
          Update the values of the JTextPane with the last changes in the HTML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

TABLE_TAG

public static final java.lang.String TABLE_TAG
See Also:
Constant Field Values

ROW_TAG

public static final java.lang.String ROW_TAG
See Also:
Constant Field Values

CELL_HEAD_TAG

public static final java.lang.String CELL_HEAD_TAG
See Also:
Constant Field Values

CELL_TAG

public static final java.lang.String CELL_TAG
See Also:
Constant Field Values

END_ROW_TAG

public static final java.lang.String END_ROW_TAG
See Also:
Constant Field Values

END_CELL_HEAD_TAG

public static final java.lang.String END_CELL_HEAD_TAG
See Also:
Constant Field Values

END_CELL_TAG

public static final java.lang.String END_CELL_TAG
See Also:
Constant Field Values

END_TABLE_TAG

public static final java.lang.String END_TABLE_TAG
See Also:
Constant Field Values

code

protected java.lang.String code

document

protected javax.swing.text.html.HTMLDocument document

editor

protected javax.swing.text.html.HTMLEditorKit editor

textPane

protected javax.swing.JTextPane textPane

headId

protected java.lang.String headId

footId

protected java.lang.String footId
Constructor Detail

HTMLProcessor

public HTMLProcessor(java.lang.String htmlCode,
                     java.net.URL base)
              throws java.lang.Exception
Creates a processor class using the html code

Parameters:
htmlCode -
base -
Throws:
java.lang.Exception

HTMLProcessor

public HTMLProcessor(java.net.URL fileURL,
                     java.net.URL base)
              throws java.lang.Exception
Builds a new processor using the file with the specified URL

Parameters:
fileURL -
base -
Throws:
java.lang.Exception

HTMLProcessor

public HTMLProcessor(java.net.URL fileURL)
              throws java.lang.Exception
Builds a new processor using the html file with the specified URL

Parameters:
fileURL -
Throws:
java.lang.Exception
Method Detail

replaceTextInHTML

public void replaceTextInHTML(java.lang.String text,
                              java.lang.String newText)
Replaces the text in the string HTML with the newText
This replaces the code in the same html code and this method must be used carefully.

Parameters:
text - Text to replace
newText - New text to set

replaceTextInHTML

public void replaceTextInHTML(java.lang.String text,
                              byte[] imageBytes,
                              int width,
                              int height)
Replace the text in the html code with the image represented by the bytes array.
If width or height are 0 then the image size will be the real
With values different from 0 this method scales the image. The method replaces te values in the html code and must be used carefully

Parameters:
text -
imageBytes -
width -
height -

getEditorKit

public javax.swing.text.html.HTMLEditorKit getEditorKit()
Get the EditorKit used for this processor to can use it in a text panel

Returns:

getDocument

public javax.swing.text.html.HTMLDocument getDocument()
Get the document used for this processor to can use it in a text panel

Returns:

getHTML

public java.lang.String getHTML()

getJTextPane

public javax.swing.JTextPane getJTextPane()
Get a JTextPanel with the current document text The processor save a reference to the returned panel

Returns:

updateTextPane

public void updateTextPane()
Update the values of the JTextPane with the last changes in the HTML


reset

public void reset()
           throws java.lang.Exception
Undo all the changes in the html code and set the original value again

Throws:
java.lang.Exception

insertTable

public java.lang.String insertTable(java.lang.String text,
                                    java.util.Hashtable tableValues,
                                    java.util.Vector sortColumns)
Insert a table using its values, replacing in the html code the key word text with the table HTML equivalence.

Parameters:
text -
tableValues - The keys of this hashtable are the names of the table columns and the values are vectors whit the column values. If some of these values are hashtables then they are new tables in the appropriate cell.
sortColumns - This vector contains the name of the table columns in the order to put them in the table. These columns must be the keys of the tableValues hashtable
Returns:

insertTable

public java.lang.String insertTable(java.lang.String text,
                                    java.util.Hashtable tableValues)

toPages

public java.util.Vector toPages(java.awt.print.PageFormat pageFormat)
Gets a vector of JTextPane with the document separated by pages with the specified page format.

Parameters:
pageFormat -
Returns:

print

public void print(java.awt.print.PageFormat pf,
                  int height)

setHead

public void setHead(java.lang.String id)
Fixes the element with attribute id as header in the template for all the pages. If the element has children the children will be in the header too.

Parameters:
id -

setFoot

public void setFoot(java.lang.String id)
Fixes the element with attribute id as footer in the template for all the pages.If the element has children the children will be in the footer too.

Parameters:
id -

advancedPrint

public void advancedPrint(java.awt.print.PageFormat pf,
                          int height)
Parameters:
pf - Page format to use in the printing method
height - Height in pixels from the text pane of this processor

getPrintable

public java.awt.print.Printable getPrintable(java.awt.print.PageFormat pf,
                                             int height)

Ontimize