KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nwalsh > saxon > LineCountEmitter


1 package com.nwalsh.saxon;
2
3 import org.xml.sax.*;
4 import javax.xml.transform.TransformerException JavaDoc;
5 import com.icl.saxon.output.*;
6 import com.icl.saxon.om.*;
7 import com.icl.saxon.expr.FragmentValue;
8
9 /**
10  * <p>Saxon extension to count the lines in a result tree fragment.</p>
11  *
12  * <p>$Id: LineCountEmitter.java,v 1.1 2001/07/16 21:23:57 nwalsh Exp $</p>
13  *
14  * <p>Copyright (C) 2000 Norman Walsh.</p>
15  *
16  * <p>This class provides a
17  * <a HREF="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
18  * implementation to count the number of lines in a result tree
19  * fragment.</p>
20  *
21  * <p>The general design is this: the stylesheets construct a result tree
22  * fragment for some verbatim environment. That result tree fragment
23  * is "replayed" through the LineCountEmitter; the LineCountEmitter watches
24  * characters go by and counts the number of line feeds that it sees.
25  * That number is then returned.</p>
26  *
27  * <p><b>Change Log:</b></p>
28  * <dl>
29  * <dt>1.0</dt>
30  * <dd><p>Initial release.</p></dd>
31  * </dl>
32  *
33  * @see Verbatim
34  *
35  * @author Norman Walsh
36  * <a HREF="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
37  *
38  * @version $Id: LineCountEmitter.java,v 1.1 2001/07/16 21:23:57 nwalsh Exp $
39  *
40  */

41 public class LineCountEmitter extends com.icl.saxon.output.Emitter {
42   /** The number of lines seen. */
43   protected int numLines = 0;
44
45   /** Construct a new LineCountEmitter. */
46   public LineCountEmitter() {
47     numLines = 0;
48   }
49
50   /** Reset the number of lines. */
51   public void reset() {
52     numLines = 0;
53   }
54
55   /** Return the number of lines. */
56   public int lineCount() {
57     return numLines;
58   }
59
60   /** Process characters. */
61   public void characters(char[] chars, int start, int len)
62     throws javax.xml.transform.TransformerException JavaDoc {
63
64     if (numLines == 0) {
65       // If there are any characters at all, there's at least one line
66
numLines++;
67     }
68
69     for (int count = start; count < start+len; count++) {
70       if (chars[count] == '\n') {
71     numLines++;
72       }
73     }
74   }
75
76   /** Discarded. */
77   public void comment(char[] chars, int start, int length)
78     throws javax.xml.transform.TransformerException JavaDoc {
79     // nop
80
}
81
82   /** Discarded. */
83   public void endDocument()
84     throws javax.xml.transform.TransformerException JavaDoc {
85     // nop
86
}
87
88   /** Discarded. */
89   public void endElement(int nameCode)
90     throws javax.xml.transform.TransformerException JavaDoc {
91     // nop
92
}
93
94   /** Discarded. */
95   public void processingInstruction(java.lang.String JavaDoc name,
96                     java.lang.String JavaDoc data)
97     throws javax.xml.transform.TransformerException JavaDoc {
98     // nop
99
}
100
101   /** Discarded. */
102   public void setDocumentLocator(org.xml.sax.Locator JavaDoc locator) {
103     // nop
104
}
105
106   /** Discarded. */
107   public void setEscaping(boolean escaping)
108     throws javax.xml.transform.TransformerException JavaDoc {
109     // nop
110
}
111
112   /** Discarded. */
113   public void setNamePool(NamePool namePool) {
114     // nop
115
}
116
117   /** Discarded. */
118   public void setUnparsedEntity(java.lang.String JavaDoc name, java.lang.String JavaDoc uri)
119     throws javax.xml.transform.TransformerException JavaDoc {
120     // nop
121
}
122
123   /** Discarded. */
124   public void setWriter(java.io.Writer JavaDoc writer) {
125     // nop
126
}
127
128   /** Discarded. */
129   public void startDocument()
130     throws javax.xml.transform.TransformerException JavaDoc {
131     // nop
132
}
133
134   /** Discarded. */
135   public void startElement(int nameCode,
136             org.xml.sax.Attributes JavaDoc attributes,
137             int[] namespaces, int nscount)
138     throws javax.xml.transform.TransformerException JavaDoc {
139     // nop
140
}
141 }
142
Popular Tags