1 package net.sf.saxon.tinytree; 2 import net.sf.saxon.type.Type; 3 import net.sf.saxon.om.FastStringBuffer; 4 5 10 11 12 abstract class TinyParentNodeImpl extends TinyNodeImpl { 13 14 17 18 public final boolean hasChildNodes() { 19 return (nodeNr+1 < tree.numberOfNodes && 20 tree.depth[nodeNr+1] > tree.depth[nodeNr]); 21 } 22 23 28 29 public final String getStringValue() { 30 return getStringValue(tree, nodeNr).toString(); 31 } 32 33 37 38 public CharSequence getStringValueCS() { 39 return getStringValue(tree, nodeNr); 40 } 41 42 52 53 public static final CharSequence getStringValue(TinyTree tree, int nodeNr) { 54 int level = tree.depth[nodeNr]; 55 56 59 int next = nodeNr+1; 60 61 64 if (tree.depth[next] <= level) { 65 return ""; 66 } else if (tree.nodeKind[next] == Type.TEXT && tree.depth[next+1] <= level) { 67 int length = tree.beta[next]; 68 int start = tree.alpha[next]; 69 return new CharSlice(tree.charBuffer, start, length); 70 } 71 72 74 FastStringBuffer sb = null; 75 while (next < tree.numberOfNodes && tree.depth[next] > level) { 76 if (tree.nodeKind[next]==Type.TEXT) { 77 int length = tree.beta[next]; 78 int start = tree.alpha[next]; 79 if (sb==null) { 80 sb = new FastStringBuffer(1024); 81 } 82 sb.append(tree.charBuffer, start, length); 83 } 84 next++; 85 } 86 if (sb==null) return ""; 87 return sb.condense(); 88 } 89 90 } 91 92 93 | Popular Tags |