zongaro 2003/06/28 08:09:53
Modified: java/src/org/apache/xpath XPathContext.java
java/src/org/apache/xpath/functions FuncCurrent.java
Log:
Applied Igor Hersht's ([EMAIL PROTECTED]) patch for Bugzilla bug 10900. Fixed
up algorithm for determining the result of the current() function to avoid
NullPointerException.
Revision Changes Path
1.49 +4 -12 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.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- XPathContext.java 30 Jan 2003 18:46:22 -0000 1.48
+++ XPathContext.java 28 Jun 2003 15:09:53 -0000 1.49
@@ -993,20 +993,12 @@
*
* @return the <a
href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>.
*/
- public org.apache.xpath.axes.LocPathIterator getCurrentNodeList()
+
+ public org.apache.xpath.axes.SubContextList getCurrentNodeList()
{
- for (int i = m_axesIteratorStack.size()-1; i >= 0; i--)
- {
- org.apache.xpath.axes.PredicatedNodeTest iter
- =
(org.apache.xpath.axes.PredicatedNodeTest)m_axesIteratorStack.elementAt(i);
- org.apache.xpath.axes.LocPathIterator lpi = iter.getLocPathIterator();
- if(lpi.getIsTopLevel())
- return lpi;
- }
- return null;
+ return m_axesIteratorStack.isEmpty()
+ ? null : (SubContextList) m_axesIteratorStack.elementAt(0);
}
-
-
//==========================================================
// SECTION: Implementation of ExpressionContext interface
//==========================================================
1.11 +21 -39
xml-xalan/java/src/org/apache/xpath/functions/FuncCurrent.java
Index: FuncCurrent.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncCurrent.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FuncCurrent.java 30 Jan 2003 18:46:26 -0000 1.10
+++ FuncCurrent.java 28 Jun 2003 15:09:53 -0000 1.11
@@ -63,6 +63,11 @@
import org.apache.xpath.axes.PredicatedNodeTest;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XObject;
+import org.apache.xpath.axes.SubContextList;
+import org.apache.xpath.patterns.StepPattern;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
+
/**
* <meta name="usage" content="advanced"/>
@@ -81,46 +86,23 @@
*/
public XObject execute(XPathContext xctxt) throws
javax.xml.transform.TransformerException
{
- // If we're in a predicate, then this will return non-null.
- Object subContextList = xctxt.getSubContextList();
- int currentNode;
-
- // %TBD% Hack city...
- if (null != subContextList && subContextList instanceof
PredicatedNodeTest)
- {
- // PredicatedNodeTest iter = (PredicatedNodeTest)
xctxt.getSubContextList();
- // LocPathIterator lpi = iter.getLocPathIterator();
- LocPathIterator lpi = xctxt.getCurrentNodeList();
-
- currentNode = lpi.getCurrentContextNode();
-
- }
- else if(xctxt.getIteratorRoot() != DTM.NULL)
- {
- currentNode = xctxt.getIteratorRoot();
+
+ SubContextList subContextList = xctxt.getCurrentNodeList();
+ int currentNode = DTM.NULL;
+
+ if (null != subContextList) {
+ if (subContextList instanceof PredicatedNodeTest) {
+ LocPathIterator iter = ((PredicatedNodeTest)subContextList)
+
.getLocPathIterator();
+ currentNode = iter.getCurrentContextNode();
+ } else if(subContextList instanceof StepPattern) {
+ throw new RuntimeException(XSLMessages.createMessage(
+ XSLTErrorResources.ER_PROCESSOR_ERROR,null));
+ }
+ } else {
+ // not predicate => ContextNode == CurrentNode
+ currentNode = xctxt.getContextNode();
}
- else
- {
- DTMIterator cnl = xctxt.getContextNodeList();
-
- if (null != cnl)
- {
- // %REVIEW% Not so certain that this is doing the right thing?
- currentNode = cnl.getCurrentNode();
- }
- else
- currentNode = DTM.NULL;
- }
- // if(DTM.NULL != currentNode)
- // {
- // DTM dtm = xctxt.getDTM(currentNode);
- // System.err.println("current node:
"+dtm.getNodeName(currentNode)+"["+Integer.toHexString(currentNode)+"]");
- // }
- // else
- // {
- // System.err.println("current node: DTM.NULL");
- // }
-
return new XNodeSet(currentNode, xctxt.getDTMManager());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]