public class HTMLDocument extends HTMLTagAttributes implements java.io.Serializable
The following java program creates an HTMLDocument:
package com.ibm.as400.util.html;
import java.*;
import java.io.*;
import java.lang.*;
import java.beans.PropertyVetoException;
public class FoFile
{
public static void main (String[] args)
{
//Create the HTMLDocument that holds necessary document properties
HTMLDocument fo = new HTMLDocument();
//Set page and margin properties. Numbers are in inches.
fo.setPageWidth(8.5);
fo.setPageHeight(11);
fo.setMarginTop(1);
fo.setMarginBottom(1);
fo.setMarginLeft(1);
fo.setMarginRight(1);
//Create a header for the page.
HTMLHead head = new HTMLHead();
//Set the title for the header
head.setTitle("This is the page header.");
//Create several headings
HTMLHeading h1 = new HTMLHeading(1, "Heading 1");
HTMLHeading h2 = new HTMLHeading(2, "Heading 2");
HTMLHeading h3 = new HTMLHeading(3, "Heading 3");
HTMLHeading h4 = new HTMLHeading(4, "Heading 4");
HTMLHeading h5 = new HTMLHeading(5, "Heading 5");
HTMLHeading h6 = new HTMLHeading(6, "Heading 6");
//Create some text that is printed from right to left.
//Create BidiOrdering object and set the direction
BidiOrdering bdo = new BidiOrdering();
bdo.setDirection(HTMLConstants.RTL);
//Create some text
HTMLText text = New HTMLText("This is Arabic text.");
//Add the text to the bidi-ordering object and get XSL-FO tag
bdo.addItem(text);
//Add the HTMLHead
fo.setHTMLHead(head);
//Add the items to the document
fo.addElement(h1);
fo.addElement(h2);
fo.addElement(h3);
fo.addElement(h4);
fo.addElement(h5);
fo.addElement(h6);
fo.addElement(bdo);
//Print the Formatting Object tag.
System.out.println(fo.getFOTag());
//Print the HTML Object tag.
System.out.println(fo.getTag());
}
}
Here is the output generated by the above program:
<fo:root xmlns:fo = 'http://www.w3.org/1999/XSL/Format'>
<fo:layout-master-set>
<fo:simple-page-master master-name='body-page' writing-mode='lr-tb' page-width='8.5in' page-height='11.0in' margin-top='1.0in' margin-bottom='1.0in' margin-left='1.0in' margin-right='1.0in'>
<fo:region-body region-name='xsl-region-body'/>
<fo:region-before region-name='xsl-region-before' precedence='true' extent='1.0in'/>
<fo:region-after region-name='xsl-region-after' precedence='true' extent='1.0in'/>
<fo:region-start region-name='xsl-region-start' extent='1.0in'/>
<fo:region-end region-name='xsl-region-end' extent='1.0in'/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-name='body-page'>
<fo:flow flow-name='xsl-region-body'>
<fo:block-container writing-mode='lr'>
<fo:block font-size='25pt'>Heading 1</fo:block>
</fo:block-container>
<fo:block-container writing-mode='lr'>
<fo:block font-size='20pt'>Heading 2</fo:block>
</fo:block-container>
<fo:block-container writing-mode='lr'>
<fo:block font-size='15pt'>Heading 3</fo:block>
</fo:block-container>
<fo:block-container writing-mode='lr'>
<fo:block font-size='13pt'>Heading 4</fo:block>
</fo:block-container>
<fo:block-container writing-mode='lr'>
<fo:block font-size='11pt'>Heading 5</fo:block>
</fo:block-container>
<fo:block-container writing-mode='lr'>
<fo:block font-size='9pt'>Heading 6</fo:block>
</fo:block-container>
<fo:block-container writing-mode='rl'>
<fo:block>This is Arabic text.</fo:block>
</fo:block-container>
</fo:flow>
<fo:static-content flow-name='xsl-region-before'>
<fo:block-container>
This is the page header.</fo:block-container>
</fo:static-content>
</fo:page-sequence>
</fo:root>
<html>
<head>
<title>This is the page header.</title>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<bdo dir="rtl">
This is Arabic text.
</bdo>
</body>
</html>
| Constructor and Description |
|---|
HTMLDocument()
Constructs a default HTMLDocument object.
|
HTMLDocument(HTMLHead head)
Constructs an HTMLDocument object with the specified HTMLHead.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addElement(HTMLTagElement tag)
Adds a tag to the main body of the document.
|
void |
addElement(HTMLTagElement[] tag)
Adds an array of tags to the document.
|
void |
addListener(ElementListener listener)
Adds an ElementListener for the tag
The ElementListener object is added to an internal list of tag Listeners;
it can be removed with removeListener.
|
java.lang.String |
getFOTag()
Returns the tag for the XSL-FO document.
|
HTMLHead |
getHTMLHead()
Returns an HTMLHead object for the page.
|
double |
getMarginBottom()
Returns the bottom margin of the page in inches.
|
double |
getMarginLeft()
Returns the left margin of the page in inches.
|
double |
getMarginRight()
Returns the right margin of the page in inches.
|
double |
getMarginTop()
Returns the top margin of the page in inches.
|
double |
getPageHeight()
Returns the height of the page in inches.
|
double |
getPageWidth()
Returns the width of the page in inches.
|
java.lang.String |
getTag()
Returns the tag for the HTML document.
|
boolean |
isUseFO()
Returns if Formatting Object tags are outputted.
|
void |
removeElement(HTMLTagElement tag)
Removes an HTMLTagElement from the document.
|
void |
removeListener(ElementListener listener)
Removes this tags ElementListener from the internal list.
|
void |
setHTMLHead(HTMLHead head)
Adds the <head> HTML tag or the page header for an XSL-FO page.
|
void |
setMarginBottom(double bottom)
Sets the bottom-margin of the XSL-FO page in inches.
|
void |
setMarginLeft(double left)
Sets the left-margin of the XSL-FO page in inches.
|
void |
setMarginRight(double right)
Sets the right-margin of the XSL-FO page in inches.
|
void |
setMarginTop(double top)
Sets the top-margin of the XSL-FO page in inches.
|
void |
setPageHeight(double height)
Sets the page-height of the XSL-FO page in inches.
|
void |
setPageWidth(double width)
Sets the page-width of the XSL-FO page in inches.
|
void |
setUseFO(boolean useFO)
Sets if Formatting Object tags should be used.
|
java.lang.String |
toString()
Returns a String representation for the Document tag.
|
addPropertyChangeListener, getAttributes, getAttributeString, removePropertyChangeListener, setAttributespublic HTMLDocument()
public HTMLDocument(HTMLHead head)
head - An HTMLHead object.public void addElement(HTMLTagElement tag)
tag - An HTMLTagElement object.public void setHTMLHead(HTMLHead head)
head - An HTMLHead object.public HTMLHead getHTMLHead()
public void addElement(HTMLTagElement[] tag)
tag - An HTMLTagElement array.public java.lang.String getFOTag()
getFOTag in interface HTMLTagElementpublic java.lang.String getTag()
getTag in interface HTMLTagElementpublic boolean isUseFO()
public java.lang.String toString()
toString in class java.lang.Objectpublic void removeListener(ElementListener listener)
listener - The ElementListener.addListener(com.ibm.as400.util.html.ElementListener)public void addListener(ElementListener listener)
listener - The ElementListener.removeListener(com.ibm.as400.util.html.ElementListener)public void setPageHeight(double height)
height - The height.public void setPageWidth(double width)
width - The widthpublic void setMarginTop(double top)
top - The width of the top marginpublic void setMarginBottom(double bottom)
bottom - The width of the bottom marginpublic void setMarginRight(double right)
right - The width of the right marginpublic void setMarginLeft(double left)
left - The width of the left marginpublic void removeElement(HTMLTagElement tag)
tag - The HTMLTagElement.public double getPageHeight()
public double getPageWidth()
public double getMarginTop()
public double getMarginBottom()
public double getMarginLeft()
public double getMarginRight()
public void setUseFO(boolean useFO)
useFO - - true if output generated is an XSL formatting object, false if the output generated is HTML.