com.ibm.as400.util.html

Class HTMLDocument

  • All Implemented Interfaces:
    HTMLTagElement, java.io.Serializable


    public class HTMLDocument
    extends HTMLTagAttributes
    implements java.io.Serializable
    The HTMLDocument class represents an HTML or an XSL-FO document. The document contains all information needed to display an HTML or an XSL-FO page.
      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>
      
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      HTMLDocument()
      Constructs a default HTMLDocument object.
      HTMLDocument(HTMLHead head)
      Constructs an HTMLDocument object with the specified HTMLHead.
    • Constructor Detail

      • HTMLDocument

        public HTMLDocument()
        Constructs a default HTMLDocument object.
      • HTMLDocument

        public HTMLDocument(HTMLHead head)
        Constructs an HTMLDocument object with the specified HTMLHead.
        Parameters:
        head - An HTMLHead object.
    • Method Detail

      • addElement

        public void addElement(HTMLTagElement tag)
        Adds a tag to the main body of the document.
        Parameters:
        tag - An HTMLTagElement object.
      • setHTMLHead

        public void setHTMLHead(HTMLHead head)
        Adds the <head> HTML tag or the page header for an XSL-FO page.
        Parameters:
        head - An HTMLHead object.
      • getHTMLHead

        public HTMLHead getHTMLHead()
        Returns an HTMLHead object for the page.
        Returns:
        The HTMLHead object.
      • addElement

        public void addElement(HTMLTagElement[] tag)
        Adds an array of tags to the document.
        Parameters:
        tag - An HTMLTagElement array.
      • getFOTag

        public java.lang.String getFOTag()
        Returns the tag for the XSL-FO document.
        Specified by:
        getFOTag in interface HTMLTagElement
        Returns:
        The tag.
      • getTag

        public java.lang.String getTag()
        Returns the tag for the HTML document.
        Specified by:
        getTag in interface HTMLTagElement
        Returns:
        The tag.
      • isUseFO

        public boolean isUseFO()
        Returns if Formatting Object tags are outputted. The default value is false.
        Returns:
        true if the output generated is an XSL formatting object, false if the output generated is HTML.
      • toString

        public java.lang.String toString()
        Returns a String representation for the Document tag.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The tag.
      • setPageHeight

        public void setPageHeight(double height)
        Sets the page-height of the XSL-FO page in inches. The default value is 11 inches.
        Parameters:
        height - The height.
      • setPageWidth

        public void setPageWidth(double width)
        Sets the page-width of the XSL-FO page in inches. The default value is 8.5 inches.
        Parameters:
        width - The width
      • setMarginTop

        public void setMarginTop(double top)
        Sets the top-margin of the XSL-FO page in inches. The default value is 0.5 inches.
        Parameters:
        top - The width of the top margin
      • setMarginBottom

        public void setMarginBottom(double bottom)
        Sets the bottom-margin of the XSL-FO page in inches. The default value is 0.5 inches.
        Parameters:
        bottom - The width of the bottom margin
      • setMarginRight

        public void setMarginRight(double right)
        Sets the right-margin of the XSL-FO page in inches. The default value is 0.5 inches.
        Parameters:
        right - The width of the right margin
      • setMarginLeft

        public void setMarginLeft(double left)
        Sets the left-margin of the XSL-FO page in inches. The default value is 0.5 inches.
        Parameters:
        left - The width of the left margin
      • removeElement

        public void removeElement(HTMLTagElement tag)
        Removes an HTMLTagElement from the document.
        Parameters:
        tag - The HTMLTagElement.
      • getPageHeight

        public double getPageHeight()
        Returns the height of the page in inches.
        Returns:
        The height.
      • getPageWidth

        public double getPageWidth()
        Returns the width of the page in inches.
        Returns:
        The width.
      • getMarginTop

        public double getMarginTop()
        Returns the top margin of the page in inches.
        Returns:
        The top margin.
      • getMarginBottom

        public double getMarginBottom()
        Returns the bottom margin of the page in inches.
        Returns:
        The bottom margin.
      • getMarginLeft

        public double getMarginLeft()
        Returns the left margin of the page in inches.
        Returns:
        The left margin.
      • getMarginRight

        public double getMarginRight()
        Returns the right margin of the page in inches.
        Returns:
        The right margin.
      • setUseFO

        public void setUseFO(boolean useFO)
        Sets if Formatting Object tags should be used. The default value is false.
        Parameters:
        useFO - - true if output generated is an XSL formatting object, false if the output generated is HTML.