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

Quick Search    Search Deep

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

java.lang.Object
  extended bycom.icl.saxon.output.Emitter
      extended bycom.nwalsh.saxon.CopyEmitter
          extended bycom.nwalsh.saxon.CalloutEmitter

public class CalloutEmitter
extends CopyEmitter

Saxon extension to decorate a result tree fragment with callouts.

Copyright (C) 2000 Norman Walsh.

This class provides the guts of a Saxon 6.* implementation of callouts for verbatim environments. (It is used by the Verbatim class.)

The general design is this: the stylesheets construct a result tree fragment for some verbatim environment. The Verbatim class initializes a CalloutEmitter with information about the callouts that should be applied to the verbatim environment in question. Then the result tree fragment is "replayed" through the CalloutEmitter; the CalloutEmitter builds a new result tree fragment from this event stream, decorated with callouts, and that is returned.

Change Log:

1.0

Initial release.


Nested Class Summary
private  class CalloutEmitter.StartElementInfo
          A private class for maintaining the information required to call the startElement method.
 
Field Summary
private static Callout[] callout
          The (sorted) array of callouts obtained from the areaspec.
private static int calloutCount
          The number of callouts in the callout array.
private static int calloutPos
          A pointer used to keep track of our position in the callout array.
private static int colNumber
          The current column number.
protected  int defaultColumn
          The default column for callouts that specify only a line.
protected  java.util.Stack elementStack
          A stack for the preserving information about open elements.
private static FormatCallout fCallout
          The FormatCallout object to use for formatting callouts.
protected  boolean firstElement
          Is the next element absolutely the first element in the fragment?
protected  boolean foStylesheet
          Is the stylesheet currently running an FO stylesheet?
protected static java.lang.String foURI
          The FO namespace name.
private static int lineNumber
          The current line number.
protected  java.util.Stack tempStack
          A stack for holding information about temporarily closed elements.
 
Fields inherited from class com.nwalsh.saxon.CopyEmitter
namePool, rtf, rtfEmitter
 
Constructor Summary
CalloutEmitter(Controller controller, NamePool namePool, int defaultColumn, boolean foStylesheet, FormatCallout fCallout)
          Constructor for the CalloutEmitter.
 
Method Summary
protected  void addCallout(int coNum, org.w3c.dom.Node node, int defaultColumn)
          Add a callout to the global callout array
 void characters(char[] chars, int start, int len)
          Process characters.
private  void closeOpenElements(Emitter rtfEmitter)
           
 void endElement(int nameCode)
          Process end element events.
protected  void formatPad(int numBlanks)
          Add blanks to the result tree fragment.
private  void openClosedElements(Emitter rtfEmitter)
           
 void setupCallouts(org.w3c.dom.NodeList areaspecNodeList)
          Examine the areaspec and determine the number and position of callouts.
protected  boolean skipThisElement(int nameCode)
          Protect the outer-most block wrapper.
 void startElement(int nameCode, org.xml.sax.Attributes attributes, int[] namespaces, int nscount)
          Process start element events.
 
Methods inherited from class com.nwalsh.saxon.CopyEmitter
comment, endDocument, getResultTreeFragment, processingInstruction, setDocumentLocator, setEscaping, setNamePool, setUnparsedEntity, setWriter, startDocument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

elementStack

protected java.util.Stack elementStack
A stack for the preserving information about open elements.


tempStack

protected java.util.Stack tempStack
A stack for holding information about temporarily closed elements.


firstElement

protected boolean firstElement
Is the next element absolutely the first element in the fragment?


foURI

protected static java.lang.String foURI
The FO namespace name.


defaultColumn

protected int defaultColumn
The default column for callouts that specify only a line.


foStylesheet

protected boolean foStylesheet
Is the stylesheet currently running an FO stylesheet?


lineNumber

private static int lineNumber
The current line number.


colNumber

private static int colNumber
The current column number.


callout

private static Callout[] callout
The (sorted) array of callouts obtained from the areaspec.


calloutCount

private static int calloutCount
The number of callouts in the callout array.


calloutPos

private static int calloutPos
A pointer used to keep track of our position in the callout array.


fCallout

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

Constructor Detail

CalloutEmitter

public CalloutEmitter(Controller controller,
                      NamePool namePool,
                      int defaultColumn,
                      boolean foStylesheet,
                      FormatCallout fCallout)

Constructor for the CalloutEmitter.

Method Detail

setupCallouts

public void setupCallouts(org.w3c.dom.NodeList areaspecNodeList)

Examine the areaspec and determine the number and position of callouts.

The areaspecNodeSet is examined and a sorted list of the callouts is constructed.

This data structure is used to augment the result tree fragment with callout bullets.


characters

public void characters(char[] chars,
                       int start,
                       int len)
                throws javax.xml.transform.TransformerException
Process characters.

Overrides:
characters in class CopyEmitter

formatPad

protected void formatPad(int numBlanks)

Add blanks to the result tree fragment.

This method adds numBlanks to the result tree fragment. It's used to pad lines when callouts occur after the last existing characater in a line.


addCallout

protected void addCallout(int coNum,
                          org.w3c.dom.Node node,
                          int defaultColumn)

Add a callout to the global callout array

This method examines a callout area and adds it to the global callout array if it can be interpreted.

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.


endElement

public void endElement(int nameCode)
                throws javax.xml.transform.TransformerException
Process end element events.

Overrides:
endElement in class CopyEmitter

startElement

public void startElement(int nameCode,
                         org.xml.sax.Attributes attributes,
                         int[] namespaces,
                         int nscount)
                  throws javax.xml.transform.TransformerException
Process start element events.

Overrides:
startElement in class CopyEmitter

skipThisElement

protected boolean skipThisElement(int nameCode)

Protect the outer-most block wrapper.

Open elements in the result tree fragment are closed and reopened around callouts (so that callouts don't appear inside links or other environments). But if the result tree fragment is a single block (a div or pre in HTML, an fo:block in FO), that outer-most block is treated specially.

This method returns true if the element in question is that outermost block.


closeOpenElements

private void closeOpenElements(Emitter rtfEmitter)
                        throws javax.xml.transform.TransformerException

openClosedElements

private void openClosedElements(Emitter rtfEmitter)
                         throws javax.xml.transform.TransformerException