Class NumberLinesEmitter
- All Implemented Interfaces:
Result
Saxon extension to decorate a result tree fragment with line numbers.
$Id: NumberLinesEmitter.java 5907 2006-04-27 08:26:47Z xmldoc $
Copyright (C) 2000 Norman Walsh.
This class provides the guts of a Saxon 6.* implementation of line numbering 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 NumberLinesEmitter with information about what lines should be numbered and how. Then the result tree fragment is "replayed" through the NumberLinesEmitter; the NumberLinesEmitter builds a new result tree fragment from this event stream, decorated with line numbers, and that is returned.
Change Log:
- 1.0
Initial release.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StackA stack for the preserving information about open elements.protected booleanIs the next element absolutely the first element in the fragment?protected booleanIs the stylesheet currently running an FO stylesheet?protected static StringThe FO namespace name.protected intThe current line number.protected intEverymodulusline will be numbered.protected StringLine numbers are separated from the listing byseparator.protected intThe first line number will bestartinglinenumber.protected intLine numbers arewidthcharacters wide.protected static StringThe XHTML namespace name.Fields inherited from class com.nwalsh.saxon.CopyEmitter
namePool, rtf, rtfEmitterFields inherited from class com.icl.saxon.output.Emitter
locator, outputProperties, outputStream, systemId, writerFields inherited from interface javax.xml.transform.Result
PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING -
Constructor Summary
ConstructorsConstructorDescriptionNumberLinesEmitter(com.icl.saxon.Controller controller, com.icl.saxon.om.NamePool namePool, int startingLineNumber, int modulus, int width, String separator, boolean foStylesheet) Constructor for the NumberLinesEmitter. -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] chars, int start, int len) Process characters.voidendElement(int nameCode) Process end element events.protected voidformatLineNumber(int lineNumber) Add a formatted line number to the result tree fragment.protected booleanskipThisElement(int nameCode) Protect the outer-most block wrapper.voidstartElement(int nameCode, 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, startDocumentMethods inherited from class com.icl.saxon.output.Emitter
getNamePool, getOutputProperties, getOutputStream, getSystemId, getWriter, makeEmitter, setOutputProperties, setOutputStream, setSystemId, usesWriter
-
Field Details
-
elementStack
A stack for the preserving information about open elements. -
lineNumber
protected int lineNumberThe current line number. -
firstElement
protected boolean firstElementIs the next element absolutely the first element in the fragment? -
foURI
The FO namespace name. -
xhURI
The XHTML namespace name. -
startinglinenumber
protected int startinglinenumberThe first line number will bestartinglinenumber. -
modulus
protected int modulusEverymodulusline will be numbered. -
width
protected int widthLine numbers arewidthcharacters wide. -
separator
Line numbers are separated from the listing byseparator. -
foStylesheet
protected boolean foStylesheetIs the stylesheet currently running an FO stylesheet?
-
-
Constructor Details
-
NumberLinesEmitter
public NumberLinesEmitter(com.icl.saxon.Controller controller, com.icl.saxon.om.NamePool namePool, int startingLineNumber, int modulus, int width, String separator, boolean foStylesheet) Constructor for the NumberLinesEmitter.
- Parameters:
namePool- The name pool to use for constructing elements and attributes.modulus- The modulus to use for this listing.width- The width to use for line numbers in this listing.separator- The separator to use for this listing.foStylesheet- Is this an FO stylesheet?
-
-
Method Details
-
characters
Process characters.- Overrides:
charactersin classCopyEmitter- Throws:
TransformerException
-
formatLineNumber
Add a formatted line number to the result tree fragment.
- Parameters:
lineNumber- The number of the current line.- Throws:
TransformerException
-
endElement
Process end element events.- Overrides:
endElementin classCopyEmitter- Throws:
TransformerException
-
startElement
public void startElement(int nameCode, Attributes attributes, int[] namespaces, int nscount) throws TransformerException Process start element events.- Overrides:
startElementin classCopyEmitter- Throws:
TransformerException
-
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.
- Parameters:
nameCode- The name code for the element- Returns:
- True if the element is the outer-most block, false otherwise.
-