286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 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: ExsltBase.java,v 1.1.2.1 2005/08/01 02:08:51 jeffsuttor Exp $
286N/A */
286N/Apackage com.sun.org.apache.xalan.internal.lib;
286N/A
286N/Aimport com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
286N/A
286N/Aimport org.w3c.dom.Node;
286N/Aimport org.w3c.dom.NodeList;
286N/A
286N/A/**
286N/A * The base class for some EXSLT extension classes.
286N/A * It contains common utility methods to be used by the sub-classes.
286N/A */
286N/Apublic abstract class ExsltBase
286N/A{
286N/A /**
286N/A * Return the string value of a Node
286N/A *
286N/A * @param n The Node.
286N/A * @return The string value of the Node
286N/A */
286N/A protected static String toString(Node n)
286N/A {
286N/A if (n instanceof DTMNodeProxy)
286N/A return ((DTMNodeProxy)n).getStringValue();
286N/A else
286N/A {
286N/A String value = n.getNodeValue();
286N/A if (value == null)
286N/A {
286N/A NodeList nodelist = n.getChildNodes();
286N/A StringBuffer buf = new StringBuffer();
286N/A for (int i = 0; i < nodelist.getLength(); i++)
286N/A {
286N/A Node childNode = nodelist.item(i);
286N/A buf.append(toString(childNode));
286N/A }
286N/A return buf.toString();
286N/A }
286N/A else
286N/A return value;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Convert the string value of a Node to a number.
286N/A * Return NaN if the string is not a valid number.
286N/A *
286N/A * @param n The Node.
286N/A * @return The number value of the Node
286N/A */
286N/A protected static double toNumber(Node n)
286N/A {
286N/A double d = 0.0;
286N/A String str = toString(n);
286N/A try
286N/A {
286N/A d = Double.valueOf(str).doubleValue();
286N/A }
286N/A catch (NumberFormatException e)
286N/A {
286N/A d= Double.NaN;
286N/A }
286N/A return d;
286N/A }
286N/A}