|
From: <et...@us...> - 2011-06-20 03:07:53
|
Revision: 4411
http://mxquery.svn.sourceforge.net/mxquery/?rev=4411&view=rev
Author: etterth
Date: 2011-06-20 03:07:47 +0000 (Mon, 20 Jun 2011)
Log Message:
-----------
- Fix for document order (using native browser function)
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java 2011-06-20 02:34:37 UTC (rev 4410)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java 2011-06-20 03:07:47 UTC (rev 4411)
@@ -84,38 +84,48 @@
return -1;
if (other.node == this.node)
return 0;
- Node tmpnode = node;
- LinkedList<Node> thislistfromtopparent = new LinkedList<Node>();
- while (tmpnode != null){
- thislistfromtopparent.add(0, tmpnode);
- tmpnode = tmpnode.getParentNode();
- }
- tmpnode = other.node;
- LinkedList<Node> otherlistfromtopparent = new LinkedList<Node>();
- while (tmpnode != null){
- otherlistfromtopparent.add(0, tmpnode);
- tmpnode = tmpnode.getParentNode();
- }
- int smallest = Math.min(thislistfromtopparent.size(), otherlistfromtopparent.size());
- int i;
- for (i=0;i<smallest;i++){
- if (thislistfromtopparent.get(i) != otherlistfromtopparent.get(i)){
- break;
- }
- }
+ short comp = this.node.compareDocumentPosition(other.node);
+ if ((comp | Node.DOCUMENT_POSITION_PRECEDING) != 0 ||
+ (comp | Node.DOCUMENT_POSITION_CONTAINS) != 0)//the other is parent
+ return -1;
- if (i==smallest){//there was no difference
- return 0;
- }
- //TODO this seems wrong
- Node first = thislistfromtopparent.get(i);
- Node second = otherlistfromtopparent.get(i);
- while (first != null && first!= second ){
- first = first.getNextSibling();
- }
- if (first == null)//first was after second
- return -1;
- return 1;
+ if ((comp | Node.DOCUMENT_POSITION_FOLLOWING) != 0 ||
+ (comp | Node.DOCUMENT_POSITION_CONTAINED_BY) != 0)//the other is child
+ return 1;
+ return -2;
+
+// Node tmpnode = node;
+// LinkedList<Node> thislistfromtopparent = new LinkedList<Node>();
+// while (tmpnode != null){
+// thislistfromtopparent.add(0, tmpnode);
+// tmpnode = tmpnode.getParentNode();
+// }
+// tmpnode = other.node;
+// LinkedList<Node> otherlistfromtopparent = new LinkedList<Node>();
+// while (tmpnode != null){
+// otherlistfromtopparent.add(0, tmpnode);
+// tmpnode = tmpnode.getParentNode();
+// }
+// int smallest = Math.min(thislistfromtopparent.size(), otherlistfromtopparent.size());
+// int i;
+// for (i=0;i<smallest;i++){
+// if (thislistfromtopparent.get(i) != otherlistfromtopparent.get(i)){
+// break;
+// }
+// }
+//
+// if (i==smallest){//there was no difference
+// return 0;
+// }
+// //TODO this seems wrong
+// Node first = thislistfromtopparent.get(i);
+// Node second = otherlistfromtopparent.get(i);
+// while (first != null && first!= second ){
+// first = first.getNextSibling();
+// }
+// if (first == null)//first was after second
+// return -1;
+// return 1;
}
public Node getNode(){
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java 2011-06-20 02:34:37 UTC (rev 4410)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java 2011-06-20 03:07:47 UTC (rev 4411)
@@ -5,9 +5,14 @@
import ch.ethz.mxquery.datamodel.types.Type;
public class Node extends JavaScriptObject {
+
+ public final static short DOCUMENT_POSITION_DISCONNECTED = 0;
+ public final static short DOCUMENT_POSITION_PRECEDING = 2;
+ public final static short DOCUMENT_POSITION_FOLLOWING = 4;
+ public final static short DOCUMENT_POSITION_CONTAINS = 8;
+ public final static short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
+ public final static short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
-
-
protected Node() {
}
@@ -377,4 +382,12 @@
public final void setNodeValue(String nodeValue) {
DOMImpl.impl.nodeSetValue(this, nodeValue);
}
+
+ /**
+ * The value of this node, depending on its type; see the table above. When
+ * it is defined to be null, setting it has no effect.
+ */
+ public final native short compareDocumentPosition(Node other) /*-{
+ return this.compareDocumentPosition(other);
+ }-*/;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|