215 lines
8.5 KiB
HTML
215 lines
8.5 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="Example: Using HTMLDocument to generate both HTML source and XSL FO source" />
|
|
<meta name="abstract" content="" />
|
|
<meta name="description" content="" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="htmldocumenthtmlexmpl" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Example: Using HTMLDocument to generate both HTML source and XSL FO
|
|
source</title>
|
|
</head>
|
|
<body id="htmldocumenthtmlexmpl"><a name="htmldocumenthtmlexmpl"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Example: Using HTMLDocument to generate both HTML source and XSL FO
|
|
source</h1>
|
|
<div><p></p>
|
|
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
|
|
example disclaimer</a> for important legal information.</div>
|
|
<pre>///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Example: Using the Toolbox HTMLDocument Class
|
|
// to generate both HTML and XSL FO source data.
|
|
//
|
|
// This program uses the HTMLDocument class to
|
|
// generate two files: one that has HTML source and
|
|
// another than has XSL FO source.
|
|
//
|
|
// Command syntax:
|
|
// HTMLDocumentExample
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
import com.ibm.as400.util.html.*;
|
|
import java.*;
|
|
import java.io.*;
|
|
import java.lang.*;
|
|
import java.beans.PropertyVetoException;
|
|
|
|
public class HTMLDocumentExample
|
|
{
|
|
public static void main (String[] args)
|
|
{
|
|
//Create the HTMLDocument that holds necessary document properties
|
|
HTMLDocument doc = new HTMLDocument();
|
|
|
|
//Set page and margin properties. Numbers are in inches.
|
|
doc.setPageWidth(8.5);
|
|
doc.setPageHeight(11);
|
|
doc.setMarginTop(1);
|
|
doc.setMarginBottom(1);
|
|
doc.setMarginLeft(1);
|
|
doc.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
|
|
bdo.addItem(text);
|
|
|
|
// Create an UnorderedList.
|
|
UnorderedList uList = new UnorderedList(HTMLConstants.SQUARE);
|
|
// Create and set the data for UnorderedListItems.
|
|
UnorderedListItem listItem1 = new UnorderedListItem();
|
|
UnorderedListItem listItem2 = new UnorderedListItem();
|
|
listItem1.setItemData(new HTMLText("First item"));
|
|
listItem2.setItemData(new HTMLText("Second item"));
|
|
// Add the list items to the UnorderedList.
|
|
uList.addListItem(listItem1);
|
|
uList.addListItem(listItem2);
|
|
|
|
// Create an OrderedList.
|
|
OrderedList oList = new OrderedList(HTMLConstants.SMALL_ROMAN);
|
|
// Create the OrderedListItems.
|
|
OrderedListItem olistItem1 = new OrderedListItem();
|
|
OrderedListItem olistItem2 = new OrderedListItem();
|
|
OrderedListItem olistItem3 = new OrderedListItem();
|
|
// Set the data in the OrderedListItems.
|
|
olistItem1.setItemData(new HTMLText("First item"));
|
|
olistItem2.setItemData(new HTMLText("Second item"));
|
|
olistItem3.setItemData(new HTMLText("Third item"));
|
|
// Add the list items to the OrderedList.
|
|
oList.addListItem(olistItem1);
|
|
oList.addListItem(olistItem2);
|
|
// Add (nest) the unordered list to OrderedListItem2
|
|
oList.addList(uList);
|
|
// Add another OrderedListItem to the OrderedList
|
|
// after the nested UnorderedList.
|
|
oList.addListItem(olistItem3);
|
|
|
|
// Create a default HTMLTable object.
|
|
HTMLTable table = new HTMLTable();
|
|
try
|
|
{
|
|
// Set the table attributes.
|
|
table.setAlignment(HTMLTable.LEFT);
|
|
table.setBorderWidth(1);
|
|
|
|
// Create a default HTMLTableCaption object and set the caption text.
|
|
HTMLTableCaption caption = new HTMLTableCaption();
|
|
caption.setElement("Customer Account Balances - January 1, 2000");
|
|
|
|
// Set the caption.
|
|
table.setCaption(caption);
|
|
|
|
// Create the table headers and add to the table.
|
|
HTMLTableHeader account_header = new HTMLTableHeader(new HTMLText("ACCOUNT"));
|
|
HTMLTableHeader name_header = new HTMLTableHeader(new HTMLText("NAME"));
|
|
HTMLTableHeader balance_header = new HTMLTableHeader(new HTMLText("BALANCE"));
|
|
|
|
table.addColumnHeader(account_header);
|
|
table.addColumnHeader(name_header);
|
|
table.addColumnHeader(balance_header);
|
|
|
|
// Add rows to the table. Each customer record represents a row in the table.
|
|
int numCols = 3;
|
|
for (int rowIndex=0; rowIndex< 5; rowIndex++)
|
|
{
|
|
HTMLTableRow row = new HTMLTableRow();
|
|
row.setHorizontalAlignment(HTMLTableRow.CENTER);
|
|
|
|
HTMLText account = new HTMLText("000" + rowIndex);
|
|
HTMLText name = new HTMLText("Customer" + rowIndex);
|
|
HTMLText balance = new HTMLText("" + (rowIndex + 1)*200);
|
|
|
|
row.addColumn(new HTMLTableCell(account));
|
|
row.addColumn(new HTMLTableCell(name));
|
|
row.addColumn(new HTMLTableCell(balance));
|
|
|
|
// Add the row to the table.
|
|
table.addRow(row);
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
System.out.println("Problem creating table");
|
|
System.exit(0);
|
|
}
|
|
|
|
//Add the items to the HTMLDocument
|
|
doc.addElement(head);
|
|
doc.addElement(h1);
|
|
doc.addElement(h2);
|
|
doc.addElement(h3);
|
|
doc.addElement(h4);
|
|
doc.addElement(h5);
|
|
doc.addElement(h6);
|
|
doc.addElement(oList);
|
|
doc.addElement(table);
|
|
doc.addElement(bdo);
|
|
|
|
//Print the fo tags to a file.
|
|
try
|
|
{
|
|
FileOutputStream fout = new FileOutputStream("FOFILE.fo");
|
|
PrintStream pout = new PrintStream(fout);
|
|
pout.println(doc.getFOTag());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.out.println("Unable to write fo tags to FOFILE.fo");
|
|
}
|
|
|
|
//Print the html tags to a file
|
|
try
|
|
{
|
|
FileOutputStream htmlout = new FileOutputStream("HTMLFILE.html");
|
|
PrintStream phtmlout = new PrintStream(htmlout);
|
|
phtmlout.println(doc.getTag());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.out.println("Unable to write html tags to HTMLFILE.html");
|
|
}
|
|
|
|
}
|
|
}</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |