|
From: <et...@us...> - 2011-06-16 01:37:16
|
Revision: 4406
http://mxquery.svn.sourceforge.net/mxquery/?rev=4406&view=rev
Author: etterth
Date: 2011-06-16 01:37:09 +0000 (Thu, 16 Jun 2011)
Log Message:
-----------
- Window events added
- Diverse bug fixes
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetLocation.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/WindowInfo.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/EventIterator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
Added Paths:
-----------
trunk/MXQuery/xqib_samples/lateresolve-behavior.html
trunk/MXQuery/xqib_samples/window-event.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddWindowListener.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveWindowListener.java
Added: trunk/MXQuery/xqib_samples/lateresolve-behavior.html
===================================================================
--- trunk/MXQuery/xqib_samples/lateresolve-behavior.html (rev 0)
+++ trunk/MXQuery/xqib_samples/lateresolve-behavior.html 2011-06-16 01:37:09 UTC (rev 4406)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+ declare updating function local:update() {
+ replace node b:dom()//div with <div>{concat('The window height is ', b:windowInfo()/b:client-height/text())}<br/>{concat('The window width is ', b:windowInfo()/b:client-width/text())}</div>
+ };
+ declare updating function local:listener($loc, $evtObj) {
+ local:update()
+ };
+local:update(),
+ b:addWindowListener("resize", local:listener#2)
+ </script>
+ </head>
+ <body>
+ <h1 id='a'>Window event</h1>
+<div/>
+ </body>
+</html>
Added: trunk/MXQuery/xqib_samples/window-event.html
===================================================================
--- trunk/MXQuery/xqib_samples/window-event.html (rev 0)
+++ trunk/MXQuery/xqib_samples/window-event.html 2011-06-16 01:37:09 UTC (rev 4406)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <script type="application/xquery">
+module namespace up = "update";
+ declare updating function up:update() {
+ replace node b:dom()//div with <div>{concat('The window height is ', b:windowInfo()/b:client-height/text())}<br/>{concat('The window width is ', b:windowInfo()/b:client-width/text())}</div>
+ };
+ </script>
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+import module namespace up = "update";
+ declare updating function local:listener($loc, $evtObj) {
+ up:update()
+ };
+up:update(),
+ b:addWindowListener("resize", local:listener#2)
+ </script>
+ </head>
+ <body>
+ <h1 id='a'>Window event</h1>
+<div/>
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -17,6 +17,7 @@
import ch.ethz.mxquery.iterators.browser.EventIterator;
import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
+import ch.ethz.mxquery.model.EmptySequenceIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -34,6 +35,7 @@
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.dom.client.Text;
@@ -47,6 +49,7 @@
static Context modCtx = new Context();
static CompilerOptions co;
static int contextcounter = 0;
+ private static Hashtable<String, List<FunctionItemToken>> windowhandlers;
public static CompilerOptions getCompilerOptions() {
if (co != null)
@@ -102,18 +105,17 @@
// modCtx = null;
co = null;
handlers = null;
+ windowhandlers = null;
}
- public static void addEventListener(JavaScriptObject obj, String eventName,
+ public static void addEventListener(Element el, String eventName,
FunctionItemToken fi, Context ctx) {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
- if (handlers == null)
+ if (handlers == null)
handlers = new Hashtable<NodeAndEventName, List<FunctionItemToken>>();
+
- if (JsToMxQuery.isNode(obj)) {
- //node
- Element el = (Element) obj;
NodeAndEventName test = new NodeAndEventName(el, eventName);
List<FunctionItemToken> lst = handlers.get(test);
if (lst == null) {
@@ -121,17 +123,37 @@
handlers.put(test, lst);
}
lst.add(fi);
+
+
+
+ nativeAddEventListener(el, eventName);
+ }
+
+ public static void addWindowListener(String eventName,
+ FunctionItemToken fi, Context ctx) {
+ if (eventName.startsWith("on"))
+ eventName = eventName.substring(2);
+ if (windowhandlers == null) {
+ windowhandlers = new Hashtable<String, List<FunctionItemToken>>();
}
- else {
- //window
- //TODO
-
- }
- nativeAddEventListener(obj, eventName);
+ List<FunctionItemToken> lst = windowhandlers.get(eventName);
+ if (lst == null) {
+ lst = new ArrayList<FunctionItemToken>();
+ windowhandlers.put(eventName, lst);
+ }
+ lst.add(fi);
+
+
+
+ nativeAddWindowListener(eventName);
}
- public static void removeEventListener(JavaScriptObject obj, String eventName,
+ private static native JavaScriptObject getWindowObject() /*-{
+ return $wnd;
+ }-*/;
+
+ public static void removeEventListener(Element el, String eventName,
FunctionItemToken fi, Context ctx) throws MXQueryException {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
@@ -140,8 +162,6 @@
"handler to remove cannot be found", null);
- if (JsToMxQuery.isNode(obj)) {
- Element el = (Element) obj;
NodeAndEventName test = new NodeAndEventName(el, eventName);
List<FunctionItemToken> lst = handlers.get(test);
if (lst == null) {
@@ -165,13 +185,46 @@
handlers.put(test, null);
nativeRemoveEventListener(el, eventName);
}
- } else {
- //window
- //TODO
- }
+
}
+
+ public static void removeWindowListener(String eventName,
+ FunctionItemToken fi, Context ctx) throws MXQueryException {
+ if (eventName.startsWith("on"))
+ eventName = eventName.substring(2);
+ if (windowhandlers == null)
+ throw new MXQueryException("Eventlistener cannot be removed",
+ "handler to remove cannot be found", null);
+
+ String test = eventName;
+ List<FunctionItemToken> lst = windowhandlers.get(test);
+ if (lst == null) {
+ throw new MXQueryException("Eventlistener cannot be removed",
+ "handler to remove cannot be found", null);
+ }
+ List<FunctionItemToken> lstnew = new ArrayList<FunctionItemToken>();
+ ListIterator<FunctionItemToken> it = lst.listIterator();
+
+ while (it.hasNext()) {
+ FunctionItemToken ft = it.next();
+ FunctionSignature fts = ft.getFunction().getFunctionSignature();
+ FunctionSignature fis = fi.getFunction().getFunctionSignature();
+ if (!fis.getName().equals(fts.getName())
+ || fts.getArity() != fis.getArity())
+ lstnew.add(ft);
+ }
+ windowhandlers.remove(test);
+ windowhandlers.put(test, lstnew);
+ if (lst.isEmpty()) {
+ windowhandlers.put(test, null);
+ nativeRemoveWindowListener(eventName);
+ }
+
+
+ }
+
public static void removeAnonymousEventListeners(Element el,
String eventName, Context ctx) throws MXQueryException {
if (eventName.startsWith("on"))
@@ -217,7 +270,15 @@
test.node = test.node.getParentElement();
}
for (FunctionItemToken fi : handlers.get(test)) {
- SingleNodeIterator nodeiter = new SingleNodeIterator(test.node);
+ Iterator nodeiter;
+ final EventTarget eventTarget = event.getEventTarget();
+ if (JsToMxQuery.isNode(eventTarget)) {
+
+ nodeiter = new SingleNodeIterator((Node) (Object)eventTarget);
+ }
+ else {
+ nodeiter = new EmptySequenceIterator(null, null);
+ }
try {
// TODO: remove name reference - inline functions don't have a
// name
@@ -244,7 +305,53 @@
event.stopPropagation();
event.preventDefault();
}
+ /**
+ * the callback called by any listened window event
+ *
+ * @param event
+ */
+ public static void windowEventCallback(NativeEvent event) {
+ // TODO add arity
+ Logger log = Logger.getLogger(Environment.class.toString());
+ log.log(LogLevel.FINER, "Got a window event: " + event.getString());
+ for (FunctionItemToken fi : windowhandlers.get(event.getType())) {
+ Iterator nodeiter;
+ final EventTarget eventTarget = event.getEventTarget();
+ if (JsToMxQuery.isNode(eventTarget)) {
+
+ nodeiter = new SingleNodeIterator((Node) (Object)eventTarget);
+ }
+ else {
+ nodeiter = new EmptySequenceIterator(null, null);
+ }
+ try {
+ // TODO: remove name reference - inline functions don't have a
+ // name
+ // log.log(LogLevel.FINER, "Calling eventcallback " +
+ // fi.getFunction().getFunctionSignature().getName().toString());
+ ListBasedIterator eventiter = new EventIterator(event);
+ eventiter.setContext(new Context(), true);
+ Iterator[] subiterators = { nodeiter, eventiter };
+
+ Environment.invokeModule(fi, subiterators);
+ // log.log(LogLevel.FINER, "Eventcallback " +
+ // fi.getFunction().getFunctionSignature().getName().toString()
+ // + " done");
+ eventiter = null;
+ subiterators = null;
+ nodeiter = null;
+ } catch (MXQueryException e) {
+ Environment.displayErrorMessage(new StringBuffer(), null, e,
+ true);
+ e.printStackTrace();
+ }
+ }
+ // TODO decide this dynamically
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
public static void invokeModule(FunctionItemToken ft,
XDMIterator[] subiterators) throws MXQueryException {
preProcessDocument();
@@ -340,24 +447,32 @@
// }
// }
private static final native void nativeAddEventListener(
- JavaScriptObject obj, String eventName)/*-{
- // el.addEventListener('click', function (ev) {$wnd.alert('test');}, false);
- if (el.addEventListener){//good browser
- el.addEventListener(eventName, @ch.ethz.mxqjs.client.Environment::eventCallback(Lcom/google/gwt/dom/client/NativeEvent;), false);
- }
- else {//bad browser
- el.attachEvent('on' + eventName, @ch.ethz.mxqjs.client.Environment::eventCallback(Lcom/google/gwt/dom/client/NativeEvent;));
-
- }
-
- }-*/;
+ Element el, String eventName)/*-{
+ // el.addEventListener('click', function (ev) {$wnd.alert('test');}, false);
+ el.addEventListener(eventName, @ch.ethz.mxqjs.client.Environment::eventCallback(Lcom/google/gwt/dom/client/NativeEvent;), false);
+
+ }-*/;
+ private static final native void nativeAddWindowListener(String eventName)/*-{
+
+ $wnd.addEventListener(eventName, @ch.ethz.mxqjs.client.Environment::windowEventCallback(Lcom/google/gwt/dom/client/NativeEvent;), false);
+
+
+ }-*/;
+
private static final native void nativeRemoveEventListener(Element el,
String eventName)/*-{
// el.addEventListener('click', function (ev) {$wnd.alert('test');}, false);
el.removeEventListener(eventName, @ch.ethz.mxqjs.client.Environment::eventCallback(Lcom/google/gwt/dom/client/NativeEvent;), false);
}-*/;
+
+ private static final native void nativeRemoveWindowListener(String eventName)/*-{
+ // el.addEventListener('click', function (ev) {$wnd.alert('test');}, false);
+ $wnd.removeEventListener(eventName, @ch.ethz.mxqjs.client.Environment::windowEventCallback(Lcom/google/gwt/dom/client/NativeEvent;), false);
+ }-*/;
+
+
public static void displayErrorMessage(StringBuffer queryResult,
String query, MXQueryException err, boolean compiled) {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-06-16 01:37:09 UTC (rev 4406)
@@ -154,35 +154,33 @@
<paramType>xs:string</paramType>
</parameters>
<className>AddClassName</className>
- </functionDescription><functionDescription>
- <functionName>addEventListener</functionName>
+ </functionDescription>
+ <functionDescription>
+ <functionName>addWindowListener</functionName>
<parameters>
- <paramType>node()+</paramType>
+
<paramType>xs:string</paramType>
- <paramType>QName</paramType>
- <paramType>xs:integer</paramType>
+ <paramType>function()</paramType>
</parameters>
- <className>AddEventListener</className>
+ <className>AddWindowListener</className>
</functionDescription>
<functionDescription>
- <functionName>addEventListener</functionName>
+ <functionName>removeWindowListener</functionName>
<parameters>
- <paramType>node()+</paramType>
<paramType>xs:string</paramType>
<paramType>function()</paramType>
</parameters>
- <className>AddEventListener</className>
+ <className>RemoveWindowListener</className>
</functionDescription>
<functionDescription>
- <functionName>removeEventListener</functionName>
+ <functionName>addEventListener</functionName>
<parameters>
<paramType>node()+</paramType>
<paramType>xs:string</paramType>
- <paramType>QName</paramType>
- <paramType>xs:integer</paramType>
+ <paramType>function()</paramType>
</parameters>
- <className>RemoveEventListener</className>
- </functionDescription>
+ <className>AddEventListener</className>
+ </functionDescription>
<functionDescription>
<functionName>removeEventListener</functionName>
<parameters>
@@ -192,7 +190,16 @@
</parameters>
<className>RemoveEventListener</className>
</functionDescription>
+
<functionDescription>
+ <functionName>removeAnonymousEventListeners</functionName>
+ <parameters>
+ <paramType>node()</paramType>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className>RemoveAnonymousEventListener</className>
+ </functionDescription>
+ <functionDescription>
<functionName>dom</functionName>
<className>Dom</className>
</functionDescription>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -42,7 +42,6 @@
TypeInfo function__ = new TypeInfo(FunctionGallery.getType("function()",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
TypeInfo xs_dateTime = new TypeInfo(FunctionGallery.getType("xs:dateTime",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
TypeInfo node___plus = new TypeInfo(FunctionGallery.getType("node()+",ctx), Type.OCCURRENCE_IND_ONE_OR_MORE,null);
- TypeInfo QName = new TypeInfo(FunctionGallery.getType("QName",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
TypeInfo node__ = new TypeInfo(FunctionGallery.getType("node()",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
TypeInfo xs_string_quest = new TypeInfo(FunctionGallery.getType("xs:string?",ctx), Type.OCCURRENCE_IND_ZERO_OR_ONE,null);
TypeInfo numeric_quest = new TypeInfo(FunctionGallery.getType("numeric?",ctx), Type.OCCURRENCE_IND_ZERO_OR_ONE,null);
@@ -540,17 +539,15 @@
qn = new QName(
"http://xqib.org",
"b",
- "addEventListener");
- paramTypes = new TypeInfo[4];
+ "addWindowListener");
+ paramTypes = new TypeInfo[2];
- paramTypes[0] = node___plus;
- paramTypes[1] = xs_string;
- paramTypes[2] = QName;
- paramTypes[3] = xs_integer;
+ paramTypes[0] = xs_string;
+ paramTypes[1] = function__;
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
{
- ch.ethz.mxquery.functions.b.AddEventListener iter = new ch.ethz.mxquery.functions.b.AddEventListener();
+ ch.ethz.mxquery.functions.b.AddWindowListener iter = new ch.ethz.mxquery.functions.b.AddWindowListener();
iter.setContext(context, false);
type = null;
@@ -564,6 +561,28 @@
qn = new QName(
"http://xqib.org",
"b",
+ "removeWindowListener");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = xs_string;
+ paramTypes[1] = function__;
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.RemoveWindowListener iter = new ch.ethz.mxquery.functions.b.RemoveWindowListener();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"addEventListener");
paramTypes = new TypeInfo[3];
@@ -588,12 +607,11 @@
"http://xqib.org",
"b",
"removeEventListener");
- paramTypes = new TypeInfo[4];
+ paramTypes = new TypeInfo[3];
- paramTypes[0] = node___plus;
+ paramTypes[0] = node__;
paramTypes[1] = xs_string;
- paramTypes[2] = QName;
- paramTypes[3] = xs_integer;
+ paramTypes[2] = function__;
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
{
@@ -611,16 +629,15 @@
qn = new QName(
"http://xqib.org",
"b",
- "removeEventListener");
- paramTypes = new TypeInfo[3];
+ "removeAnonymousEventListeners");
+ paramTypes = new TypeInfo[2];
paramTypes[0] = node__;
paramTypes[1] = xs_string;
- paramTypes[2] = function__;
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
{
- ch.ethz.mxquery.functions.b.RemoveEventListener iter = new ch.ethz.mxquery.functions.b.RemoveEventListener();
+ ch.ethz.mxquery.functions.b.RemoveAnonymousEventListener iter = new ch.ethz.mxquery.functions.b.RemoveAnonymousEventListener();
iter.setContext(context, false);
type = null;
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddWindowListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddWindowListener.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddWindowListener.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -0,0 +1,51 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import ch.ethz.mxqjs.client.Environment;
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class AddWindowListener extends TokenBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ currentToken = Token.END_SEQUENCE_TOKEN;
+ String eventname;
+
+ eventname = getStringValue(subIters[0]);
+ XDMIterator functioniter = subIters[1];
+ TokenInterface functiontoken = functioniter.next();
+
+ if (functiontoken.getEventType() != Type.FUNCTION_ITEM || functioniter.next().getEventType() != Type.END_SEQUENCE)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Function Item expected", loc);
+
+ addWindowHandler(eventname, (FunctionItemToken)functiontoken);
+ }
+
+ private void addWindowHandler( String eventname,
+ FunctionItemToken fi) throws MXQueryException {
+
+ Context ctx = this.getContext().getRootContext();
+ Environment.addWindowListener(eventname, fi,ctx);
+
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new AddWindowListener();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetLocation.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetLocation.java 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetLocation.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -32,7 +32,10 @@
protected void init() throws MXQueryException {
lst = new LinkedList<TokenInterface>();
- this.addTextElement("hash", Location.getHash());
+
+ QName qn = new QName(namespace.getURI(),namespace.getNamespacePrefix(),"location");
+ lst.add(new ElementToken(Type.START_TAG, null, qn,scope));
+ this.addTextElement("hash", Location.getHash());
this.addTextElement("host", Location.getHost());
this.addTextElement("hostname", Location.getHostName());
this.addTextElement("href", Location.getHref());
@@ -41,7 +44,8 @@
this.addTextElement("protocol", Location.getProtocol());
// this.addTextElement("search", Location.getSearch());
appendParameters();
-
+
+ lst.add(new ElementToken(Type.END_TAG, null, qn,scope));
// addTextElement(tagname, content);
// TODO Auto-generated method stub
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveWindowListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveWindowListener.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveWindowListener.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -0,0 +1,50 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import ch.ethz.mxqjs.client.Environment;
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class RemoveWindowListener extends TokenBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ currentToken = Token.END_SEQUENCE_TOKEN;
+ String eventname;
+
+ eventname = getStringValue(subIters[0]);
+ XDMIterator functioniter = subIters[1];
+ TokenInterface functiontoken = functioniter.next();
+
+ if (functiontoken.getEventType() != Type.FUNCTION_ITEM || functioniter.next().getEventType() != Type.END_SEQUENCE)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Function Item expected", loc);
+
+ addWindowHandler(eventname, (FunctionItemToken)functiontoken);
+ }
+
+ private void addWindowHandler( String eventname,
+ FunctionItemToken fi) throws MXQueryException {
+
+ Context ctx = this.getContext().getRootContext();
+ Environment.removeWindowListener(eventname, fi,ctx);
+
+ }
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new RemoveWindowListener();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/WindowInfo.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/WindowInfo.java 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/WindowInfo.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -1,28 +1,46 @@
package ch.ethz.mxquery.functions.b;
+import java.util.LinkedList;
import java.util.Vector;
import com.google.gwt.user.client.Window;
import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.Namespace;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.ElementToken;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class WindowInfo extends ListBasedIterator {
+ public WindowInfo() {
+ this.namespace = new Namespace(Context.NS_BROWSER, Context.URI_BROWSER);
+ }
+
@Override
protected void init() throws MXQueryException {
+ lst = new LinkedList<TokenInterface>();
+
+ QName qn = new QName(namespace.getURI(),namespace.getNamespacePrefix(),"window-info");
+
+ lst.add(new ElementToken(Type.START_TAG, null, qn,scope));
addIntegerElement("client-height", Window.getClientHeight());
- addIntegerElement("client-height", Window.getClientWidth());
+ addIntegerElement("client-width", Window.getClientWidth());
addIntegerElement("scroll-left", Window.getScrollLeft());
addIntegerElement("scroll-top", Window.getScrollTop());
+ lst.add(new ElementToken(Type.END_TAG, null, qn,scope));
}
@Override
- protected XDMIterator copy(Context context, XDMIterator[] subIters,
- Vector nestedPredCtxStack) throws MXQueryException {
- return new WindowInfo();
- }
-
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack)
+ throws MXQueryException {
+ XDMIterator ret = new WindowInfo();
+ ret.setSubIters(subIters);
+ ret.setContext(context, false);
+ return ret;
+ }
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/EventIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/EventIterator.java 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/EventIterator.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -30,8 +30,8 @@
@Override
protected void init() throws MXQueryException {
lst = new LinkedList<TokenInterface>();
- QName qn = new QName("event");
- lst.add(new ElementToken(Type.START_TAG, null, qn,null));
+ QName qn = new QName(namespace.getURI(),namespace.getNamespacePrefix(),"event");
+ lst.add(new ElementToken(Type.START_TAG, null, qn,scope));
String type = event.getType();
if (isMouseEvent(type)){
addIntegerElement("screenX", event.getScreenX());
@@ -44,8 +44,7 @@
addElementIfTrue("metaKey", event.getMetaKey());
addTextElement("button", buttonToString(event.getButton()));
}
- lst.add(new ElementToken(Type.END_TAG, null, qn,null));
- lst.add(Token.END_SEQUENCE_TOKEN);
+ lst.add(new ElementToken(Type.END_TAG, null, qn,scope));
}
protected boolean isMouseEvent(String type) {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java 2011-06-15 17:51:06 UTC (rev 4405)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java 2011-06-16 01:37:09 UTC (rev 4406)
@@ -20,16 +20,18 @@
boolean multipletokens;
public SingleNodeIterator(Node store) {
super(store);
+ if (store != null) {
short nt = store.getNodeType();
multipletokens = nt == Node.ELEMENT_NODE
|| nt == Node.DOCUMENT_NODE;
+ }
}
@Override
public TokenInterface next() throws MXQueryException {
- if (finished)
+ if (this.store == null || finished)
return Token.END_SEQUENCE_TOKEN;
-
+
if (!multipletokens && called >= 1)
return Token.END_SEQUENCE_TOKEN;
TokenInterface tok = super.next();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|