KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > tinytree > TinyParentNodeImpl


1 package com.icl.saxon.tinytree;
2 import com.icl.saxon.om.NodeInfo;
3 import com.icl.saxon.output.Outputter;
4
5 import javax.xml.transform.TransformerException JavaDoc;
6
7 /**
8   * TinyParentNodeImpl is an implementation of a non-leaf node (specifically, an Element node
9   * or a Document node)
10   * @author Michael H. Kay (mhkay@iclway.co.uk)
11   */

12   
13
14 abstract class TinyParentNodeImpl extends TinyNodeImpl {
15
16     /**
17     * Determine if the node has children.
18     */

19
20     public boolean hasChildNodes() {
21         return (nodeNr+1 < document.numberOfNodes &&
22                 document.depth[nodeNr+1] > document.depth[nodeNr]);
23     }
24
25     /**
26     * Return the string-value of the node, that is, the concatenation
27     * of the character content of all descendent elements and text nodes.
28     * @return the accumulated character content of the element, including descendant elements.
29     */

30
31     public String JavaDoc getStringValue() {
32         int level = document.depth[nodeNr];
33         StringBuffer JavaDoc sb = null;
34
35         // note, we can't rely on the value being contiguously stored because of whitespace
36
// nodes: the data for these may still be present.
37

38         int next = nodeNr+1;
39         while (next < document.numberOfNodes && document.depth[next] > level) {
40             if (document.nodeType[next]==NodeInfo.TEXT) {
41                 if (sb==null) {
42                     sb = new StringBuffer JavaDoc();
43                 }
44                 int length = document.length[next];
45                 int start = document.offset[next];
46                 sb.append(document.charBuffer, start, length);
47             }
48             next++;
49         }
50         if (sb==null) return "";
51         return sb.toString();
52     }
53
54     /**
55     * Copy the string-value of this node to a given outputter
56     */

57
58     public void copyStringValue(Outputter out) throws TransformerException JavaDoc {
59         int level = document.depth[nodeNr];
60
61         // note, we can't rely on the value being contiguously stored because of whitespace
62
// nodes: the data for these may still be present.
63

64         int next = nodeNr+1;
65         while (next < document.numberOfNodes && document.depth[next] > level) {
66             if (document.nodeType[next]==NodeInfo.TEXT) {
67                 out.writeContent(document.charBuffer, document.offset[next], document.length[next]);
68             }
69             next++;
70         }
71     }
72
73 }
74
75
76 //
77
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
78
// you may not use this file except in compliance with the License. You may obtain a copy of the
79
// License at http://www.mozilla.org/MPL/
80
//
81
// Software distributed under the License is distributed on an "AS IS" basis,
82
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
83
// See the License for the specific language governing rights and limitations under the License.
84
//
85
// The Original Code is: all this file.
86
//
87
// The Initial Developer of the Original Code is
88
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
89
//
90
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
91
//
92
// Contributor(s): none.
93
//
94
Popular Tags