You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mk...@apache.org on 2002/09/23 18:22:41 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/lib ExsltBase.java ExsltDynamic.java ExsltMath.java ExsltSets.java ExsltStrings.java

mkwan       2002/09/23 09:22:41

  Modified:    java/src/org/apache/xalan/lib ExsltDynamic.java
                        ExsltMath.java ExsltSets.java ExsltStrings.java
  Added:       java/src/org/apache/xalan/lib ExsltBase.java
  Log:
  Extension cleanup.
  Add an ExsltBase class as the super class for other EXSLT implementation
  classes, so that the toString() and toNumber() interfaces can be easily
  reused by all the subclasses without duplicating code.
  
  Revision  Changes    Path
  1.3       +1 -1      xml-xalan/java/src/org/apache/xalan/lib/ExsltDynamic.java
  
  Index: ExsltDynamic.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/ExsltDynamic.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExsltDynamic.java	19 Sep 2002 14:54:04 -0000	1.2
  +++ ExsltDynamic.java	23 Sep 2002 16:22:40 -0000	1.3
  @@ -92,7 +92,7 @@
    * @see <a href="http://www.exslt.org/">EXSLT</a>
   
    */
  -public class ExsltDynamic
  +public class ExsltDynamic extends ExsltBase
   {
   
      public static final String EXSL_URI = "http://exslt.org/common";
  
  
  
  1.6       +1 -35     xml-xalan/java/src/org/apache/xalan/lib/ExsltMath.java
  
  Index: ExsltMath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/ExsltMath.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExsltMath.java	19 Sep 2002 14:54:04 -0000	1.5
  +++ ExsltMath.java	23 Sep 2002 16:22:40 -0000	1.6
  @@ -58,12 +58,7 @@
   
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  -
   import org.apache.xpath.NodeSet;
  -import org.apache.xpath.DOMHelper;
  -import org.apache.xml.dtm.ref.DTMNodeProxy;
  -
  -import java.util.Hashtable;
   
   /**
    * <meta name="usage" content="general"/>
  @@ -79,7 +74,7 @@
    * @see <a href="http://www.exslt.org/">EXSLT</a>
   
    */
  -public class ExsltMath
  +public class ExsltMath extends ExsltBase
   {
     // Constants
     private static String PI = "3.1415926535897932384626433832795028841971693993751";
  @@ -234,35 +229,6 @@
       return lowNodes;
     }
     
  -  /**
  -   *  Return the string value of a Node
  -   */
  -  private static String toString(Node n)
  -  {
  -  	if (n instanceof DTMNodeProxy)
  -  	 return ((DTMNodeProxy)n).getStringValue();
  -  	else
  -  	 return n.getNodeValue();
  -  }
  -  
  -  /**
  -   * Convert the string value of a Node to a number
  -   */
  -  private static double toNumber(Node n)
  -  {
  -  	double d = 0.0;
  -  	String str = toString(n);
  -  	try
  -  	{
  -  	  d = Double.parseDouble(str);
  -  	}
  -  	catch (NumberFormatException e)
  -  	{
  -  	  d= Double.NaN;  		
  -  	}
  -  	return d;
  -  }
  -
     /**
      * The math:abs function returns the absolute value of a number. 
      */
  
  
  
  1.5       +4 -14     xml-xalan/java/src/org/apache/xalan/lib/ExsltSets.java
  
  Index: ExsltSets.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/ExsltSets.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ExsltSets.java	6 Sep 2002 16:41:24 -0000	1.4
  +++ ExsltSets.java	23 Sep 2002 16:22:40 -0000	1.5
  @@ -58,15 +58,9 @@
   
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  -import org.w3c.dom.traversal.NodeIterator;
  -
   import org.apache.xpath.NodeSet;
   import org.apache.xpath.DOMHelper;
  -import org.apache.xml.dtm.ref.DTMNodeProxy;
   import java.util.Hashtable;
  -
  -import org.apache.xalan.extensions.ExpressionContext;
  -
   import javax.xml.parsers.*;
   
   /**
  @@ -82,7 +76,7 @@
    * 
    * @see <a href="http://www.exslt.org/">EXSLT</a>
    */
  -public class ExsltSets
  +public class ExsltSets extends ExsltBase
   {   
     /**
      * The set:leading function returns the nodes in the node set passed as the first argument that
  @@ -113,7 +107,7 @@
       {
         Node testNode = nl1.item(i);
         if (DOMHelper.isNodeAfter(testNode, endNode) 
  -          && !(testNode == endNode || DOMHelper.isNodeTheSame(testNode, endNode)))
  +          && !DOMHelper.isNodeTheSame(testNode, endNode))
           leadNodes.addElement(testNode);
       }
       return leadNodes;
  @@ -148,7 +142,7 @@
       {
         Node testNode = nl1.item(i);
         if (DOMHelper.isNodeAfter(startNode, testNode) 
  -          && !(startNode == testNode || DOMHelper.isNodeTheSame(startNode, testNode)))
  +          && !DOMHelper.isNodeTheSame(startNode, testNode))
           trailNodes.addElement(testNode);          
       }
       return trailNodes;
  @@ -237,11 +231,7 @@
       for (int i = 0; i < nl.getLength(); i++)
       {
         Node currNode = nl.item(i);
  -      String key = null;
  -      if (currNode instanceof DTMNodeProxy)
  -        key = ((DTMNodeProxy)currNode).getStringValue();
  -      else
  -        key = currNode.getNodeValue();
  +      String key = toString(currNode);
         
         if (key == null)
           dist.addElement(currNode);
  
  
  
  1.4       +3 -12     xml-xalan/java/src/org/apache/xalan/lib/ExsltStrings.java
  
  Index: ExsltStrings.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/ExsltStrings.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ExsltStrings.java	19 Sep 2002 14:54:04 -0000	1.3
  +++ ExsltStrings.java	23 Sep 2002 16:22:41 -0000	1.4
  @@ -57,14 +57,9 @@
   package org.apache.xalan.lib;
   
   import org.w3c.dom.*;
  -
  -import org.apache.xpath.XPath;
  -import org.apache.xpath.XPathContext;
  +import javax.xml.parsers.*;
   import org.apache.xpath.NodeSet;
  -import org.apache.xml.dtm.ref.DTMNodeProxy;
  -
   import java.util.StringTokenizer;
  -import javax.xml.parsers.*;
   
   /**
    * <meta name="usage" content="general"/>
  @@ -81,7 +76,7 @@
    * @see <a href="http://www.exslt.org/">EXSLT</a>
   
    */
  -public class ExsltStrings
  +public class ExsltStrings extends ExsltBase
   {
     // Reuse the Document object to reduce memory usage.
     private static Document lDoc = null;
  @@ -152,11 +147,7 @@
       for (int i = 0; i < nl.getLength(); i++)
       {
         Node node = nl.item(i);
  -      String value = null;
  -      if (node instanceof DTMNodeProxy)
  -        value = ((DTMNodeProxy)node).getStringValue();
  -      else
  -        value = node.getNodeValue();
  +      String value = toString(node);
         
         if (value != null && value.length() > 0)
           sb.append(value);
  
  
  
  1.1                  xml-xalan/java/src/org/apache/xalan/lib/ExsltBase.java
  
  Index: ExsltBase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.lib;
  
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.apache.xml.dtm.ref.DTMNodeProxy;
  
  /**
   * The base class for some EXSLT extension classes.
   * It contains common utility methods to be used by the sub-classes.
   */
  public abstract class ExsltBase
  {
    /**
     * Return the string value of a Node
     *
     * @param n The Node.
     * @return The string value of the Node
     */
    protected static String toString(Node n)
    {
      if (n instanceof DTMNodeProxy)
    	 return ((DTMNodeProxy)n).getStringValue();
      else
      {
        String value = n.getNodeValue();
        if (value == null)
        {
          NodeList nodelist = n.getChildNodes();
          StringBuffer buf = new StringBuffer();
          for (int i = 0; i < nodelist.getLength(); i++)
          {
            Node childNode = nodelist.item(i);
            buf.append(toString(childNode));
          }
          return buf.toString();
        }
        else
          return value;
      }
    }
    
    /**
     * Convert the string value of a Node to a number.
     * Return NaN if the string is not a valid number.
     *
     * @param n The Node.
     * @return The number value of the Node
     */
    protected static double toNumber(Node n)
    {
      double d = 0.0;
      String str = toString(n);
      try
      {
        d = Double.parseDouble(str);
      }
      catch (NumberFormatException e)
      {
        d= Double.NaN;  		
      }
      return d;
    }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org