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.xalan.internal.xsltc.util.IntegerArray; 25 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; 26 27 31 public abstract class MultipleNodeCounter extends NodeCounter { 32 private DTMAxisIterator _precSiblings = null; 33 34 public MultipleNodeCounter(Translet translet, 35 DOM document, DTMAxisIterator iterator) { 36 super(translet, document, iterator); 37 } 38 39 public NodeCounter setStartNode(int node) { 40 _node = node; 41 _nodeType = _document.getExpandedTypeID(node); 42 _precSiblings = _document.getAxisIterator(PRECEDINGSIBLING); 43 return this; 44 } 45 46 public String getCounter() { 47 if (_value != Integer.MIN_VALUE) { 48 return formatNumbers(_value); 49 } 50 51 IntegerArray ancestors = new IntegerArray(); 52 53 int next = _node; 55 ancestors.add(next); while ((next = _document.getParent(next)) > END && 57 !matchesFrom(next)) { 58 ancestors.add(next); 59 } 60 61 final int nAncestors = ancestors.cardinality(); 63 final int[] counters = new int[nAncestors]; 64 for (int i = 0; i < nAncestors; i++) { 65 counters[i] = Integer.MIN_VALUE; 66 } 67 68 for (int j = 0, i = nAncestors - 1; i >= 0 ; i--, j++) { 70 final int counter = counters[j]; 71 final int ancestor = ancestors.at(i); 72 73 if (matchesCount(ancestor)) { 74 _precSiblings.setStartNode(ancestor); 75 while ((next = _precSiblings.next()) != END) { 76 if (matchesCount(next)) { 77 counters[j] = (counters[j] == Integer.MIN_VALUE) ? 1 78 : counters[j] + 1; 79 } 80 } 81 counters[j] = counters[j] == Integer.MIN_VALUE 83 ? 1 84 : counters[j] + 1; 85 } 86 } 87 return formatNumbers(counters); 88 } 89 90 public static NodeCounter getDefaultNodeCounter(Translet translet, 91 DOM document, 92 DTMAxisIterator iterator) { 93 return new DefaultMultipleNodeCounter(translet, document, iterator); 94 } 95 96 static class DefaultMultipleNodeCounter extends MultipleNodeCounter { 97 public DefaultMultipleNodeCounter(Translet translet, 98 DOM document, 99 DTMAxisIterator iterator) { 100 super(translet, document, iterator); 101 } 102 } 103 } 104 | Popular Tags |