You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/07/31 00:44:37 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath XPathContext.java

sboag       00/07/30 15:44:37

  Modified:    java/src/org/apache/xpath XPathContext.java
  Log:
  Implement ExpressionContext.
  
  Revision  Changes    Path
  1.2       +62 -6     xml-xalan/java/src/org/apache/xpath/XPathContext.java
  
  Index: XPathContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XPathContext.java	2000/07/05 14:44:26	1.1
  +++ XPathContext.java	2000/07/30 22:44:36	1.2
  @@ -69,16 +69,20 @@
   import org.apache.xalan.utils.QName;
   import org.apache.xalan.res.XSLMessages;
   import org.apache.xpath.res.XPATHErrorResources;
  -import org.apache.xpath.objects.XObject;
   import org.apache.xpath.axes.ContextNodeList;
   import org.apache.xpath.axes.SubContextList;
   
  +import org.apache.xpath.objects.XObject;
  +import org.apache.xpath.objects.XNodeSet;
  +
   
   // DOM Imports
   import org.w3c.dom.traversal.NodeIterator;
   import org.w3c.dom.traversal.TreeWalker;
   import org.w3c.dom.Node;
   
  +import org.w3c.xslt.ExpressionContext;
  +
   // SAX2 imports
   import org.xml.sax.ErrorHandler;
   import org.xml.sax.SAXException;
  @@ -95,12 +99,9 @@
   
   /**
    * <meta name="usage" content="advanced"/>
  - * Default class for the execution context for XPath. Many 
  - * of the functions in this class need to be overridden in order to 
  - * perform correct execution of the XPath (for instance, variable 
  - * execution).
  + * Default class for the runtime execution context for XPath.
    */
  -public class XPathContext
  +public class XPathContext implements ExpressionContext
   {
     /**
      * Create an XPathContext instance.
  @@ -503,5 +504,60 @@
              ? null : (SubContextList)m_axesIteratorStack.peek();
                                              
     }
  +
  +  //==========================================================
  +  // SECTION: Implementation of ExpressionContext interface
  +  //==========================================================
  +
  +  /**
  +   * Get the current context node.
  +   * @return The current context node.
  +   */
  +  public Node getContextNode()
  +  {
  +    return this.getCurrentNode();
  +  }
  +  
  +  /**
  +   * Get the current context node list.
  +   * @return An iterator for the current context list, as 
  +   * defined in XSLT.
  +   */
  +  public NodeIterator getContextNodes()
  +  {
  +    try
  +    {
  +    ContextNodeList cnl = getContextNodeList();
  +    if(null != cnl)
  +      return cnl.cloneWithReset();
  +    else
  +      return null; // for now... this might ought to be an empty iterator.
  +    }
  +    catch(CloneNotSupportedException cnse)
  +    {
  +      return null; // error reporting?
  +    }
  +  }
  +
  +  /**
  +   * Get the value of a node as a number.
  +   * @param n Node to be converted to a number.  May be null.
  +   * @return value of n as a number.
  +   */
  +  public double toNumber(Node n)
  +  {
  +    return XNodeSet.getNumberFromNode(n);
  +  }
  +
  +  /**
  +   * Get the value of a node as a string.
  +   * @param n Node to be converted to a string.  May be null.
  +   * @return value of n as a string, or an empty string if n is null.
  +   */
  +  public String toString(Node n)
  +  {
  +    return XNodeSet.getStringFromNode(n);
  +  }
  +
   
   }