KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > tinytree > TinyTextImpl


1 package net.sf.saxon.tinytree;
2 import net.sf.saxon.event.Receiver;
3 import net.sf.saxon.trans.XPathException;
4 import net.sf.saxon.type.Type;
5
6 /**
7   * A node in the XML parse tree representing character content<P>
8   * @author Michael H. Kay
9   */

10
11 final class TinyTextImpl extends TinyNodeImpl {
12
13     public TinyTextImpl(TinyTree tree, int nodeNr) {
14         this.tree = tree;
15         this.nodeNr = nodeNr;
16     }
17
18     /**
19     * Return the character value of the node.
20     * @return the string value of the node
21     */

22
23     public String JavaDoc getStringValue() {
24         int start = tree.alpha[nodeNr];
25         int len = tree.beta[nodeNr];
26         return new String JavaDoc(tree.charBuffer, start, len);
27     }
28
29     /**
30      * Get the value of the item as a CharSequence. This is in some cases more efficient than
31      * the version of the method that returns a String.
32      */

33
34     public CharSequence JavaDoc getStringValueCS() {
35         int start = tree.alpha[nodeNr];
36         int len = tree.beta[nodeNr];
37         return new CharSlice(tree.charBuffer, start, len);
38     }
39
40     static CharSequence JavaDoc getStringValue(TinyTree tree, int nodeNr) {
41         int start = tree.alpha[nodeNr];
42         int len = tree.beta[nodeNr];
43         return new CharSlice(tree.charBuffer, start, len);
44     }
45
46     /**
47     * Return the type of node.
48     * @return Type.TEXT
49     */

50
51     public final int getNodeKind() {
52         return Type.TEXT;
53     }
54
55     /**
56     * Copy this node to a given outputter
57     */

58
59     public void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId) throws XPathException {
60         int start = tree.alpha[nodeNr];
61         int len = tree.beta[nodeNr];
62         out.characters(new CharSlice(tree.charBuffer, start, len), 0, 0);
63     }
64
65
66 }
67
68 //
69
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
70
// you may not use this file except in compliance with the License. You may obtain a copy of the
71
// License at http://www.mozilla.org/MPL/
72
//
73
// Software distributed under the License is distributed on an "AS IS" basis,
74
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
75
// See the License for the specific language governing rights and limitations under the License.
76
//
77
// The Original Code is: all this file.
78
//
79
// The Initial Developer of the Original Code is Michael H. Kay.
80
//
81
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
82
//
83
// Contributor(s): none.
84
//
85
Popular Tags