01: package net.sf.saxon.tinytree;
02:
03: import net.sf.saxon.event.Receiver;
04: import net.sf.saxon.trans.XPathException;
05: import net.sf.saxon.type.Type;
06:
07: /**
08: * A node in the XML parse tree representing character content<P>
09: * @author Michael H. Kay
10: */
11:
12: final class TinyTextImpl extends TinyNodeImpl {
13:
14: public TinyTextImpl(TinyTree tree, int nodeNr) {
15: this .tree = tree;
16: this .nodeNr = nodeNr;
17: }
18:
19: /**
20: * Return the character value of the node.
21: * @return the string value of the node
22: */
23:
24: public String getStringValue() {
25: int start = tree.alpha[nodeNr];
26: int len = tree.beta[nodeNr];
27: return new String(tree.charBuffer, start, len);
28: }
29:
30: /**
31: * Get the value of the item as a CharSequence. This is in some cases more efficient than
32: * the version of the method that returns a String.
33: */
34:
35: public CharSequence getStringValueCS() {
36: int start = tree.alpha[nodeNr];
37: int len = tree.beta[nodeNr];
38: return new CharSlice(tree.charBuffer, start, len);
39: }
40:
41: static CharSequence getStringValue(TinyTree tree, int nodeNr) {
42: int start = tree.alpha[nodeNr];
43: int len = tree.beta[nodeNr];
44: return new CharSlice(tree.charBuffer, start, len);
45: }
46:
47: /**
48: * Return the type of node.
49: * @return Type.TEXT
50: */
51:
52: public final int getNodeKind() {
53: return Type.TEXT;
54: }
55:
56: /**
57: * Copy this node to a given outputter
58: */
59:
60: public void copy(Receiver out, int whichNamespaces,
61: boolean copyAnnotations, int locationId)
62: throws XPathException {
63: int start = tree.alpha[nodeNr];
64: int len = tree.beta[nodeNr];
65: out
66: .characters(new CharSlice(tree.charBuffer, start, len),
67: 0, 0);
68: }
69:
70: }
71:
72: //
73: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
74: // you may not use this file except in compliance with the License. You may obtain a copy of the
75: // License at http://www.mozilla.org/MPL/
76: //
77: // Software distributed under the License is distributed on an "AS IS" basis,
78: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
79: // See the License for the specific language governing rights and limitations under the License.
80: //
81: // The Original Code is: all this file.
82: //
83: // The Initial Developer of the Original Code is Michael H. Kay.
84: //
85: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
86: //
87: // Contributor(s): none.
88: //
|