1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.dom; 21 22 import com.sun.org.apache.xalan.internal.xsltc.DOM; 23 import com.sun.org.apache.xalan.internal.xsltc.Translet; 24 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; 25 26 30 public abstract class SingleNodeCounter extends NodeCounter { 31 static private final int[] EmptyArray = new int[] { }; 32 DTMAxisIterator _countSiblings = null; 33 34 public SingleNodeCounter(Translet translet, 35 DOM document, 36 DTMAxisIterator iterator) { 37 super(translet, document, iterator); 38 } 39 40 public NodeCounter setStartNode(int node) { 41 _node = node; 42 _nodeType = _document.getExpandedTypeID(node); 43 _countSiblings = _document.getAxisIterator(PRECEDINGSIBLING); 44 return this; 45 } 46 47 public String getCounter() { 48 int result; 49 if (_value != Integer.MIN_VALUE) { 50 result = _value; 51 } 52 else { 53 int next = _node; 54 result = 0; 55 if (!matchesCount(next)) { 56 while ((next = _document.getParent(next)) > END) { 57 if (matchesCount(next)) { 58 break; } 60 if (matchesFrom(next)) { 61 next = END; 62 break; } 64 } 65 } 66 67 if (next != END) { 68 _countSiblings.setStartNode(next); 69 do { 70 if (matchesCount(next)) result++; 71 } while ((next = _countSiblings.next()) != END); 72 } 73 else { 74 return formatNumbers(EmptyArray); 76 } 77 } 78 return formatNumbers(result); 79 } 80 81 public static NodeCounter getDefaultNodeCounter(Translet translet, 82 DOM document, 83 DTMAxisIterator iterator) { 84 return new DefaultSingleNodeCounter(translet, document, iterator); 85 } 86 87 static class DefaultSingleNodeCounter extends SingleNodeCounter { 88 public DefaultSingleNodeCounter(Translet translet, 89 DOM document, DTMAxisIterator iterator) { 90 super(translet, document, iterator); 91 } 92 93 public NodeCounter setStartNode(int node) { 94 _node = node; 95 _nodeType = _document.getExpandedTypeID(node); 96 _countSiblings = 97 _document.getTypedAxisIterator(PRECEDINGSIBLING, 98 _document.getExpandedTypeID(node)); 99 return this; 100 } 101 102 public String getCounter() { 103 int result; 104 if (_value != Integer.MIN_VALUE) { 105 result = _value; 106 } 107 else { 108 int next; 109 result = 1; 110 _countSiblings.setStartNode(_node); 111 while ((next = _countSiblings.next()) != END) { 112 result++; 113 } 114 } 115 return formatNumbers(result); 116 } 117 } 118 } 119 120 | Popular Tags |