286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001-2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: AnyNodeCounter.java,v 1.2.4.1 2005/09/06 05:54:53 pvedula Exp $
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xalan.internal.xsltc.dom;
286N/A
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.DOM;
286N/Aimport com.sun.org.apache.xalan.internal.xsltc.Translet;
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
286N/A
286N/A/**
286N/A * @author Jacek Ambroziak
286N/A * @author Santiago Pericas-Geertsen
286N/A */
286N/Apublic abstract class AnyNodeCounter extends NodeCounter {
286N/A public AnyNodeCounter(Translet translet,
286N/A DOM document, DTMAxisIterator iterator) {
286N/A super(translet, document, iterator);
286N/A }
286N/A
286N/A public AnyNodeCounter(Translet translet,
286N/A DOM document,
286N/A DTMAxisIterator iterator,
286N/A boolean hasFrom) {
286N/A super(translet, document, iterator, hasFrom);
286N/A }
286N/A
286N/A public NodeCounter setStartNode(int node) {
286N/A _node = node;
286N/A _nodeType = _document.getExpandedTypeID(node);
286N/A return this;
286N/A }
286N/A
286N/A public String getCounter() {
286N/A int result;
286N/A if (_value != Integer.MIN_VALUE) {
286N/A //See Errata E24
286N/A if (_value == 0) return "0";
286N/A else if (Double.isNaN(_value)) return "NaN";
286N/A else if (_value < 0 && Double.isInfinite(_value)) return "-Infinity";
286N/A else if (Double.isInfinite(_value)) return "Infinity";
286N/A else return formatNumbers((int)_value);
286N/A }
286N/A else {
286N/A int next = _node;
286N/A final int root = _document.getDocument();
286N/A result = 0;
286N/A while (next >= root && !matchesFrom(next)) {
286N/A if (matchesCount(next)) {
286N/A ++result;
286N/A }
286N/A next--;
286N/A//%HZ%: Is this the best way of finding the root? Is it better to check
286N/A//%HZ%: parent(next)?
286N/A /*
286N/A if (next == root) {
286N/A break;
286N/A }
286N/A else {
286N/A --next;
286N/A }
286N/A */
286N/A }
286N/A }
286N/A return formatNumbers(result);
286N/A }
286N/A
286N/A public static NodeCounter getDefaultNodeCounter(Translet translet,
286N/A DOM document,
286N/A DTMAxisIterator iterator) {
286N/A return new DefaultAnyNodeCounter(translet, document, iterator);
286N/A }
286N/A
286N/A static class DefaultAnyNodeCounter extends AnyNodeCounter {
286N/A public DefaultAnyNodeCounter(Translet translet,
286N/A DOM document, DTMAxisIterator iterator) {
286N/A super(translet, document, iterator);
286N/A }
286N/A
286N/A public String getCounter() {
286N/A int result;
286N/A if (_value != Integer.MIN_VALUE) {
286N/A //See Errata E24
286N/A if (_value == 0) return "0";
286N/A else if (Double.isNaN(_value)) return "NaN";
286N/A else if (_value < 0 && Double.isInfinite(_value)) return "-Infinity";
286N/A else if (Double.isInfinite(_value)) return "Infinity";
286N/A else result = (int) _value;
286N/A }
286N/A else {
286N/A int next = _node;
286N/A result = 0;
286N/A final int ntype = _document.getExpandedTypeID(_node);
286N/A final int root = _document.getDocument();
286N/A while (next >= 0) {
286N/A if (ntype == _document.getExpandedTypeID(next)) {
286N/A result++;
286N/A }
286N/A//%HZ%: Is this the best way of finding the root? Is it better to check
286N/A//%HZ%: parent(next)?
286N/A if (next == root) {
286N/A break;
286N/A }
286N/A else {
286N/A --next;
286N/A }
286N/A }
286N/A }
286N/A return formatNumbers(result);
286N/A }
286N/A }
286N/A}