Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.nwalsh.saxon
Class Table  view Table download Table.java

java.lang.Object
  extended bycom.nwalsh.saxon.Table

public class Table
extends java.lang.Object

Saxon extensions supporting Tables

Copyright (C) 2000 Norman Walsh.

This class provides a Saxon implementation of some code to adjust CALS Tables to HTML Tables.

Column Widths

The adjustColumnWidths method takes a result tree fragment (assumed to contain the colgroup of an HTML Table) and returns the result tree fragment with the column widths adjusted to HTML terms.

Convert Lengths

The convertLength method takes a length specification of the form 9999.99xx (where "xx" is a unit) and returns that length as an integral number of pixels. For convenience, percentage lengths are returned unchanged.

The recognized units are: inches (in), centimeters (cm), millimeters (mm), picas (pc, 1pc=12pt), points (pt), and pixels (px). A number with no units is assumed to be pixels.

Change Log:

1.0

Initial release.


Field Summary
private static boolean foStylesheet
          Is this an FO stylesheet?
private static int nominalWidth
          The nominal table width (6in by default).
private static int pixelsPerInch
          The number of pixels per inch
private static java.lang.String tableWidth
          The default table width (100% by default).
protected static java.util.Hashtable unitHash
          The hash used to associate units with a length in pixels.
 
Constructor Summary
Table()
          Constructor for Verbatim
 
Method Summary
static NodeSetValue adjustColumnWidths(Context context, NodeSetValue rtf_ns)
          Adjust column widths in an HTML table.
static int convertLength(java.lang.String length)
          Convert a length specification to a number of pixels.
 int getPixelsPerInch()
          Return the current pixels-per-inch value.
protected static java.lang.String getVariable(Context context, java.lang.String varName)
          Find the string value of a stylesheet variable or parameter
protected static void initializeHash()
          Initialize the internal hash table with proper values.
static void setPixelsPerInch(int value)
          Set the pixels-per-inch value.
private static void setupColumnWidths(Context context)
          Setup the parameters associated with column width calculations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pixelsPerInch

private static int pixelsPerInch
The number of pixels per inch


nominalWidth

private static int nominalWidth
The nominal table width (6in by default).


tableWidth

private static java.lang.String tableWidth
The default table width (100% by default).


foStylesheet

private static boolean foStylesheet
Is this an FO stylesheet?


unitHash

protected static java.util.Hashtable unitHash
The hash used to associate units with a length in pixels.

Constructor Detail

Table

public Table()

Constructor for Verbatim

All of the methods are static, so the constructor does nothing.

Method Detail

initializeHash

protected static void initializeHash()
Initialize the internal hash table with proper values.


setPixelsPerInch

public static void setPixelsPerInch(int value)
Set the pixels-per-inch value. Only positive values are legal.


getPixelsPerInch

public int getPixelsPerInch()
Return the current pixels-per-inch value.


convertLength

public static int convertLength(java.lang.String length)

Convert a length specification to a number of pixels.

The specified length should be of the form [+/-]999.99xx, where xx is a valid unit.


getVariable

protected static java.lang.String getVariable(Context context,
                                              java.lang.String varName)
                                       throws javax.xml.transform.TransformerException

Find the string value of a stylesheet variable or parameter

Returns the string value of varName in the current context. Returns the empty string if the variable is not defined.


setupColumnWidths

private static void setupColumnWidths(Context context)

Setup the parameters associated with column width calculations

This method queries the stylesheet for the variables associated with table column widths. It is called automatically before column widths are adjusted. The context is used to retrieve the values, this allows templates to redefine these variables.

The following variables are queried. If the variables do not exist, builtin defaults will be used (but you may also get a bunch of messages from the Java interpreter).

nominal.table.width
The "normal" width for tables. This must be an absolute length.
table.width
The width for tables. This may be either an absolute length or a percentage.


adjustColumnWidths

public static NodeSetValue adjustColumnWidths(Context context,
                                              NodeSetValue rtf_ns)

Adjust column widths in an HTML table.

The specification of column widths in CALS (a relative width plus an optional absolute width) are incompatible with HTML column widths. This method adjusts CALS column width specifiers in an attempt to produce equivalent HTML specifiers.

In order for this method to work, the CALS width specifications should be placed in the "width" attribute of the <col>s within a <colgroup>. Then the colgroup result tree fragment is passed to this method.

This method makes use of two parameters from the XSL stylesheet that calls it: nominal.table.width and table.width. The value of nominal.table.width must be an absolute distance. The value of table.width can be either absolute or relative.

Presented with a mixture of relative and absolute lengths, the table width is used to calculate appropriate values. If the table.width is relative, the nominal width is used for this calculation.

There are three possible combinations of values:

  1. There are no relative widths; in this case the absolute widths are used in the HTML table.
  2. There are no absolute widths; in this case the relative widths are used in the HTML table.
  3. There are a mixture of absolute and relative widths:
    1. If the table width is absolute, all widths become absolute.
    2. If the table width is relative, make all the widths absolute relative to the nominal table width then turn them all back into relative widths.