
com.nwalsh.saxon.LineCountEmitter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docbook-xsl-saxon Show documentation
Show all versions of docbook-xsl-saxon Show documentation
These are Java extensions for use with the DocBook XML stylesheets and the Saxon XSLT engine.
The newest version!
package com.nwalsh.saxon;
import com.icl.saxon.om.NamePool;
/**
* Saxon extension to count the lines in a result tree fragment.
*
* $Id: LineCountEmitter.java 8098 2008-08-03 13:27:07Z mzjn $
*
* Copyright (C) 2000 Norman Walsh.
*
* This class provides a
* Saxon 6.*
* implementation to count the number of lines in a result tree
* fragment.
*
* The general design is this: the stylesheets construct a result tree
* fragment for some verbatim environment. That result tree fragment
* is "replayed" through the LineCountEmitter; the LineCountEmitter watches
* characters go by and counts the number of line feeds that it sees.
* That number is then returned.
*
* Change Log:
*
* - 1.0
* Initial release.
*
*
* @see Verbatim
*
* @author Norman Walsh
* [email protected]
*
* @version $Id: LineCountEmitter.java 8098 2008-08-03 13:27:07Z mzjn $
*
*/
public class LineCountEmitter extends com.icl.saxon.output.Emitter {
/** The number of lines seen. */
protected int numLines = 0;
/** Construct a new LineCountEmitter. */
public LineCountEmitter() {
numLines = 0;
}
/** Reset the number of lines. */
public void reset() {
numLines = 0;
}
/** Return the number of lines. */
public int lineCount() {
return numLines;
}
/** Process characters. */
public void characters(char[] chars, int start, int len)
throws javax.xml.transform.TransformerException {
if (numLines == 0) {
// If there are any characters at all, there's at least one line
numLines++;
}
for (int count = start; count < start+len; count++) {
if (chars[count] == '\n') {
numLines++;
}
}
}
/** Discarded. */
public void comment(char[] chars, int start, int length)
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void endDocument()
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void endElement(int nameCode)
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void processingInstruction(java.lang.String name,
java.lang.String data)
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void setDocumentLocator(org.xml.sax.Locator locator) {
// nop
}
/** Discarded. */
public void setEscaping(boolean escaping)
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void setNamePool(NamePool namePool) {
// nop
}
/** Discarded. */
public void setUnparsedEntity(java.lang.String name, java.lang.String uri)
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void setWriter(java.io.Writer writer) {
// nop
}
/** Discarded. */
public void startDocument()
throws javax.xml.transform.TransformerException {
// nop
}
/** Discarded. */
public void startElement(int nameCode,
org.xml.sax.Attributes attributes,
int[] namespaces, int nscount)
throws javax.xml.transform.TransformerException {
// nop
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy