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

Quick Search    Search Deep

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

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

public class Verbatim
extends java.lang.Object

Saxon extensions supporting DocBook verbatim environments

Copyright (C) 2000 Norman Walsh.

This class provides a Saxon implementation of two features that would be impractical to implement directly in XSLT: line numbering and callouts.

Line Numbering

The numberLines method takes a result tree fragment (assumed to contain the contents of a formatted verbatim element in DocBook: programlisting, screen, address, literallayout, or synopsis) and returns a result tree fragment decorated with line numbers.

Callouts

The insertCallouts method takes an areaspec and a result tree fragment (assumed to contain the contents of a formatted verbatim element in DocBook: programlisting, screen, address, literallayout, or synopsis) and returns a result tree fragment decorated with callouts.

Change Log:

1.0

Initial release.


Field Summary
private static boolean calloutsSetup
          True if callouts have been setup
private static int defaultColumn
          The default column for callouts that have only a line or line range
private static FormatCallout fCallout
          The FormatCallout object to use for formatting callouts.
private static boolean foStylesheet
          True if the stylesheet is producing formatting objects
private static java.lang.String graphicsExt
          The extension to use for graphical callout decorations.
private static int graphicsMax
          The largest callout number that can be represented graphically.
private static java.lang.String graphicsPath
          The path to use for graphical callout decorations.
private static int modulus
          The modulus for line numbering (every 'modulus' line is numbered).
private static java.lang.String separator
          The separator between the line number and the verbatim text.
private static int width
          The width (in characters) of line numbers (for padding).
 
Constructor Summary
Verbatim()
          Constructor for Verbatim
 
Method Summary
protected static java.lang.String getVariable(Context context, java.lang.String varName)
          Find the string value of a stylesheet variable or parameter
static NodeSetValue insertCallouts(Context context, org.w3c.dom.NodeList areaspecNodeList, NodeSetValue rtf_ns)
          Insert text callouts into a verbatim environment.
static NodeSetValue numberLines(Context context, NodeSetValue rtf_ns)
          Number lines in a verbatim environment
private static void setupCallouts(Context context)
          Setup the parameters associated with callouts
private static void setupLineNumbering(Context context)
          Setup the parameters associated with line numbering
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

foStylesheet

private static boolean foStylesheet
True if the stylesheet is producing formatting objects


modulus

private static int modulus
The modulus for line numbering (every 'modulus' line is numbered).


width

private static int width
The width (in characters) of line numbers (for padding).


separator

private static java.lang.String separator
The separator between the line number and the verbatim text.


calloutsSetup

private static boolean calloutsSetup
True if callouts have been setup


defaultColumn

private static int defaultColumn
The default column for callouts that have only a line or line range


graphicsPath

private static java.lang.String graphicsPath
The path to use for graphical callout decorations.


graphicsExt

private static java.lang.String graphicsExt
The extension to use for graphical callout decorations.


graphicsMax

private static int graphicsMax
The largest callout number that can be represented graphically.


fCallout

private static FormatCallout fCallout
The FormatCallout object to use for formatting callouts.

Constructor Detail

Verbatim

public Verbatim()

Constructor for Verbatim

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

Method Detail

getVariable

protected static java.lang.String getVariable(Context context,
                                              java.lang.String varName)

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.


setupLineNumbering

private static void setupLineNumbering(Context context)

Setup the parameters associated with line numbering

This method queries the stylesheet for the variables associated with line numbering. It is called automatically before lines are numbered. 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).

linenumbering.everyNth
Specifies the lines that will be numbered. The first line is always numbered. (builtin default: 5).
linenumbering.width
Specifies the width of the numbers. If the specified width is too narrow for the largest number needed, it will automatically be made wider. (builtin default: 3).
linenumbering.separator
Specifies the string that separates line numbers from lines in the program listing. (builtin default: " ").
stylesheet.result.type
Specifies the stylesheet result type. The value is either 'fo' (for XSL Formatting Objects) or it isn't. (builtin default: html).


numberLines

public static NodeSetValue numberLines(Context context,
                                       NodeSetValue rtf_ns)

Number lines in a verbatim environment

The extension function expects the following variables to be available in the calling context: $linenumbering.everyNth, $linenumbering.width, $linenumbering.separator, and $stylesheet.result.type.

This method adds line numbers to a result tree fragment. Each newline that occurs in a text node is assumed to start a new line. The first line is always numbered, every subsequent 'everyNth' line is numbered (so if everyNth=5, lines 1, 5, 10, 15, etc. will be numbered. If there are fewer than everyNth lines in the environment, every line is numbered.

Every line number will be right justified in a string 'width' characters long. If the line number of the last line in the environment is too long to fit in the specified width, the width is automatically increased to the smallest value that can hold the number of the last line. (In other words, if you specify the value 2 and attempt to enumerate the lines of an environment that is 100 lines long, the value 3 will automatically be used for every line in the environment.)

The 'separator' string is inserted between the line number and the original program listing. Lines that aren't numbered are preceded by a 'width' blank string and the separator.

If inline markup extends across line breaks, markup changes are required. All the open elements are closed before the line break and "reopened" afterwards. The reopened elements will have the same attributes as the originals, except that 'name' and 'id' attributes are not duplicated if the stylesheet.result.type is "html" and 'id' attributes will not be duplicated if the result type is "fo".


setupCallouts

private static void setupCallouts(Context context)

Setup the parameters associated with callouts

This method queries the stylesheet for the variables associated with line numbering. It is called automatically before callouts are processed. 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).

callout.graphics
Are we using callout graphics? A value of 0 or "" is false, any other value is true. If callout graphics are not used, the parameters related to graphis are not queried.
callout.graphics.path
Specifies the path to callout graphics.
callout.graphics.extension
Specifies the extension ot use for callout graphics.
callout.graphics.number.limit
Identifies the largest number that can be represented as a graphic. Larger callout numbers will be represented using text.
callout.defaultcolumn
Specifies the default column for callout bullets that do not specify a column.
stylesheet.result.type
Specifies the stylesheet result type. The value is either 'fo' (for XSL Formatting Objects) or it isn't. (builtin default: html).


insertCallouts

public static NodeSetValue insertCallouts(Context context,
                                          org.w3c.dom.NodeList areaspecNodeList,
                                          NodeSetValue rtf_ns)

Insert text callouts into a verbatim environment.

This method examines the areaset and area elements in the supplied areaspec and decorates the supplied result tree fragment with appropriate callout markers.

If a label attribute is supplied on an area, its content will be used for the label, otherwise the callout number will be used, surrounded by parenthesis. Callout numbers may also be represented as graphics. Callouts are numbered in document order. All of the areas in an areaset get the same number.

Only the linecolumn and linerange units are supported. If no unit is specifed, linecolumn is assumed. If only a line is specified, the callout decoration appears in the defaultColumn. Lines will be padded with blanks to reach the necessary column, but callouts that are located beyond the last line of the verbatim environment will be ignored.

Callouts are inserted before the character at the line/column where they are to occur.

If graphical callouts are used, and the callout number is less than or equal to the $callout.graphics.number.limit, the following image will be generated for HTML:

 <img src="$callout.graphics.path/999$callout.graphics.ext"
         alt="conumber">
 
If the $stylesheet.result.type is 'fo', the following image will be generated:
 <fo:external-graphic src="$callout.graphics.path/999$callout.graphics.ext"/>
 

If the callout number exceeds $callout.graphics.number.limit, the callout will be the callout number surrounded by parenthesis.