You can subscribe to this list here.
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(71) |
Jun
(43) |
Jul
(9) |
Aug
(10) |
Sep
(21) |
Oct
(38) |
Nov
|
Dec
(11) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2012 |
Jan
|
Feb
(21) |
Mar
(9) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <pm_...@us...> - 2012-02-07 08:43:25
|
Revision: 4514
http://mxquery.svn.sourceforge.net/mxquery/?rev=4514&view=rev
Author: pm_fischer
Date: 2012-02-07 08:43:19 +0000 (Tue, 07 Feb 2012)
Log Message:
-----------
Resolved merge with upstream
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java 2012-02-06 21:12:47 UTC (rev 4513)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java 2012-02-07 08:43:19 UTC (rev 4514)
@@ -217,4 +217,4 @@
*/
public abstract ObjectObjectPair getProjectionPaths() throws StaticException;
-}
\ No newline at end of file
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2012-02-06 21:12:47 UTC (rev 4513)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2012-02-07 08:43:19 UTC (rev 4514)
@@ -387,7 +387,11 @@
throw new DynamicException(ErrorCodes.U0021_UPDATE_DYNAMIC_INVALID_XDM,"Duplicate attribute names in updates",null);
else
seenAttrNames.add(attName);
- }
+ }
+ } else {
+ if (seenAttrNames.size() > 0)
+ seenAttrNames = new Set();
+ }
else {
if (seenAttrNames.size() > 0)
seenAttrNames = new Set();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2012-02-06 21:12:53
|
Revision: 4513
http://mxquery.svn.sourceforge.net/mxquery/?rev=4513&view=rev
Author: etterth
Date: 2012-02-06 21:12:47 +0000 (Mon, 06 Feb 2012)
Log Message:
-----------
- Fail the build if the GWT compilation fails
Modified Paths:
--------------
trunk/MXQuery/build.xml
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2012-02-06 17:29:43 UTC (rev 4512)
+++ trunk/MXQuery/build.xml 2012-02-06 21:12:47 UTC (rev 4513)
@@ -805,7 +805,7 @@
<echo message="Compiling with GWT..."/>
- <java classpathref="run.MXQueryJS.classpath" fork="true"
+ <java classpathref="run.MXQueryJS.classpath" fork="true" failonerror="true"
classname="com.google.gwt.dev.Compiler">
<arg line="-war ${gwt_war.dir}/"/>
<arg line="-style OBFUSCATED"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2012-02-06 17:29:50
|
Revision: 4512
http://mxquery.svn.sourceforge.net/mxquery/?rev=4512&view=rev
Author: pm_fischer
Date: 2012-02-06 17:29:43 +0000 (Mon, 06 Feb 2012)
Log Message:
-----------
Fix wrongly initialized contexts for order by
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2012-02-01 13:10:51 UTC (rev 4511)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2012-02-06 17:29:43 UTC (rev 4512)
@@ -63,7 +63,6 @@
import ch.ethz.mxquery.functions.ft.ScoreSequence;
import ch.ethz.mxquery.iterators.AdditiveIterator;
import ch.ethz.mxquery.iterators.AttributeIterator;
-import ch.ethz.mxquery.iterators.AxisIterator;
import ch.ethz.mxquery.iterators.CastAsIterator;
import ch.ethz.mxquery.iterators.ChildIterator;
import ch.ethz.mxquery.iterators.ClosureIterator;
@@ -136,6 +135,7 @@
import ch.ethz.mxquery.iterators.update.ReplaceIterator;
import ch.ethz.mxquery.iterators.update.StripTypeIterator;
import ch.ethz.mxquery.iterators.update.TransformIterator;
+import ch.ethz.mxquery.model.StepInformation;
import ch.ethz.mxquery.model.Constants;
import ch.ethz.mxquery.model.EmptySequenceIterator;
import ch.ethz.mxquery.model.Iterator;
@@ -3915,14 +3915,14 @@
inscopevars[i], true, getCurrentLoc());
// orderedVars[i].setResettable(true);
}
- createNewContextScope();
+ extendCurrentContextScope();
for (int i = 0; i < inscopevars.length; i++) {
getCurrentContext().registerVariable(inscopevars[i], true);
}
GOrderByIterator ret = new GOrderByIterator(getCurrentContext(), getCurrentLoc(),
arrOptions, stable, orderedVars, arrExprs);
- removeContextScope();
+ //removeContextScope();
return ret;
}
@@ -5225,7 +5225,7 @@
switch (state) {
case STATE_INIT:
if (currIt instanceof FullAxisIterator) {
- if ((((AxisIterator) currIt).getDirection() & AxisIterator.BACKWARD_AXIS_MASK) == 0)
+ if ((((StepInformation) currIt).getDirection() & StepInformation.BACKWARD_AXIS_MASK) == 0)
state = STATE_INIT;
else
state = STATE_DUP;
@@ -5265,7 +5265,7 @@
break;
case STATE_ONEDUP_NOSORT:
if (currIt instanceof FullAxisIterator) {
- if ((((AxisIterator) currIt).getDirection() & AxisIterator.BACKWARD_AXIS_MASK) == 0)
+ if ((((StepInformation) currIt).getDirection() & StepInformation.BACKWARD_AXIS_MASK) == 0)
state = STATE_ONEDUP;
else
state = STATE_DUP;
@@ -5871,7 +5871,7 @@
TypeInfo stepData = new TypeInfo(Type.TYPE_NK_ANY_NODE_TEST,
Type.OCCURRENCE_IND_EXACTLY_ONE);
return genIteratorFromPathStep(stepData,
- AxisIterator.AXIS_PARENT);
+ StepInformation.AXIS_PARENT);
} else {
throw new StaticException(
ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
@@ -5882,16 +5882,16 @@
} else {
int axis = -1;
if ((step = parseStringGetResult("parent::", false)) != null) {
- axis = AxisIterator.AXIS_PARENT;
+ axis = StepInformation.AXIS_PARENT;
} else if ((step = parseStringGetResult("ancestor::", false)) != null) {
- axis = AxisIterator.AXIS_ANCESTOR;
+ axis = StepInformation.AXIS_ANCESTOR;
} else if ((step = parseStringGetResult("preceding-sibling::",
false)) != null) {
- axis = AxisIterator.AXIS_PRECEDING_SIBLING;
+ axis = StepInformation.AXIS_PRECEDING_SIBLING;
} else if ((step = parseStringGetResult("preceding::", false)) != null) {
- axis = AxisIterator.AXIS_PRECEDING;
+ axis = StepInformation.AXIS_PRECEDING;
} else if ((step = parseStringGetResult("ancestor-or-self::", false)) != null) {
- axis = AxisIterator.AXIS_SELF_ANCESTOR;
+ axis = StepInformation.AXIS_SELF_ANCESTOR;
}
if (axis != -1) {
TypeInfo stepData = NodeTest();
@@ -5930,10 +5930,10 @@
} else if ((stepData = NodeTest()) != null) {
if (descendantOrSelf)
return genIteratorFromPathStep(stepData,
- AxisIterator.AXIS_DESCENDANT);
+ StepInformation.AXIS_DESCENDANT);
else
return genIteratorFromPathStep(stepData,
- AxisIterator.AXIS_CHILD);
+ StepInformation.AXIS_CHILD);
} else {
int axis = -1;
@@ -5942,7 +5942,7 @@
// child::... => //...
stepData = NodeTest();
return genIteratorFromPathStep(stepData,
- AxisIterator.AXIS_DESCENDANT);
+ StepInformation.AXIS_DESCENDANT);
} else
// should this also change?
@@ -5952,7 +5952,7 @@
if ((stepData = NodeTest()) != null) {
return genIteratorFromPathStep(stepData,
- AxisIterator.AXIS_DESCENDANT);
+ StepInformation.AXIS_DESCENDANT);
// return new DescendantOrSelfIterator(getCurrentContext(),
// stepData, getCurrentLoc(),
// DescendantOrSelfIterator.DESC_AXIS_DESCENDANT);
@@ -5967,7 +5967,7 @@
if (descendantOrSelf) {
return new DescendantOrSelfIterator(
getCurrentContext(), stepData, getCurrentLoc(),
- AxisIterator.AXIS_SELF_DESCENDANT);
+ StepInformation.AXIS_SELF_DESCENDANT);
} else
return new SelfAxisIterator(getCurrentContext(),
stepData, getCurrentLoc());
@@ -5983,7 +5983,7 @@
} else {
if ((stepData = NodeTest()) != null) {
return genIteratorFromPathStep(stepData,
- AxisIterator.AXIS_SELF_DESCENDANT);
+ StepInformation.AXIS_SELF_DESCENDANT);
// return new DescendantOrSelfIterator(
// getCurrentContext(),
// stepData,
@@ -5994,9 +5994,9 @@
} else if ((step = parseStringGetResult("following-sibling::",
false)) != null) {
- axis = AxisIterator.AXIS_FOLLOWING_SIBLING;
+ axis = StepInformation.AXIS_FOLLOWING_SIBLING;
} else if ((step = parseStringGetResult("following::", false)) != null) {
- axis = AxisIterator.AXIS_FOLLOWING;
+ axis = StepInformation.AXIS_FOLLOWING;
} else if (parseStringAndStay("(#", true, false)) {
return null;
}
@@ -6019,8 +6019,8 @@
// -- attribute kind test
if (Type.isAttribute(stepData.getType())) {
boolean descendantOrSelf = false;
- if (axis == AxisIterator.AXIS_DESCENDANT
- || axis == AxisIterator.AXIS_SELF_DESCENDANT)
+ if (axis == StepInformation.AXIS_DESCENDANT
+ || axis == StepInformation.AXIS_SELF_DESCENDANT)
descendantOrSelf = true;
return new AttributeIterator(getCurrentContext(), stepData,
descendantOrSelf, getCurrentLoc());
@@ -6032,13 +6032,13 @@
stepData.setType(Type.START_TAG);
}
switch (axis) {
- case AxisIterator.AXIS_DESCENDANT:
+ case StepInformation.AXIS_DESCENDANT:
return new DescendantOrSelfIterator(getCurrentContext(), stepData,
- getCurrentLoc(), AxisIterator.AXIS_DESCENDANT);
- case AxisIterator.AXIS_SELF_DESCENDANT:
+ getCurrentLoc(), StepInformation.AXIS_DESCENDANT);
+ case StepInformation.AXIS_SELF_DESCENDANT:
return new DescendantOrSelfIterator(getCurrentContext(), stepData,
- getCurrentLoc(), AxisIterator.AXIS_SELF_DESCENDANT);
- case AxisIterator.AXIS_CHILD:
+ getCurrentLoc(), StepInformation.AXIS_SELF_DESCENDANT);
+ case StepInformation.AXIS_CHILD:
return new ChildIterator(getCurrentContext(), stepData,
getCurrentLoc());
default:
@@ -7065,7 +7065,7 @@
}
if (!(iter instanceof SequenceIterator
|| iter instanceof EmptySequenceIterator || iter instanceof FFLWORIterator)) {
- if (iter instanceof AxisIterator) {
+ if (iter instanceof StepInformation) {
iter = new DocOrderIterator(getCurrentContext(), iter,
getCurrentLoc());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2012-02-01 13:11:02
|
Revision: 4511
http://mxquery.svn.sourceforge.net/mxquery/?rev=4511&view=rev
Author: pm_fischer
Date: 2012-02-01 13:10:51 +0000 (Wed, 01 Feb 2012)
Log Message:
-----------
- within XSP, use global Context to store base URI
- root context base URI is only set to system base URI if not already set
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/XSPMain.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-12-22 11:00:23 UTC (rev 4510)
+++ trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2012-02-01 13:10:51 UTC (rev 4511)
@@ -325,7 +325,8 @@
rootContext.storeSet = stores;
else
rootContext.storeSet = new LLStoreSet();
- rootContext.setBaseURI(IOLib.getSystemBaseUri());
+ if (rootContext.getBaseURI() == null)
+ rootContext.setBaseURI(IOLib.getSystemBaseUri());
} else {
this.parent = parent;
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/XSPMain.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/XSPMain.java 2011-12-22 11:00:23 UTC (rev 4510)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/XSPMain.java 2012-02-01 13:10:51 UTC (rev 4511)
@@ -181,7 +181,7 @@
// Initialize context
Context ctx = new Context();
File dir = new File(getServletContext().getRealPath("."));
- ctx.setBaseURI(dir.toURI().toString());
+ Context.getGlobalContext().setBaseURI(dir.toURI().toString());
CompilerOptions co = new CompilerOptions();
co.setSchemaAwareness(true);
co.setXquery11(true);
@@ -360,4 +360,4 @@
queryResult.append("</pre></div>");
queryResult.append("</body></html>");
}
-}
\ No newline at end of file
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-22 11:00:33
|
Revision: 4510
http://mxquery.svn.sourceforge.net/mxquery/?rev=4510&view=rev
Author: pm_fischer
Date: 2011-12-22 11:00:23 +0000 (Thu, 22 Dec 2011)
Log Message:
-----------
- json:parse support on XQIB
- base 64 support
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
Added Paths:
-----------
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/base64/Base64Ops.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml 2011-12-21 06:34:33 UTC (rev 4509)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml 2011-12-22 11:00:23 UTC (rev 4510)
@@ -218,5 +218,21 @@
<className op="json">Parse</className>
</functionDescription>
</functionGroup>
+<functionGroup prefix="base64" namespace="http://www.zorba-xquery.com/modules/base64">
+ <functionDescription>
+ <functionName>encode</functionName>
+ <parameters>
+ <paramType>string</paramType>
+ </parameters>
+ <className op="enc">Base64Ops</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>decode</functionName>
+ <parameters>
+ <paramType>base64Binary</paramType>
+ </parameters>
+ <className op="dec">Base64Ops</className>
+ </functionDescription>
+</functionGroup>
</functionGallery>
\ No newline at end of file
Added: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/base64/Base64Ops.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/base64/Base64Ops.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/base64/Base64Ops.java 2011-12-22 11:00:23 UTC (rev 4510)
@@ -0,0 +1,86 @@
+/* Copyright 2006 - 2009 ETH Zurich
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.ethz.mxquery.extensionsModules.base64;
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.MXQueryBinary;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.datamodel.xdm.BinaryToken;
+import ch.ethz.mxquery.datamodel.xdm.TextToken;
+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.functions.RequestTypeMulti;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Base64;
+
+public class Base64Ops extends TokenBasedIterator implements RequestTypeMulti{
+
+ private boolean dec = false;
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack)
+ throws MXQueryException {
+ Base64Ops ret = new Base64Ops();
+ ret.setSubIters(subIters);
+ ret.setContext(context, false);
+ ret.dec = dec;
+ return ret;
+ }
+
+
+
+ public void init() throws MXQueryException {
+ if (dec) {
+ TokenInterface arg = subIters[0].next();
+ int aType = Type.getEventTypeSubstituted(arg.getEventType(),Context.getDictionary());
+ if ( !(Type.isTypeOrSubTypeOf(aType, Type.BASE64_BINARY,Context.getDictionary()) ||aType == Type.UNTYPED_ATOMIC )) {
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Item of type "+"xs:string"+" expected", loc);
+ }
+ if (subIters[0].next().getEventType() != Type.END_SEQUENCE)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Single Item expected", loc);
+ MXQueryBinary bin = arg.getBinary();
+ currentToken = new TextToken(null, new String(Base64.decode(bin.toString())));
+
+ }
+ else {
+ String add = getStringValue(subIters[0]);
+ currentToken = new BinaryToken(null,new MXQueryBinary(add, Type.BASE64_BINARY),null);
+
+ }
+ }
+ public TypeInfo getStaticType() {
+ return new TypeInfo(Type.START_TAG,Type.OCCURRENCE_IND_ZERO_OR_ONE);
+ }
+
+ public void setOperation(String type) throws MXQueryException {
+ if (type.equals("dec"))
+ dec = true;
+ else if (type.equals("enc"))
+ dec = false;
+
+ else throw new MXQueryException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Incorrect operation for parse/tidy", loc);
+
+ }
+
+ public void setReturnType(int type) throws MXQueryException {
+ }
+
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-12-21 06:34:33 UTC (rev 4509)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-12-22 11:00:23 UTC (rev 4510)
@@ -445,7 +445,8 @@
contentType = overrideMediaType;
if (contentType.startsWith("text")
|| contentType.indexOf("+xml") >= 0
- || contentType.equals("application/xml")) {
+ || contentType.equals("application/xml")
+ || contentType.equals("application/json")) {
String enc = conn.getContentEncoding();
if (enc == null)
enc = "utf-8";
@@ -557,7 +558,7 @@
else if (contentType.indexOf("html") >= 0) {
resIts[resIts.length - 1] = XDMInputFactory.createTidyInput(
context, new StringReader(result.toString()), loc);
- } else if (contentType.startsWith("text/") || contentType.equalsIgnoreCase("application/xml-dtd")) {
+ } else if (contentType.startsWith("text/") || contentType.equalsIgnoreCase("application/xml-dtd") || contentType.equalsIgnoreCase("application/json")) {
resIts[resIts.length - 1] = new TokenIterator(context,
new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(3), result
.toString(), curNsScope), loc, false);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java 2011-12-21 06:34:33 UTC (rev 4509)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java 2011-12-22 11:00:23 UTC (rev 4510)
@@ -69,14 +69,15 @@
if (tokens.size() > 0) // If not standalone
tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "object", TYPE_QN, curNsScope));
JSONArray names = jo.names();
- for (int i=0;i<names.length();i++) {
+ if (names != null)
+ for (int i=0;i<names.length();i++) {
String nm = (String)names.get(i);
tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "pair"), PAIR_QN, curNsScope));
- tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, nm, NAME_QN, curNsScope));
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, nm, NAME_QN, curNsScope));
Object no = jo.get(nm);
handleJSONItem(no);
tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.END_TAG, "pair"), PAIR_QN, curNsScope));
- }
+ }
return;
}
if (obj instanceof JSONArray) {
@@ -105,6 +106,14 @@
tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), it.toString(), curNsScope));
return;
}
+ if (obj instanceof Long) {
+ Long it = (Long)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "number", TYPE_QN, curNsScope));
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), it.toString(), curNsScope));
+ return;
+ }
+
if (obj instanceof Double) {
Double db = (Double)obj;
if (tokens.size() > 0) // If not standalone
@@ -129,8 +138,7 @@
protected XDMIterator copy(Context context, XDMIterator[] subIters,
Vector nestedPredCtxStack) throws MXQueryException {
- // TODO Auto-generated method stub
- return null;
+ return new JSONAdapter(context, getLoc(), this.jsonString, this.jsonML);
}
}
Copied: trunk/MXQuery/xqib_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java (from rev 4509, trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java)
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java 2011-12-22 11:00:23 UTC (rev 4510)
@@ -0,0 +1,134 @@
+package ch.ethz.mxquery.xdmio.xmlAdapters;
+
+import com.google.gwt.json.client.*;
+
+import java.util.Vector;
+
+import com.google.gwt.json.client.JSONParser;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.MXQueryDouble;
+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.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.xdmio.xmlAdapters.JSONAdapter;
+
+public class JSONAdapter extends XDMImportAdapter {
+ public static final String JSON_URI="http://www.zorba-xquery.com/modules/converters/json";
+ private static final QName JSON_QN = new QName(null,null,"json");
+ private static final QName TYPE_QN = new QName(null,null,"type");
+ private static final QName PAIR_QN = new QName(null,null,"pair");
+ private static final QName NAME_QN = new QName(null,null,"name");
+ private static final QName ITEM_QN = new QName(null,null,"item");
+ Vector tokens;
+ String jsonString;
+ boolean jsonML;
+
+ public JSONAdapter(Context ctx, QueryLocation loc, String jsonString, boolean useJSONML) {
+ super(ctx, loc);
+ this.jsonString = jsonString;
+ tokens = new Vector();
+ jsonML = useJSONML;
+ }
+
+ public TokenInterface next() throws MXQueryException {
+ if (called == 0) {
+ init();
+ }
+ if (called < tokens.size()) {
+ called++;
+ return (TokenInterface)tokens.elementAt(called-1);
+ }
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ private void init() throws MXQueryException {
+ try {
+ JSONValue jo = JSONParser.parseStrict(jsonString);
+ tokens.addElement(new Token(Type.START_DOCUMENT, createNextTokenId(Type.START_DOCUMENT,null),curNsScope));
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ //tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "unknown", TYPE_QN, curNsScope));
+ handleJSONItem(jo);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ tokens.addElement(new Token(Type.END_DOCUMENT, createNextTokenId(Type.END_DOCUMENT,null),curNsScope));
+ } catch (JSONException je) {
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"), je.toString(), loc);
+ }
+ }
+
+ void handleJSONItem (JSONValue obj) throws JSONException, MXQueryException {
+ if (obj.isObject() != null) {
+ JSONObject jo = obj.isObject();
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "object", TYPE_QN, curNsScope));
+ java.util.Set<java.lang.String> nameSet = jo.keySet();
+ java.util.Iterator<java.lang.String> names = nameSet.iterator();
+ while (names.hasNext()) {
+ String nm = names.next();
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "pair"), PAIR_QN, curNsScope));
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, nm, NAME_QN, curNsScope));
+ JSONValue no = jo.get(nm);
+ handleJSONItem(no);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.END_TAG, "pair"), PAIR_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj.isArray() != null) {
+ JSONArray ja = obj.isArray();
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "array", TYPE_QN, curNsScope));
+ for (int i=0;i<ja.size();i++) {
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ JSONValue o = ja.get(i);
+ handleJSONItem(o);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj.isString() != null) {
+ JSONString str = obj.isString();
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "string", TYPE_QN, curNsScope));
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), str.stringValue(), curNsScope));
+ return;
+ }
+ if (obj.isNumber() != null) {
+ JSONNumber nm = obj.isNumber();
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "number", TYPE_QN, curNsScope));
+ MXQueryDouble db = new MXQueryDouble(nm.doubleValue());
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), db.toString(), curNsScope));
+ return;
+ }
+
+ if (obj.isBoolean() != null) {
+ JSONBoolean bo = obj.isBoolean();
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "boolean", TYPE_QN, curNsScope));
+ String boolVal = "false";
+ if (bo.booleanValue())
+ boolVal = "true";
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), boolVal, curNsScope));
+ return;
+ }
+ if (obj.isNull() != null) {
+ return;
+ }
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"),"Not implemented Type",loc);
+ }
+
+
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ return new JSONAdapter(context, getLoc(), this.jsonString, this.jsonML);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-21 06:34:40
|
Revision: 4509
http://mxquery.svn.sourceforge.net/mxquery/?rev=4509&view=rev
Author: pm_fischer
Date: 2011-12-21 06:34:33 +0000 (Wed, 21 Dec 2011)
Log Message:
-----------
Removed Paths:
-------------
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmladapters/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-20 23:38:35
|
Revision: 4508
http://mxquery.svn.sourceforge.net/mxquery/?rev=4508&view=rev
Author: pm_fischer
Date: 2011-12-20 23:38:28 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
fixed wrong package
Added Paths:
-----------
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmlAdapters/
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
Added: trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java (rev 0)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java 2011-12-20 23:38:28 UTC (rev 4508)
@@ -0,0 +1,129 @@
+package ch.ethz.mxquery.xdmio.xmlAdapters;
+
+import org.json.me.JSONArray;
+import org.json.me.JSONException;
+import org.json.me.JSONObject;
+
+import java.util.Vector;
+
+import org.json.me.JSONTokener;
+
+import ch.ethz.mxquery.contextConfig.Context;
+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.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class JSONAdapter extends XDMImportAdapter {
+ public static final String JSON_URI="http://www.zorba-xquery.com/modules/converters/json";
+ private static final QName JSON_QN = new QName(null,null,"json");
+ private static final QName TYPE_QN = new QName(null,null,"type");
+ private static final QName PAIR_QN = new QName(null,null,"pair");
+ private static final QName NAME_QN = new QName(null,null,"name");
+ private static final QName ITEM_QN = new QName(null,null,"item");
+ Vector tokens;
+ String jsonString;
+ boolean jsonML;
+
+ public JSONAdapter(Context ctx, QueryLocation loc, String jsonString, boolean useJSONML) {
+ super(ctx, loc);
+ this.jsonString = jsonString;
+ tokens = new Vector();
+ jsonML = useJSONML;
+ }
+
+ public TokenInterface next() throws MXQueryException {
+ if (called == 0) {
+ init();
+ }
+ if (called < tokens.size()) {
+ called++;
+ return (TokenInterface)tokens.elementAt(called-1);
+ }
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ private void init() throws MXQueryException {
+ try {
+ Object jo = new JSONTokener(jsonString).nextValue();
+ tokens.addElement(new Token(Type.START_DOCUMENT, createNextTokenId(Type.START_DOCUMENT,null),curNsScope));
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ //tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "unknown", TYPE_QN, curNsScope));
+ handleJSONItem(jo);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ tokens.addElement(new Token(Type.END_DOCUMENT, createNextTokenId(Type.END_DOCUMENT,null),curNsScope));
+ } catch (JSONException je) {
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"), je.toString(), loc);
+ }
+ }
+
+ void handleJSONItem (Object obj) throws JSONException, MXQueryException {
+ if (obj instanceof JSONObject) {
+ JSONObject jo = ((JSONObject)obj);
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "object", TYPE_QN, curNsScope));
+ JSONArray names = jo.names();
+ for (int i=0;i<names.length();i++) {
+ String nm = (String)names.get(i);
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "pair"), PAIR_QN, curNsScope));
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, nm, NAME_QN, curNsScope));
+ Object no = jo.get(nm);
+ handleJSONItem(no);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.END_TAG, "pair"), PAIR_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj instanceof JSONArray) {
+ JSONArray ja = (JSONArray)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "array", TYPE_QN, curNsScope));
+ for (int i=0;i<ja.length();i++) {
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ Object o = ja.get(i);
+ handleJSONItem(o);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj instanceof String) {
+ String str = (String)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "string", TYPE_QN, curNsScope));
+ tokens.addElement(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), str, curNsScope));
+ return;
+ }
+ if (obj instanceof Integer) {
+ Integer it = (Integer)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "number", TYPE_QN, curNsScope));
+ tokens.addElement(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), it.toString(), curNsScope));
+ return;
+ }
+ if (obj instanceof Boolean) {
+ Boolean bo = (Boolean)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "boolean", TYPE_QN, curNsScope));
+ tokens.addElement(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), bo.toString(), curNsScope));
+ return;
+ }
+ if (obj == JSONObject.NULL) {
+ return;
+ }
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"),"Not implemented Type",loc);
+ }
+
+
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-20 23:14:21
|
Revision: 4507
http://mxquery.svn.sourceforge.net/mxquery/?rev=4507&view=rev
Author: pm_fischer
Date: 2011-12-20 23:14:13 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
JSON support on J2ME
Modified Paths:
--------------
trunk/MXQuery/build.xml
Added Paths:
-----------
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmladapters/
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmladapters/JSONAdapter.java
trunk/MXQuery/midp_src/org/json/
trunk/MXQuery/midp_src/org/json/me/
trunk/MXQuery/midp_src/org/json/me/JSONArray.java
trunk/MXQuery/midp_src/org/json/me/JSONException.java
trunk/MXQuery/midp_src/org/json/me/JSONObject.java
trunk/MXQuery/midp_src/org/json/me/JSONString.java
trunk/MXQuery/midp_src/org/json/me/JSONStringer.java
trunk/MXQuery/midp_src/org/json/me/JSONTokener.java
trunk/MXQuery/midp_src/org/json/me/JSONWriter.java
trunk/MXQuery/midp_src/org/json/me/StringWriter.java
trunk/MXQuery/midp_src/org/json/me/util/
trunk/MXQuery/midp_src/org/json/me/util/XML.java
trunk/MXQuery/midp_src/org/json/me/util/XMLTokener.java
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-12-20 22:00:54 UTC (rev 4506)
+++ trunk/MXQuery/build.xml 2011-12-20 23:14:13 UTC (rev 4507)
@@ -371,9 +371,9 @@
</fileset>
</delete>
<copy todir="${midptmp.dir}"><fileset dir="${src.dir}"/></copy>
+ <delete dir="${midptmp.dir}/org/json/"/>
<copy todir="${midptmp.dir}" overwrite="yes"><fileset dir="${midpsrc.dir}"/></copy>
<echo message="Removing unsupported classes"/>
-
<delete dir="${midptmp.dir}/ch/ethz/mxquery/parallel/"/>
<delete dir="${midptmp.dir}/javax/"/>
<delete dir="${midptmp.dir}/org/tartarus"/>
Added: trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmladapters/JSONAdapter.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmladapters/JSONAdapter.java (rev 0)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/xmladapters/JSONAdapter.java 2011-12-20 23:14:13 UTC (rev 4507)
@@ -0,0 +1,129 @@
+package ch.ethz.mxquery.xdmio.xmlAdapters;
+
+import org.json.me.JSONArray;
+import org.json.me.JSONException;
+import org.json.me.JSONObject;
+
+import java.util.Vector;
+
+import org.json.me.JSONTokener;
+
+import ch.ethz.mxquery.contextConfig.Context;
+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.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class JSONAdapter extends XDMImportAdapter {
+ public static final String JSON_URI="http://www.zorba-xquery.com/modules/converters/json";
+ private static final QName JSON_QN = new QName(null,null,"json");
+ private static final QName TYPE_QN = new QName(null,null,"type");
+ private static final QName PAIR_QN = new QName(null,null,"pair");
+ private static final QName NAME_QN = new QName(null,null,"name");
+ private static final QName ITEM_QN = new QName(null,null,"item");
+ Vector tokens;
+ String jsonString;
+ boolean jsonML;
+
+ public JSONAdapter(Context ctx, QueryLocation loc, String jsonString, boolean useJSONML) {
+ super(ctx, loc);
+ this.jsonString = jsonString;
+ tokens = new Vector();
+ jsonML = useJSONML;
+ }
+
+ public TokenInterface next() throws MXQueryException {
+ if (called == 0) {
+ init();
+ }
+ if (called < tokens.size()) {
+ called++;
+ return (TokenInterface)tokens.elementAt(called-1);
+ }
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ private void init() throws MXQueryException {
+ try {
+ Object jo = new JSONTokener(jsonString).nextValue();
+ tokens.addElement(new Token(Type.START_DOCUMENT, createNextTokenId(Type.START_DOCUMENT,null),curNsScope));
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ //tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "unknown", TYPE_QN, curNsScope));
+ handleJSONItem(jo);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ tokens.addElement(new Token(Type.END_DOCUMENT, createNextTokenId(Type.END_DOCUMENT,null),curNsScope));
+ } catch (JSONException je) {
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"), je.toString(), loc);
+ }
+ }
+
+ void handleJSONItem (Object obj) throws JSONException, MXQueryException {
+ if (obj instanceof JSONObject) {
+ JSONObject jo = ((JSONObject)obj);
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "object", TYPE_QN, curNsScope));
+ JSONArray names = jo.names();
+ for (int i=0;i<names.length();i++) {
+ String nm = (String)names.get(i);
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "pair"), PAIR_QN, curNsScope));
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, nm, NAME_QN, curNsScope));
+ Object no = jo.get(nm);
+ handleJSONItem(no);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.END_TAG, "pair"), PAIR_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj instanceof JSONArray) {
+ JSONArray ja = (JSONArray)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "array", TYPE_QN, curNsScope));
+ for (int i=0;i<ja.length();i++) {
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ Object o = ja.get(i);
+ handleJSONItem(o);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj instanceof String) {
+ String str = (String)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "string", TYPE_QN, curNsScope));
+ tokens.addElement(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), str, curNsScope));
+ return;
+ }
+ if (obj instanceof Integer) {
+ Integer it = (Integer)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "number", TYPE_QN, curNsScope));
+ tokens.addElement(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), it.toString(), curNsScope));
+ return;
+ }
+ if (obj instanceof Boolean) {
+ Boolean bo = (Boolean)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "boolean", TYPE_QN, curNsScope));
+ tokens.addElement(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), bo.toString(), curNsScope));
+ return;
+ }
+ if (obj == JSONObject.NULL) {
+ return;
+ }
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"),"Not implemented Type",loc);
+ }
+
+
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: trunk/MXQuery/midp_src/org/json/me/JSONArray.java
===================================================================
--- trunk/MXQuery/midp_src/org/json/me/JSONArray.java (rev 0)
+++ trunk/MXQuery/midp_src/org/json/me/JSONArray.java 2011-12-20 23:14:13 UTC (rev 4507)
@@ -0,0 +1,892 @@
+package org.json.me;
+
+/*
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * A JSONArray is an ordered sequence of values. Its external text form is a
+ * string wrapped in square brackets with commas separating the values. The
+ * internal form is an object having <code>get</code> and <code>opt</code>
+ * methods for accessing the values by index, and <code>put</code> methods for
+ * adding or replacing values. The values can be any of these types:
+ * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
+ * <code>Number</code>, <code>String</code>, or the
+ * <code>JSONObject.NULL object</code>.
+ * <p>
+ * The constructor can convert a JSON text into a Java object. The
+ * <code>toString</code> method converts to JSON text.
+ * <p>
+ * A <code>get</code> method returns a value if one can be found, and throws an
+ * exception if one cannot be found. An <code>opt</code> method returns a
+ * default value instead of throwing an exception, and so is useful for
+ * obtaining optional values.
+ * <p>
+ * The generic <code>get()</code> and <code>opt()</code> methods return an
+ * object which you can cast or query for type. There are also typed
+ * <code>get</code> and <code>opt</code> methods that do type checking and type
+ * coersion for you.
+ * <p>
+ * The texts produced by the <code>toString</code> methods strictly conform to
+ * JSON syntax rules. The constructors are more forgiving in the texts they will
+ * accept:
+ * <ul>
+ * <li>An extra <code>,</code> <small>(comma)</small> may appear just
+ * before the closing bracket.</li>
+ * <li>The <code>null</code> value will be inserted when there
+ * is <code>,</code> <small>(comma)</small> elision.</li>
+ * <li>Strings may be quoted with <code>'</code> <small>(single
+ * quote)</small>.</li>
+ * <li>Strings do not need to be quoted at all if they do not begin with a quote
+ * or single quote, and if they do not contain leading or trailing spaces,
+ * and if they do not contain any of these characters:
+ * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers
+ * and if they are not the reserved words <code>true</code>,
+ * <code>false</code>, or <code>null</code>.</li>
+ * <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as
+ * well as by <code>,</code> <small>(comma)</small>.</li>
+ * <li>Numbers may have the <code>0-</code> <small>(octal)</small> or
+ * <code>0x-</code> <small>(hex)</small> prefix.</li>
+ * <li>Comments written in the slashshlash, slashstar, and hash conventions
+ * will be ignored.</li>
+ * </ul>
+
+ * @author JSON.org
+ * @version 2
+ */
+public class JSONArray {
+
+
+ /**
+ * The Vector where the JSONArray's properties are kept.
+ */
+ private Vector myArrayList;
+
+
+ /**
+ * Construct an empty JSONArray.
+ */
+ public JSONArray() {
+ this.myArrayList = new Vector();
+ }
+
+ /**
+ * Construct a JSONArray from a JSONTokener.
+ * @param x A JSONTokener
+ * @throws JSONException If there is a syntax error.
+ */
+ public JSONArray(JSONTokener x) throws JSONException {
+ this();
+ if (x.nextClean() != '[') {
+ throw x.syntaxError("A JSONArray text must start with '['");
+ }
+ if (x.nextClean() == ']') {
+ return;
+ }
+ x.back();
+ for (;;) {
+ if (x.nextClean() == ',') {
+ x.back();
+ this.myArrayList.addElement(null);
+ } else {
+ x.back();
+ this.myArrayList.addElement(x.nextValue());
+ }
+ switch (x.nextClean()) {
+ case ';':
+ case ',':
+ if (x.nextClean() == ']') {
+ return;
+ }
+ x.back();
+ break;
+ case ']':
+ return;
+ default:
+ throw x.syntaxError("Expected a ',' or ']'");
+ }
+ }
+ }
+
+
+ /**
+ * Construct a JSONArray from a source sJSON text.
+ * @param string A string that begins with
+ * <code>[</code> <small>(left bracket)</small>
+ * and ends with <code>]</code> <small>(right bracket)</small>.
+ * @throws JSONException If there is a syntax error.
+ */
+ public JSONArray(String string) throws JSONException {
+ this(new JSONTokener(string));
+ }
+
+
+ /**
+ * Construct a JSONArray from a Collection.
+ * @param collection A Collection.
+ */
+ public JSONArray(Vector collection) {
+ if (collection == null) {
+ this.myArrayList = new Vector();
+ } else {
+ int size = collection.size();
+ this.myArrayList = new Vector(size);
+ for (int i=0; i < size; i++) {
+ this.myArrayList.addElement(collection.elementAt(i));
+ }
+ }
+ }
+
+ /**
+ * Get the object value associated with an index.
+ * @param index
+ * The index must be between 0 and length() - 1.
+ * @return An object value.
+ * @throws JSONException If there is no value for the index.
+ */
+ public Object get(int index) throws JSONException {
+ Object o = opt(index);
+ if (o == null) {
+ throw new JSONException("JSONArray[" + index + "] not found.");
+ }
+ return o;
+ }
+
+ /**
+ * Get the boolean value associated with an index.
+ * The string values "true" and "false" are converted to boolean.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The truth.
+ * @throws JSONException If there is no value for the index or if the
+ * value is not convertable to boolean.
+ */
+ public boolean getBoolean(int index) throws JSONException {
+ Object o = get(index);
+//#if CLDC!="1.0"
+//# if (o.equals(Boolean.FALSE) ||
+//#else
+ if (o.equals(JSONObject.FALSE) ||
+//#endif
+ (o instanceof String &&
+ ((String)o).toLowerCase().equals("false"))) {
+ return false;
+//#if CLDC!="1.0"
+//# } else if (o.equals(Boolean.TRUE) ||
+//#else
+ } else if (o.equals(JSONObject.TRUE) ||
+//#endif
+ (o instanceof String &&
+ ((String)o).toLowerCase().equals("true"))) {
+ return true;
+ }
+ throw new JSONException("JSONArray[" + index + "] is not a Boolean.");
+ }
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the double value associated with an index.
+//# *
+//# * @param index The index must be between 0 and length() - 1.
+//# * @return The value.
+//# * @throws JSONException If the key is not found or if the value cannot
+//# * be converted to a number.
+//# */
+//# public double getDouble(int index) throws JSONException {
+//# Object o = get(index);
+//# try {
+//# return Double.valueOf((String)o).doubleValue();
+//# } catch (Exception e) {
+//# throw new JSONException("JSONArray[" + index +
+//# "] is not a number.");
+//# }
+//# }
+//#endif
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the int value associated with an index.
+//# *
+//# * @param index The index must be between 0 and length() - 1.
+//# * @return The value.
+//# * @throws JSONException If the key is not found or if the value cannot
+//# * be converted to a number.
+//# * if the value cannot be converted to a number.
+//# */
+//# public int getInt(int index) throws JSONException {
+//# Object o = get(index);
+//# return (int)getDouble(index);
+//# }
+//#endif
+
+ /**
+ * Get the JSONArray associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return A JSONArray value.
+ * @throws JSONException If there is no value for the index. or if the
+ * value is not a JSONArray
+ */
+ public JSONArray getJSONArray(int index) throws JSONException {
+ Object o = get(index);
+ if (o instanceof JSONArray) {
+ return (JSONArray)o;
+ }
+ throw new JSONException("JSONArray[" + index +
+ "] is not a JSONArray.");
+ }
+
+
+ /**
+ * Get the JSONObject associated with an index.
+ * @param index subscript
+ * @return A JSONObject value.
+ * @throws JSONException If there is no value for the index or if the
+ * value is not a JSONObject
+ */
+ public JSONObject getJSONObject(int index) throws JSONException {
+ Object o = get(index);
+ if (o instanceof JSONObject) {
+ return (JSONObject)o;
+ }
+ throw new JSONException("JSONArray[" + index +
+ "] is not a JSONObject.");
+ }
+
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the long value associated with an index.
+//# *
+//# * @param index The index must be between 0 and length() - 1.
+//# * @return The value.
+//# * @throws JSONException If the key is not found or if the value cannot
+//# * be converted to a number.
+//# */
+//# public long getLong(int index) throws JSONException {
+//# Object o = get(index);
+//# return (long)getDouble(index);
+//# }
+//#endif
+
+ /**
+ * Get the string associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return A string value.
+ * @throws JSONException If there is no value for the index.
+ */
+ public String getString(int index) throws JSONException {
+ return get(index).toString();
+ }
+
+
+ /**
+ * Determine if the value is null.
+ * @param index The index must be between 0 and length() - 1.
+ * @return true if the value at the index is null, or if there is no value.
+ */
+ public boolean isNull(int index) {
+ return JSONObject.NULL.equals(opt(index));
+ }
+
+
+ /**
+ * Make a string from the contents of this JSONArray. The
+ * <code>separator</code> string is inserted between each element.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param separator A string that will be inserted between the elements.
+ * @return a string.
+ * @throws JSONException If the array contains an invalid number.
+ */
+ public String join(String separator) throws JSONException {
+ int len = length();
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < len; i += 1) {
+ if (i > 0) {
+ sb.append(separator);
+ }
+ sb.append(JSONObject.valueToString(this.myArrayList.elementAt(i)));
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * Get the number of elements in the JSONArray, included nulls.
+ *
+ * @return The length (or size).
+ */
+ public int length() {
+ return this.myArrayList.size();
+ }
+
+
+ /**
+ * Get the optional object value associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return An object value, or null if there is no
+ * object at that index.
+ */
+ public Object opt(int index) {
+ return (index < 0 || index >= length()) ?
+ null : this.myArrayList.elementAt(index);
+ }
+
+ /**
+ * Get the optional boolean value associated with an index.
+ * It returns false if there is no value at that index,
+ * or if the value is not Boolean.TRUE or the String "true".
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The truth.
+ */
+ public boolean optBoolean(int index) {
+ return optBoolean(index, false);
+ }
+
+ /**
+ * Get the optional boolean value associated with an index.
+ * It returns the defaultValue if there is no value at that index or if
+ * it is not a Boolean or the String "true" or "false" (case insensitive).
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue A boolean default.
+ * @return The truth.
+ */
+ public boolean optBoolean(int index, boolean defaultValue) {
+ try {
+ return getBoolean(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the optional double value associated with an index.
+//# * NaN is returned if there is no value for the index,
+//# * or if the value is not a number and cannot be converted to a number.
+//# *
+//# * @param index The index must be between 0 and length() - 1.
+//# * @return The value.
+//# */
+//# public double optDouble(int index) {
+//# return optDouble(index, Double.NaN);
+//# }
+//#endif
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the optional double value associated with an index.
+//# * The defaultValue is returned if there is no value for the index,
+//# * or if the value is not a number and cannot be converted to a number.
+//# *
+//# * @param index subscript
+//# * @param defaultValue The default value.
+//# * @return The value.
+//# */
+//# public double optDouble(int index, double defaultValue) {
+//# try {
+//# return getDouble(index);
+//# } catch (Exception e) {
+//# return defaultValue;
+//# }
+//# }
+//#endif
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the optional int value associated with an index.
+//# * Zero is returned if there is no value for the index,
+//# * or if the value is not a number and cannot be converted to a number.
+//# *
+//# * @param index The index must be between 0 and length() - 1.
+//# * @return The value.
+//# */
+//# public int optInt(int index) {
+//# return optInt(index, 0);
+//# }
+//#endif
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the optional int value associated with an index.
+//# * The defaultValue is returned if there is no value for the index,
+//# * or if the value is not a number and cannot be converted to a number.
+//# * @param index The index must be between 0 and length() - 1.
+//# * @param defaultValue The default value.
+//# * @return The value.
+//# */
+//# public int optInt(int index, int defaultValue) {
+//# try {
+//# return getInt(index);
+//# } catch (Exception e) {
+//# return defaultValue;
+//# }
+//# }
+//#endif
+
+ /**
+ * Get the optional JSONArray associated with an index.
+ * @param index subscript
+ * @return A JSONArray value, or null if the index has no value,
+ * or if the value is not a JSONArray.
+ */
+ public JSONArray optJSONArray(int index) {
+ Object o = opt(index);
+ return o instanceof JSONArray ? (JSONArray)o : null;
+ }
+
+
+ /**
+ * Get the optional JSONObject associated with an index.
+ * Null is returned if the key is not found, or null if the index has
+ * no value, or if the value is not a JSONObject.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return A JSONObject value.
+ */
+ public JSONObject optJSONObject(int index) {
+ Object o = opt(index);
+ return o instanceof JSONObject ? (JSONObject)o : null;
+ }
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the optional long value associated with an index.
+//# * Zero is returned if there is no value for the index,
+//# * or if the value is not a number and cannot be converted to a number.
+//# *
+//# * @param index The index must be between 0 and length() - 1.
+//# * @return The value.
+//# */
+//# public long optLong(int index) {
+//# return optLong(index, 0);
+//# }
+//#endif
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the optional long value associated with an index.
+//# * The defaultValue is returned if there is no value for the index,
+//# * or if the value is not a number and cannot be converted to a number.
+//# * @param index The index must be between 0 and length() - 1.
+//# * @param defaultValue The default value.
+//# * @return The value.
+//# */
+//# public long optLong(int index, long defaultValue) {
+//# try {
+//# return getLong(index);
+//# } catch (Exception e) {
+//# return defaultValue;
+//# }
+//# }
+//#endif
+
+ /**
+ * Get the optional string value associated with an index. It returns an
+ * empty string if there is no value at that index. If the value
+ * is not a string and is not null, then it is coverted to a string.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return A String value.
+ */
+ public String optString(int index) {
+ return optString(index, "");
+ }
+
+
+ /**
+ * Get the optional string associated with an index.
+ * The defaultValue is returned if the key is not found.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return A String value.
+ */
+ public String optString(int index, String defaultValue) {
+ Object o = opt(index);
+ return o != null ? o.toString() : defaultValue;
+ }
+
+
+ /**
+ * Append a boolean value. This increases the array's length by one.
+ *
+ * @param value A boolean value.
+ * @return this.
+ */
+ public JSONArray put(boolean value) {
+//#if CLDC!="1.0"
+//# put(value ? Boolean.TRUE : Boolean.FALSE);
+//#else
+ put(value ? JSONObject.TRUE : JSONObject.FALSE);
+//#endif
+ return this;
+ }
+
+ /**
+ * Put a value in the JSONArray, where the value will be a
+ * JSONArray which is produced from a Collection.
+ * @param value A Collection value.
+ * @return this.
+ */
+ public JSONArray put(Vector value) {
+ put(new JSONArray(value));
+ return this;
+ }
+
+
+//#if CLDC!="1.0"
+//# /**
+//# * Append a double value. This increases the array's length by one.
+//# *
+//# * @param value A double value.
+//# * @throws JSONException if the value is not finite.
+//# * @return this.
+//# */
+//# public JSONArray put(double value) throws JSONException {
+//# Double d = new Double(value);
+//# JSONObject.testValidity(d);
+//# put(d);
+//# return this;
+//# }
+//#endif
+
+ /**
+ * Append an int value. This increases the array's length by one.
+ *
+ * @param value An int value.
+ * @return this.
+ */
+ public JSONArray put(int value) {
+ put(new Integer(value));
+ return this;
+ }
+
+
+ /**
+ * Append an long value. This increases the array's length by one.
+ *
+ * @param value A long value.
+ * @return this.
+ */
+ public JSONArray put(long value) {
+ put(new Long(value));
+ return this;
+ }
+
+
+//#ifdef PRODUCER
+//# /**
+//# * Put a value in the JSONArray, where the value will be a
+//# * JSONObject which is produced from a Map.
+//# * @param value A Map value.
+//# * @return this.
+//# */
+//# public JSONArray put(Hashtable value) {
+//# put(new JSONObject(value));
+//# return this;
+//# }
+//#endif
+
+ /**
+ * Append an object value. This increases the array's length by one.
+ * @param value An object value. The value should be a
+ * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
+ * JSONObject.NULL object.
+ * @return this.
+ */
+ public JSONArray put(Object value) {
+ this.myArrayList.addElement(value);
+ return this;
+ }
+
+
+ /**
+ * Put or replace a boolean value in the JSONArray. If the index is greater
+ * than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value A boolean value.
+ * @return this.
+ * @throws JSONException If the index is negative.
+ */
+ public JSONArray put(int index, boolean value) throws JSONException {
+//#if CLDC!="1.0"
+//# put(index, value ? Boolean.TRUE : Boolean.FALSE);
+//#else
+ put(index, value ? JSONObject.TRUE : JSONObject.FALSE);
+//#endif
+ return this;
+ }
+
+ /**
+ * Put a value in the JSONArray, where the value will be a
+ * JSONArray which is produced from a Collection.
+ * @param index The subscript.
+ * @param value A Collection value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the value is
+ * not finite.
+ */
+ public JSONArray put(int index, Vector value) throws JSONException {
+ put(index, new JSONArray(value));
+ return this;
+ }
+
+
+//#if CLDC!="1.0"
+//# /**
+//# * Put or replace a double value. If the index is greater than the length of
+//# * the JSONArray, then null elements will be added as necessary to pad
+//# * it out.
+//# * @param index The subscript.
+//# * @param value A double value.
+//# * @return this.
+//# * @throws JSONException If the index is negative or if the value is
+//# * not finite.
+//# */
+//# public JSONArray put(int index, double value) throws JSONException {
+//# put(index, new Double(value));
+//# return this;
+//# }
+//#endif
+
+ /**
+ * Put or replace an int value. If the index is greater than the length of
+ * the JSONArray, then null elements will be added as necessary to pad
+ * it out.
+ * @param index The subscript.
+ * @param value An int value.
+ * @return this.
+ * @throws JSONException If the index is negative.
+ */
+ public JSONArray put(int index, int value) throws JSONException {
+ put(index, new Integer(value));
+ return this;
+ }
+
+
+ /**
+ * Put or replace a long value. If the index is greater than the length of
+ * the JSONArray, then null elements will be added as necessary to pad
+ * it out.
+ * @param index The subscript.
+ * @param value A long value.
+ * @return this.
+ * @throws JSONException If the index is negative.
+ */
+ public JSONArray put(int index, long value) throws JSONException {
+ put(index, new Long(value));
+ return this;
+ }
+
+
+//#ifdef PRODUCER
+//# /**
+//# * Put a value in the JSONArray, where the value will be a
+//# * JSONObject which is produced from a Map.
+//# * @param index The subscript.
+//# * @param value The Map value.
+//# * @return this.
+//# * @throws JSONException If the index is negative or if the the value is
+//# * an invalid number.
+//# */
+//# public JSONArray put(int index, Hashtable value) throws JSONException {
+//# put(index, new JSONObject(value));
+//# return this;
+//# }
+//#endif
+
+ /**
+ * Put or replace an object value in the JSONArray. If the index is greater
+ * than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value The value to put into the array. The value should be a
+ * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
+ * JSONObject.NULL object.
+ * @return this.
+ * @throws JSONException If the index is negative or if the the value is
+ * an invalid number.
+ */
+ public JSONArray put(int index, Object value) throws JSONException {
+ JSONObject.testValidity(value);
+ if (index < 0) {
+ throw new JSONException("JSONArray[" + index + "] not found.");
+ }
+ if (index < length()) {
+ this.myArrayList.setElementAt(value, index);
+ } else {
+ while (index != length()) {
+ put(JSONObject.NULL);
+ }
+ put(value);
+ }
+ return this;
+ }
+
+
+ /**
+ * Produce a JSONObject by combining a JSONArray of names with the values
+ * of this JSONArray.
+ * @param names A JSONArray containing a list of key strings. These will be
+ * paired with the values.
+ * @return A JSONObject, or null if there are no names or if this JSONArray
+ * has no values.
+ * @throws JSONException If any of the names are null.
+ */
+ public JSONObject toJSONObject(JSONArray names) throws JSONException {
+ if (names == null || names.length() == 0 || length() == 0) {
+ return null;
+ }
+ JSONObject jo = new JSONObject();
+ for (int i = 0; i < names.length(); i += 1) {
+ jo.put(names.getString(i), this.opt(i));
+ }
+ return jo;
+ }
+
+
+ /**
+ * Make a JSON text of this JSONArray. For compactness, no
+ * unnecessary whitespace is added. If it is not possible to produce a
+ * syntactically correct JSON text then null will be returned instead. This
+ * could occur if the array contains an invalid number.
+ * <p>
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return a printable, displayable, transmittable
+ * representation of the array.
+ */
+ public String toString() {
+ try {
+ return '[' + join(",") + ']';
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+
+ /**
+ * Make a prettyprinted JSON text of this JSONArray.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of
+ * indentation.
+ * @return a printable, displayable, transmittable
+ * representation of the object, beginning
+ * with <code>[</code> <small>(left bracket)</small> and ending
+ * with <code>]</code> <small>(right bracket)</small>.
+ * @throws JSONException
+ */
+ public String toString(int indentFactor) throws JSONException {
+ return toString(indentFactor, 0);
+ }
+
+
+ /**
+ * Make a prettyprinted JSON text of this JSONArray.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of
+ * indentation.
+ * @param indent The indention of the top level.
+ * @return a printable, displayable, transmittable
+ * representation of the array.
+ * @throws JSONException
+ */
+ String toString(int indentFactor, int indent) throws JSONException {
+ int len = length();
+ if (len == 0) {
+ return "[]";
+ }
+ int i;
+ StringBuffer sb = new StringBuffer("[");
+ if (len == 1) {
+ sb.append(JSONObject.valueToString(this.myArrayList.elementAt(0),
+ indentFactor, indent));
+ } else {
+ int newindent = indent + indentFactor;
+ sb.append('\n');
+ for (i = 0; i < len; i += 1) {
+ if (i > 0) {
+ sb.append(",\n");
+ }
+ for (int j = 0; j < newindent; j += 1) {
+ sb.append(' ');
+ }
+ sb.append(JSONObject.valueToString(this.myArrayList.elementAt(i),
+ indentFactor, newindent));
+ }
+ sb.append('\n');
+ for (i = 0; i < indent; i += 1) {
+ sb.append(' ');
+ }
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+
+
+ /**
+ * Write the contents of the JSONArray as JSON text to a writer.
+ * For compactness, no whitespace is added.
+ * <p>
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return The writer.
+ * @throws JSONException
+ */
+ public Writer write(Writer writer) throws JSONException {
+ try {
+ boolean b = false;
+ int len = length();
+
+ writer.write('[');
+
+ for (int i = 0; i < len; i += 1) {
+ if (b) {
+ writer.write(',');
+ }
+ Object v = this.myArrayList.elementAt(i);
+ if (v instanceof JSONObject) {
+ ((JSONObject)v).write(writer);
+ } else if (v instanceof JSONArray) {
+ ((JSONArray)v).write(writer);
+ } else {
+ writer.write(JSONObject.valueToString(v));
+ }
+ b = true;
+ }
+ writer.write(']');
+ return writer;
+ } catch (IOException e) {
+ throw new JSONException(e);
+ }
+ }
+}
\ No newline at end of file
Added: trunk/MXQuery/midp_src/org/json/me/JSONException.java
===================================================================
--- trunk/MXQuery/midp_src/org/json/me/JSONException.java (rev 0)
+++ trunk/MXQuery/midp_src/org/json/me/JSONException.java 2011-12-20 23:14:13 UTC (rev 4507)
@@ -0,0 +1,27 @@
+package org.json.me;
+
+/**
+ * The JSONException is thrown by the JSON.org classes then things are amiss.
+ * @author JSON.org
+ * @version 2
+ */
+public class JSONException extends Exception {
+ private Throwable cause;
+
+ /**
+ * Constructs a JSONException with an explanatory message.
+ * @param message Detail about the reason for the exception.
+ */
+ public JSONException(String message) {
+ super(message);
+ }
+
+ public JSONException(Throwable t) {
+ super(t.getMessage());
+ this.cause = t;
+ }
+
+ public Throwable getCause() {
+ return this.cause;
+ }
+}
Added: trunk/MXQuery/midp_src/org/json/me/JSONObject.java
===================================================================
--- trunk/MXQuery/midp_src/org/json/me/JSONObject.java (rev 0)
+++ trunk/MXQuery/midp_src/org/json/me/JSONObject.java 2011-12-20 23:14:13 UTC (rev 4507)
@@ -0,0 +1,1317 @@
+package org.json.me;
+
+/*
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * A JSONObject is an unordered collection of name/value pairs. Its
+ * external form is a string wrapped in curly braces with colons between the
+ * names and values, and commas between the values and names. The internal form
+ * is an object having <code>get</code> and <code>opt</code> methods for
+ * accessing the values by name, and <code>put</code> methods for adding or
+ * replacing values by name. The values can be any of these types:
+ * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
+ * <code>Number</code>, <code>String</code>, or the <code>JSONObject.NULL</code>
+ * object. A JSONObject constructor can be used to convert an external form
+ * JSON text into an internal form whose values can be retrieved with the
+ * <code>get</code> and <code>opt</code> methods, or to convert values into a
+ * JSON text using the <code>put</code> and <code>toString</code> methods.
+ * A <code>get</code> method returns a value if one can be found, and throws an
+ * exception if one cannot be found. An <code>opt</code> method returns a
+ * default value instead of throwing an exception, and so is useful for
+ * obtaining optional values.
+ * <p>
+ * The generic <code>get()</code> and <code>opt()</code> methods return an
+ * object, which you can cast or query for type. There are also typed
+ * <code>get</code> and <code>opt</code> methods that do type checking and type
+ * coersion for you.
+ * <p>
+ * The <code>put</code> methods adds values to an object. For example, <pre>
+ * myString = new JSONObject().put("JSON", "Hello, World!").toString();</pre>
+ * produces the string <code>{"JSON": "Hello, World"}</code>.
+ * <p>
+ * The texts produced by the <code>toString</code> methods strictly conform to
+ * the JSON sysntax rules.
+ * The constructors are more forgiving in the texts they will accept:
+ * <ul>
+ * <li>An extra <code>,</code> <small>(comma)</small> may appear just
+ * before the closing brace.</li>
+ * <li>Strings may be quoted with <code>'</code> <small>(single
+ * quote)</small>.</li>
+ * <li>Strings do not need to be quoted at all if they do not begin with a quote
+ * or single quote, and if they do not contain leading or trailing spaces,
+ * and if they do not contain any of these characters:
+ * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers
+ * and if they are not the reserved words <code>true</code>,
+ * <code>false</code>, or <code>null</code>.</li>
+ * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as
+ * by <code>:</code>.</li>
+ * <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as
+ * well as by <code>,</code> <small>(comma)</small>.</li>
+ * <li>Numbers may have the <code>0-</code> <small>(octal)</small> or
+ * <code>0x-</code> <small>(hex)</small> prefix.</li>
+ * <li>Comments written in the slashshlash, slashstar, and hash conventions
+ * will be ignored.</li>
+ * </ul>
+ * @author JSON.org
+ * @version 2
+ */
+public class JSONObject {
+
+//#if CLDC=="1.0"
+ public static final Boolean TRUE = new Boolean(true);
+ public static final Boolean FALSE = new Boolean(false);
+//#endif
+
+ /**
+ * JSONObject.NULL is equivalent to the value that JavaScript calls null,
+ * whilst Java's null is equivalent to the value that JavaScript calls
+ * undefined.
+ */
+ private static final class Null {
+
+ /**
+ * There is only intended to be a single instance of the NULL object,
+ * so the clone method returns itself.
+ * @return NULL.
+ */
+ protected final Object clone() {
+ return this;
+ }
+
+
+ /**
+ * A Null object is equal to the null value and to itself.
+ * @param object An object to test for nullness.
+ * @return true if the object parameter is the JSONObject.NULL object
+ * or null.
+ */
+ public boolean equals(Object object) {
+ return object == null || object == this;
+ }
+
+
+ /**
+ * Get the "null" string value.
+ * @return The string "null".
+ */
+ public String toString() {
+ return "null";
+ }
+ }
+
+
+ /**
+ * The hash map where the JSONObject's properties are kept.
+ */
+ private Hashtable myHashMap;
+
+
+ /**
+ * It is sometimes more convenient and less ambiguous to have a
+ * <code>NULL</code> object than to use Java's <code>null</code> value.
+ * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>.
+ * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.
+ */
+ public static final Object NULL = new Null();
+
+ /**
+ * Construct an empty JSONObject.
+ */
+ public JSONObject() {
+ this.myHashMap = new Hashtable();
+ }
+
+
+//#ifdef PRODUCER
+//# /**
+//# * Construct a JSONObject from a subset of another JSONObject.
+//# * An array of strings is used to identify the keys that should be copied.
+//# * Missing keys are ignored.
+//# * @param jo A JSONObject.
+//# * @param sa An array of strings.
+//# * @exception JSONException If a value is a non-finite number.
+//# */
+//# public JSONObject(JSONObject jo, String[] sa) throws JSONException {
+//# this();
+//# for (int i = 0; i < sa.length; i += 1) {
+//# putOpt(sa[i], jo.opt(sa[i]));
+//# }
+//# }
+//#endif
+
+ /**
+ * Construct a JSONObject from a JSONTokener.
+ * @param x A JSONTokener object containing the source string.
+ * @throws JSONException If there is a syntax error in the source string.
+ */
+ public JSONObject(JSONTokener x) throws JSONException {
+ this();
+ char c;
+ String key;
+
+ if (x.nextClean() != '{') {
+ throw x.syntaxError("A JSONObject text must begin with '{'");
+ }
+ for (;;) {
+ c = x.nextClean();
+ switch (c) {
+ case 0:
+ throw x.syntaxError("A JSONObject text must end with '}'");
+ case '}':
+ return;
+ default:
+ x.back();
+ key = x.nextValue().toString();
+ }
+
+ /*
+ * The key is followed by ':'. We will also tolerate '=' or '=>'.
+ */
+
+ c = x.nextClean();
+ if (c == '=') {
+ if (x.next() != '>') {
+ x.back();
+ }
+ } else if (c != ':') {
+ throw x.syntaxError("Expected a ':' after a key");
+ }
+ put(key, x.nextValue());
+
+ /*
+ * Pairs are separated by ','. We will also tolerate ';'.
+ */
+
+ switch (x.nextClean()) {
+ case ';':
+ case ',':
+ if (x.nextClean() == '}') {
+ return;
+ }
+ x.back();
+ break;
+ case '}':
+ return;
+ default:
+ throw x.syntaxError("Expected a ',' or '}'");
+ }
+ }
+ }
+
+
+//#ifdef PRODUCER
+//# /**
+//# * Construct a JSONObject from a Map.
+//# * @param map A map object that can be used to initialize the contents of
+//# * the JSONObject.
+//# */
+//# public JSONObject(Hashtable map) {
+//# if (map == null) {
+//# this.myHashMap = new Hashtable();
+//# } else {
+//# this.myHashMap = new Hashtable(map.size());
+//# Enumeration keys = map.keys();
+//# while (keys.hasMoreElements()) {
+//# Object key = keys.nextElement();
+//# this.myHashMap.put(key, map.get(key));
+//# }
+//# }
+//# }
+//#endif
+
+ /**
+ * Construct a JSONObject from a string.
+ * This is the most commonly used JSONObject constructor.
+ * @param string A string beginning
+ * with <code>{</code> <small>(left brace)</small> and ending
+ * with <code>}</code> <small>(right brace)</small>.
+ * @exception JSONException If there is a syntax error in the source string.
+ */
+ public JSONObject(String string) throws JSONException {
+ this(new JSONTokener(string));
+ }
+
+
+ /**
+ * Accumulate values under a key. It is similar to the put method except
+ * that if there is already an object stored under the key then a
+ * JSONArray is stored under the key to hold all of the accumulated values.
+ * If there is already a JSONArray, then the new value is appended to it.
+ * In contrast, the put method replaces the previous value.
+ * @param key A key string.
+ * @param value An object to be accumulated under the key.
+ * @return this.
+ * @throws JSONException If the value is an invalid number
+ * or if the key is null.
+ */
+ public JSONObject accumulate(String key, Object value)
+ throws JSONException {
+ testValidity(value);
+ Object o = opt(key);
+ if (o == null) {
+ put(key, value);
+ } else if (o instanceof JSONArray) {
+ ((JSONArray)o).put(value);
+ } else {
+ put(key, new JSONArray().put(o).put(value));
+ }
+ return this;
+ }
+
+//#ifdef PRODUCER
+//# /**
+//# * Append values to the array under a key. If the key does not exist in the
+//# * JSONObject, then the key is put in the JSONObject with its value being a
+//# * JSONArray containing the value parameter. If the key was already
+//# * associated with a JSONArray, then the value parameter is appended to it.
+//# * @param key A key string.
+//# * @param value An object to be accumulated under the key.
+//# * @return this.
+//# * @throws JSONException If the key is null or if the current value
+//# * associated with the key is not a JSONArray.
+//# */
+//# public JSONObject append(String key, Object value)
+//# throws JSONException {
+//# testValidity(value);
+//# Object o = opt(key);
+//# if (o == null) {
+//# put(key, new JSONArray().put(value));
+//# } else if (o instanceof JSONArray) {
+//# throw new JSONException("JSONObject[" + key +
+//# "] is not a JSONArray.");
+//# } else {
+//# put(key, new JSONArray().put(o).put(value));
+//# }
+//# return this;
+//# }
+//#endif
+
+//#if CLDC!="1.0"
+//# /**
+//# * Produce a string from a double. The string "null" will be returned if
+//# * the number is not finite.
+//# * @param d A double.
+//# * @return A String.
+//# */
+//# static public String doubleToString(double d) {
+//# if (Double.isInfinite(d) || Double.isNaN(d)) {
+//# return "null";
+//# }
+//#
+//# // Shave off trailing zeros and decimal point, if possible.
+//#
+//# String s = Double.toString(d);
+//# if (s.indexOf('.') > 0 && s.indexOf('e') < 0 && s.indexOf('E') < 0) {
+//# while (s.endsWith("0")) {
+//# s = s.substring(0, s.length() - 1);
+//# }
+//# if (s.endsWith(".")) {
+//# s = s.substring(0, s.length() - 1);
+//# }
+//# }
+//# return s;
+//# }
+//#endif
+
+ /**
+ * Get the value object associated with a key.
+ *
+ * @param key A key string.
+ * @return The object associated with the key.
+ * @throws JSONException if the key is not found.
+ */
+ public Object get(String key) throws JSONException {
+ Object o = opt(key);
+ if (o == null) {
+ throw new JSONException("JSONObject[" + quote(key) +
+ "] not found.");
+ }
+ return o;
+ }
+
+
+ /**
+ * Get the boolean value associated with a key.
+ *
+ * @param key A key string.
+ * @return The truth.
+ * @throws JSONException
+ * if the value is not a Boolean or the String "true" or "false".
+ */
+ public boolean getBoolean(String key) throws JSONException {
+ Object o = get(key);
+//#if CLDC!="1.0"
+//# if (o.equals(Boolean.FALSE) ||
+//#else
+ if (o.equals(FALSE) ||
+//#endif
+ (o instanceof String &&
+ ((String)o).toLowerCase().equals("false"))) {
+ return false;
+//#if CLDC!="1.0"
+//# } else if (o.equals(Boolean.TRUE) ||
+//#else
+ } else if (o.equals(TRUE) ||
+//#endif
+ (o instanceof String &&
+ ((String)o).toLowerCase().equals("true"))) {
+ return true;
+ }
+ throw new JSONException("JSONObject[" + quote(key) +
+ "] is not a Boolean.");
+ }
+
+//#if CLDC!="1.0"
+//# /**
+//# * Get the double value associated with a key.
+//# * @param key A key string.
+//# * @return The numeric value.
+//# * @throws JSONException if the key is not found or
+//# * if the value is not a Number object and cannot be converted to a number.
+//# */
+//# public double getDouble(String key) throws JSONException {
+//# Object o = get(key);
+//# if (o instanceof Byte) {
+//# return (double) ((Byte)o).byteValue();
+//# } else if (o instanceof Short) {
+//# return (double) ((Short)o).shortValue();
+//# } else if (o instanceof Integer) {
+//# return (double) ((Integer)o).intValue();
+//# } else if (o instanceof Long) {
+//# return (double) ((Long)o).longValue();
+//# } else if (o instanceof Float) {
+//# return (double) ((Float)o).floatValue();
+//# } else if (o instanceof Double) {
+//# return ((Double)o).doubleValue();
+//# } else if (o instanceof String) {
+//# try {
+//# return Double.valueOf((String)o).doubleValue();
+//# } catch (Exception e) {
+//# throw new JSONException("JSONObject[" + quote(key) +
+//# "] is not a number.");
+//# }
+//# }
+//# throw new JSONException("JSONObject[" + quote(key) +
+//# "] is not a number.");
+//# }
+//#endif
+
+
+ /**
+ * Get the int value associated with a key. If the number value is too
+ * large for an int, it will be clipped.
+ *
+ * @param key A key string.
+ * @return The integer value.
+ * @throws JSONException if the key is not found or if the value cannot
+ * be converted to an integer.
+ */
+ public int getInt(String key) throws JSONException {
+ Object o = get(key);
+ if (o instanceof Byte) {
+ return ((Byte)o).byteValue();
+ } else if (o instanceof Short) {
+ return ((Short)o).shortValue();
+ } else if (o instanceof Integer) {
+ return ((Integer)o).intValue();
+ } else if (o instanceof Long) {
+ return (int) ((Long)o).longValue();
+//#if CLDC!="1.0"
+//# } else if (o instanceof Float) {
+//# return (int) ((Float)o).floatValue();
+//# } else if (o instanceof Double) {
+//# return (int) ((Double)o).doubleValue();
+//# } else if (o instanceof String) {
+//# return (int) getDouble(key);
+//#endif
+ }
+ throw new JSONException("JSONObject[" + quote(key) +
+ "] is not a number.");
+ }
+
+
+ /**
+ * Get the JSONArray value associated with a key.
+ *
+ * @param key A key string.
+ * @return A JSONArray which is the value.
+ * @throws JSONException if the key is not found or
+ * if the value is not a JSONArray.
+ */
+ public JSONArray getJSONArray(String key) throws JSONException {
+ Object o = get(key);
+ if (o instanceof JSONArray) {
+ return (JSONArray)o;
+ }
+ throw new JSONException("JSONObject[" + quote(key) +
+ "] is not a JSONArray.");
+ }
+
+ /**
+ * Get the JSONObject value associated with a key.
+ *
+ * @param key A key string.
+ * @return A JSONObject which is the value.
+ * @throws JSONException if the key is not found or
+ * if the value is not a JSONObject.
+ */
+ public JSONObject getJSONObject(String key) throws JSONException {
+ Object o = get(key);
+ if (o instanceof JSONObject) {
+ return (JSONObject)o;
+ }
+ throw new JSONException("JSONObject[" + quote(key) +
+ "] is not a JSONObject.");
+ }
+
+ /**
+ * Get the long value associated with a key. If the number value is too
+ * long for a long, it will be clipped.
+ *
+ * @param key A key string.
+ * @return The long value.
+ * @throws JSONException if the key is not found or if the value cannot
+ * be converted to a long.
+ */
+ public long getLong(String key) throws JSONException {
+ Object o = get(key);
+ if (o instanceof Byte) {
+ return ((Byte)o).byteValue();
+ } else if (o instanceof Short) {
+ return ((Short)o).shortValue();
+ } else if (o instanceof Integer) {
+ return ((Integer)o).intValue();
+ } else if (o instanceof Long) {
+ return ((Long)o).longValue();
+//#if CLDC!="1.0"
+//# } else if (o instanceof Float) {
+//# return (long) ((Float)o).floatValue();
+//# } else if (o instanceof Double) {
+//# return (long) ((Double)o).doubleValue();
+//# } else if (o instanceof String) {
+//# return (long) getDouble(key);
+//#endif
+ }
+ throw new JSONException("JSONObject[" + quote(key) +
+ "] is not a number.");
+ }
+
+ /**
+ * Get the string associated with a key.
+ *
+ * @param key A key string.
+ * @return A string which is the value.
+ * @throws JSONException if the key is not found.
+ */
+ public String getString(String key) throws JSONException {
+ return get(key).toString();
+ }
+
+ /**
+ * Determine if the JSONObject contains a specific key.
+ * @param key A key string.
+ * @return true if the key exists in the JSONObject.
+ */
+ public boolean has(String key) {
+ return this.myHashMap.containsKey(key);
+ }
+
+
+ /**
+ * Determine if the value associated with the key is null or if there is
+ * no value.
+ * @param key A key string.
+ * @return true if there is no value associated with the key or if
+ * the value is the JSONObject.NULL object.
+ */
+ public boolean isNull(String key) {
+ return JSONObject.NULL.equals(opt(key));
+ }
+
+
+ /**
+ * Get an enumeration of the keys of the JSONObject.
+ *
+ * @return An iterator of the keys.
+ */
+ public Enumeration keys() {
+ return this.myHashMap.keys();
+ }
+
+
+ /**
+ * Get the number of keys stored in the JSONObject.
+ *
+ * @return The number of keys in the JSONObject.
+ */
+ public int length() {
+ return this.myHas...
[truncated message content] |
|
From: <pm_...@us...> - 2011-12-20 22:01:00
|
Revision: 4506
http://mxquery.svn.sourceforge.net/mxquery/?rev=4506&view=rev
Author: pm_fischer
Date: 2011-12-20 22:00:54 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
More JSON tests
Added Paths:
-----------
trunk/MXQuery_Testing/XQTests/ExpectedResults/json/
trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array.xml
trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array_simple.xml
trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple.xml
trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple2.xml
trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_snelson.xml
trunk/MXQuery_Testing/XQTests/Queries/json/
trunk/MXQuery_Testing/XQTests/Queries/json/json_array.xq
trunk/MXQuery_Testing/XQTests/Queries/json/json_array_simple.xq
trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple.xq
trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple2.xq
trunk/MXQuery_Testing/XQTests/Queries/json/json_snelson.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/JSONTest.java
Added: trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array.xml
===================================================================
--- trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array.xml (rev 0)
+++ trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array.xml 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<json type="array"><pair type="object"><pair name="type" type="string">home</pair><pair name="number" type="string">212 555-1234</pair></pair><item type="null"/><pair type="object"><pair name="type" type="string">fax</pair><pair name="number" type="string">646 555-4567</pair></pair></json>
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array_simple.xml
===================================================================
--- trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array_simple.xml (rev 0)
+++ trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_array_simple.xml 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<json type="array"><item type="string">Hello</item><item type="string">World</item></json>
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple.xml
===================================================================
--- trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple.xml (rev 0)
+++ trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple.xml 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<json type="object"><pair name="type" type="string">home</pair></json>
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple2.xml
===================================================================
--- trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple2.xml (rev 0)
+++ trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_object_simple2.xml 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<json type="object"><pair name="number" type="string">212 555-1234</pair><pair name="type" type="string">home</pair></json>
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_snelson.xml
===================================================================
--- trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_snelson.xml (rev 0)
+++ trunk/MXQuery_Testing/XQTests/ExpectedResults/json/json_snelson.xml 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<json type="object"><pair name="lastName" type="string">Smith</pair><pair name="address" type="object"><pair name="streetAddress" type="string">21 2nd Street</pair><pair name="postalCode" type="number">10021</pair><pair name="state" type="string">NY</pair><pair name="city" type="string">New York</pair></pair><pair name="phoneNumbers" type="array"><item type="string">212 732-1234</item><item type="string">646 123-4567</item></pair><pair name="firstName" type="string">John</pair></json>
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/Queries/json/json_array.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/json/json_array.xq (rev 0)
+++ trunk/MXQuery_Testing/XQTests/Queries/json/json_array.xq 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,6 @@
+import module namespace json = "http://www.zorba-xquery.com/modules/converters/json";
+
+let $j_string := '
+[{"type" : "home", "number": "212 555-1234"}, null,
+ { "type" : "fax", "number": "646 555-4567" } ]'
+return json:parse($j_string)
Added: trunk/MXQuery_Testing/XQTests/Queries/json/json_array_simple.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/json/json_array_simple.xq (rev 0)
+++ trunk/MXQuery_Testing/XQTests/Queries/json/json_array_simple.xq 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,3 @@
+import module namespace json = "http://www.zorba-xquery.com/modules/converters/json";
+let $j_string := '["Hello","World"]'
+return json:parse($j_string)
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple.xq (rev 0)
+++ trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple.xq 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,4 @@
+import module namespace
+ json = "http://www.zorba-xquery.com/modules/converters/json";
+
+json:parse('{"type" : "home"}')
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple2.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple2.xq (rev 0)
+++ trunk/MXQuery_Testing/XQTests/Queries/json/json_object_simple2.xq 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,4 @@
+import module namespace
+ json = "http://www.zorba-xquery.com/modules/converters/json";
+
+json:parse('{"type" : "home", "number": "212 555-1234"}')
\ No newline at end of file
Added: trunk/MXQuery_Testing/XQTests/Queries/json/json_snelson.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/json/json_snelson.xq (rev 0)
+++ trunk/MXQuery_Testing/XQTests/Queries/json/json_snelson.xq 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,15 @@
+import module namespace json = "http://www.zorba-xquery.com/modules/converters/json";
+json:parse('{
+ "firstName": "John",
+ "lastName": "Smith",
+ "address": {
+ "streetAddress": "21 2nd Street",
+ "city": "New York",
+ "state": "NY",
+ "postalCode": 10021
+ },
+ "phoneNumbers": [
+ "212 732-1234",
+ "646 123-4567"
+ ]
+ }')
\ No newline at end of file
Added: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/JSONTest.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/JSONTest.java (rev 0)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/JSONTest.java 2011-12-20 22:00:54 UTC (rev 4506)
@@ -0,0 +1,54 @@
+package ch.ethz.mxquery.test.WebService;
+
+import ch.ethz.mxquery.query.PreparedStatement;
+import ch.ethz.mxquery.testsuite.XQueryTestBase;
+
+public class JSONTest extends XQueryTestBase {
+
+ protected static final String JSON_QUERY_PATH = "XQTests/Queries/json/";
+ protected static final String JSON_RESULT_PATH = "XQTests/ExpectedResults/json/";
+
+ public void test_simpleArray() throws Exception{
+ String query = UriToString(JSON_QUERY_PATH+"json_array_simple.xq");
+ PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
+ doQuery(expr);
+ assertXMLEqual(UriToString(JSON_RESULT_PATH+"json_array_simple.xml"),resultBuffer.toString());
+ //assertEquals(UriToString(expected_results+"Q01_Google_Spelling_Suggestion.xml"),myBuffer.toString().trim());
+ }
+
+ public void test_simpleObject() throws Exception{
+ String query = UriToString(JSON_QUERY_PATH+"json_object_simple.xq");
+ PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
+ doQuery(expr);
+ assertXMLEqual(UriToString(JSON_RESULT_PATH+"json_object_simple.xml"),resultBuffer.toString());
+ //assertEquals(UriToString(expected_results+"Q01_Google_Spelling_Suggestion.xml"),myBuffer.toString().trim());
+ }
+
+ public void test_simpleObject2() throws Exception{
+ String query = UriToString(JSON_QUERY_PATH+"json_object_simple2.xq");
+ PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
+ doQuery(expr);
+ System.out.println(resultBuffer.toString());
+ assertXMLEqual(UriToString(JSON_RESULT_PATH+"json_object_simple2.xml"),resultBuffer.toString());
+ //assertEquals(UriToString(expected_results+"Q01_Google_Spelling_Suggestion.xml"),myBuffer.toString().trim());
+ }
+
+ public void test_Array() throws Exception{
+ String query = UriToString(JSON_QUERY_PATH+"json_array.xq");
+ PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
+ doQuery(expr);
+ assertXMLEqual(UriToString(JSON_RESULT_PATH+"json_array.xml"),resultBuffer.toString());
+ //assertEquals(UriToString(expected_results+"Q01_Google_Spelling_Suggestion.xml"),myBuffer.toString().trim());
+ }
+
+ public void test_Snelson() throws Exception{
+ String query = UriToString(JSON_QUERY_PATH+"json_snelson.xq");
+ PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
+ doQuery(expr);
+ //System.out.println(resultBuffer.toString());
+ assertXMLEqual(UriToString(JSON_RESULT_PATH+"json_snelson.xml"),resultBuffer.toString());
+ //assertEquals(UriToString(expected_results+"Q01_Google_Spelling_Suggestion.xml"),myBuffer.toString().trim());
+ }
+
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-20 21:59:15
|
Revision: 4505
http://mxquery.svn.sourceforge.net/mxquery/?rev=4505&view=rev
Author: pm_fischer
Date: 2011-12-20 21:59:06 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
Basic JSON support on Java platforms
Modified Paths:
--------------
trunk/MXQuery/build.xml
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml
Added Paths:
-----------
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/json/
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/json/Parse.java
trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
trunk/MXQuery/src/org/json/
trunk/MXQuery/src/org/json/CDL.java
trunk/MXQuery/src/org/json/JSONArray.java
trunk/MXQuery/src/org/json/JSONException.java
trunk/MXQuery/src/org/json/JSONML.java
trunk/MXQuery/src/org/json/JSONObject.java
trunk/MXQuery/src/org/json/JSONString.java
trunk/MXQuery/src/org/json/JSONStringer.java
trunk/MXQuery/src/org/json/JSONTokener.java
trunk/MXQuery/src/org/json/JSONWriter.java
trunk/MXQuery/src/org/json/XML.java
trunk/MXQuery/src/org/json/XMLTokener.java
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-12-19 13:35:31 UTC (rev 4504)
+++ trunk/MXQuery/build.xml 2011-12-20 21:59:06 UTC (rev 4505)
@@ -1092,6 +1092,7 @@
<!-- remove unsupported classes -->
<echo message="Removing unsupported classes"/>
<delete dir="${androidtmp.dir}/ch/ethz/mxquery/dmcq/"/>
+ <delete dir="${androidtmp.dir}/org/json/"/>
<delete>
<fileset dir="${androidtmp.dir}/ch/ethz/mxquery/functions/fn/">
<include name="NormalizeUnicode.java"/>
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml 2011-12-19 13:35:31 UTC (rev 4504)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/Extensions.xml 2011-12-20 21:59:06 UTC (rev 4505)
@@ -208,5 +208,15 @@
</parameters>
<className>SignString</className>
</functionDescription>
+</functionGroup>
+<functionGroup prefix="json" namespace="http://www.zorba-xquery.com/modules/converters/json">
+ <functionDescription>
+ <functionName>parse</functionName>
+ <parameters>
+ <paramType>string</paramType>
+ </parameters>
+ <className op="json">Parse</className>
+ </functionDescription>
</functionGroup>
+
</functionGallery>
\ No newline at end of file
Added: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/json/Parse.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/json/Parse.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/json/Parse.java 2011-12-20 21:59:06 UTC (rev 4505)
@@ -0,0 +1,86 @@
+/* Copyright 2006 - 2009 ETH Zurich
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.ethz.mxquery.extensionsModules.json;
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.functions.RequestTypeMulti;
+import ch.ethz.mxquery.model.CurrentBasedIterator;
+import ch.ethz.mxquery.model.EmptySequenceIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.xdmio.xmlAdapters.JSONAdapter;
+
+public class Parse extends CurrentBasedIterator implements RequestTypeMulti{
+
+ private boolean useJSONML;
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack)
+ throws MXQueryException {
+ Parse ret = new Parse();
+ ret.setSubIters(subIters);
+ ret.setContext(context, false);
+ ret.useJSONML = useJSONML;
+ return ret;
+ }
+
+ public TokenInterface next() throws MXQueryException {
+ if (called == 0) {
+ init();
+ called++;
+ }
+ return current.next();
+ }
+
+
+ public void init() throws MXQueryException {
+ String add = getStringValueOrEmpty(subIters[0]);
+ if (add == null || add.equals("")) {
+ current = new EmptySequenceIterator(context,loc);
+ return;
+ }
+ current = new JSONAdapter(context, loc, add, useJSONML);
+ return;
+ }
+ public TypeInfo getStaticType() {
+ return new TypeInfo(Type.START_TAG,Type.OCCURRENCE_IND_ZERO_OR_ONE);
+ }
+ public boolean isExprParameter(int valueToCheck, boolean recursive) {
+ if (valueToCheck == EXPR_PARAM_XDMGEN)
+ return true;
+ else
+ return super.isExprParameter(valueToCheck, recursive);
+ }
+
+ public void setOperation(String type) throws MXQueryException {
+ if (type.equals("json"))
+ useJSONML = false;
+ else if (type.equals("jsonml"))
+ useJSONML = true;
+
+ else throw new MXQueryException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Incorrect operation for parse/tidy", loc);
+
+ }
+
+ public void setReturnType(int type) throws MXQueryException {
+ }
+
+}
Added: trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/JSONAdapter.java 2011-12-20 21:59:06 UTC (rev 4505)
@@ -0,0 +1,136 @@
+package ch.ethz.mxquery.xdmio.xmlAdapters;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Vector;
+
+import org.json.JSONTokener;
+
+import ch.ethz.mxquery.contextConfig.Context;
+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.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class JSONAdapter extends XDMImportAdapter {
+ public static final String JSON_URI="http://www.zorba-xquery.com/modules/converters/json";
+ private static final QName JSON_QN = new QName(null,null,"json");
+ private static final QName TYPE_QN = new QName(null,null,"type");
+ private static final QName PAIR_QN = new QName(null,null,"pair");
+ private static final QName NAME_QN = new QName(null,null,"name");
+ private static final QName ITEM_QN = new QName(null,null,"item");
+ Vector tokens;
+ String jsonString;
+ boolean jsonML;
+
+ public JSONAdapter(Context ctx, QueryLocation loc, String jsonString, boolean useJSONML) {
+ super(ctx, loc);
+ this.jsonString = jsonString;
+ tokens = new Vector();
+ jsonML = useJSONML;
+ }
+
+ public TokenInterface next() throws MXQueryException {
+ if (called == 0) {
+ init();
+ }
+ if (called < tokens.size()) {
+ called++;
+ return (TokenInterface)tokens.elementAt(called-1);
+ }
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ private void init() throws MXQueryException {
+ try {
+ Object jo = new JSONTokener(jsonString).nextValue();
+ tokens.addElement(new Token(Type.START_DOCUMENT, createNextTokenId(Type.START_DOCUMENT,null),curNsScope));
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ //tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "unknown", TYPE_QN, curNsScope));
+ handleJSONItem(jo);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "json"), JSON_QN, curNsScope));
+ tokens.addElement(new Token(Type.END_DOCUMENT, createNextTokenId(Type.END_DOCUMENT,null),curNsScope));
+ } catch (JSONException je) {
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"), je.toString(), loc);
+ }
+ }
+
+ void handleJSONItem (Object obj) throws JSONException, MXQueryException {
+ if (obj instanceof JSONObject) {
+ JSONObject jo = ((JSONObject)obj);
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "object", TYPE_QN, curNsScope));
+ JSONArray names = jo.names();
+ for (int i=0;i<names.length();i++) {
+ String nm = (String)names.get(i);
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "pair"), PAIR_QN, curNsScope));
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, nm, NAME_QN, curNsScope));
+ Object no = jo.get(nm);
+ handleJSONItem(no);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.END_TAG, "pair"), PAIR_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj instanceof JSONArray) {
+ JSONArray ja = (JSONArray)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "array", TYPE_QN, curNsScope));
+ for (int i=0;i<ja.length();i++) {
+ tokens.addElement(new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ Object o = ja.get(i);
+ handleJSONItem(o);
+ tokens.addElement(new ElementToken(Type.END_TAG, createNextTokenId(Type.START_TAG, "item"), ITEM_QN, curNsScope));
+ }
+ return;
+ }
+ if (obj instanceof String) {
+ String str = (String)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "string", TYPE_QN, curNsScope));
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), str, curNsScope));
+ return;
+ }
+ if (obj instanceof Integer) {
+ Integer it = (Integer)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "number", TYPE_QN, curNsScope));
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), it.toString(), curNsScope));
+ return;
+ }
+ if (obj instanceof Double) {
+ Double db = (Double)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "number", TYPE_QN, curNsScope));
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), db.toString(), curNsScope));
+ return;
+ }
+ if (obj instanceof Boolean) {
+ Boolean bo = (Boolean)obj;
+ if (tokens.size() > 0) // If not standalone
+ tokens.addElement(createAttributeToken(Type.UNTYPED_ATOMIC, "boolean", TYPE_QN, curNsScope));
+ tokens.add(new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), bo.toString(), curNsScope));
+ return;
+ }
+ if (obj == JSONObject.NULL) {
+ return;
+ }
+ throw new DynamicException(new QName(JSON_URI,"json","ParseError"),"Not implemented Type",loc);
+ }
+
+
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: trunk/MXQuery/src/org/json/CDL.java
===================================================================
--- trunk/MXQuery/src/org/json/CDL.java (rev 0)
+++ trunk/MXQuery/src/org/json/CDL.java 2011-12-20 21:59:06 UTC (rev 4505)
@@ -0,0 +1,279 @@
+package org.json;
+
+/*
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+/**
+ * This provides static methods to convert comma delimited text into a
+ * JSONArray, and to covert a JSONArray into comma delimited text. Comma
+ * delimited text is a very popular format for data interchange. It is
+ * understood by most database, spreadsheet, and organizer programs.
+ * <p>
+ * Each row of text represents a row in a table or a data record. Each row
+ * ends with a NEWLINE character. Each row contains one or more values.
+ * Values are separated by commas. A value can contain any character except
+ * for comma, unless is is wrapped in single quotes or double quotes.
+ * <p>
+ * The first row usually contains the names of the columns.
+ * <p>
+ * A comma delimited list can be converted into a JSONArray of JSONObjects.
+ * The names for the elements in the JSONObjects can be taken from the names
+ * in the first row.
+ * @author JSON.org
+ * @version 2010-12-24
+ */
+public class CDL {
+
+ /**
+ * Get the next value. The value can be wrapped in quotes. The value can
+ * be empty.
+ * @param x A JSONTokener of the source text.
+ * @return The value string, or null if empty.
+ * @throws JSONException if the quoted string is badly formed.
+ */
+ private static String getValue(JSONTokener x) throws JSONException {
+ char c;
+ char q;
+ StringBuffer sb;
+ do {
+ c = x.next();
+ } while (c == ' ' || c == '\t');
+ switch (c) {
+ case 0:
+ return null;
+ case '"':
+ case '\'':
+ q = c;
+ sb = new StringBuffer();
+ for (;;) {
+ c = x.next();
+ if (c == q) {
+ break;
+ }
+ if (c == 0 || c == '\n' || c == '\r') {
+ throw x.syntaxError("Missing close quote '" + q + "'.");
+ }
+ sb.append(c);
+ }
+ return sb.toString();
+ case ',':
+ x.back();
+ return "";
+ default:
+ x.back();
+ return x.nextTo(',');
+ }
+ }
+
+ /**
+ * Produce a JSONArray of strings from a row of comma delimited values.
+ * @param x A JSONTokener of the source text.
+ * @return A JSONArray of strings.
+ * @throws JSONException
+ */
+ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
+ JSONArray ja = new JSONArray();
+ for (;;) {
+ String value = getValue(x);
+ char c = x.next();
+ if (value == null ||
+ (ja.length() == 0 && value.length() == 0 && c != ',')) {
+ return null;
+ }
+ ja.put(value);
+ for (;;) {
+ if (c == ',') {
+ break;
+ }
+ if (c != ' ') {
+ if (c == '\n' || c == '\r' || c == 0) {
+ return ja;
+ }
+ throw x.syntaxError("Bad character '" + c + "' (" +
+ (int)c + ").");
+ }
+ c = x.next();
+ }
+ }
+ }
+
+ /**
+ * Produce a JSONObject from a row of comma delimited text, using a
+ * parallel JSONArray of strings to provides the names of the elements.
+ * @param names A JSONArray of names. This is commonly obtained from the
+ * first row of a comma delimited text file using the rowToJSONArray
+ * method.
+ * @param x A JSONTokener of the source text.
+ * @return A JSONObject combining the names and values.
+ * @throws JSONException
+ */
+ public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
+ throws JSONException {
+ JSONArray ja = rowToJSONArray(x);
+ return ja != null ? ja.toJSONObject(names) : null;
+ }
+
+ /**
+ * Produce a comma delimited text row from a JSONArray. Values containing
+ * the comma character will be quoted. Troublesome characters may be
+ * removed.
+ * @param ja A JSONArray of strings.
+ * @return A string ending in NEWLINE.
+ */
+ public static String rowToString(JSONArray ja) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < ja.length(); i += 1) {
+ if (i > 0) {
+ sb.append(',');
+ }
+ Object object = ja.opt(i);
+ if (object != null) {
+ String string = object.toString();
+ if (string.length() > 0 && (string.indexOf(',') >= 0 ||
+ string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||
+ string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
+ sb.append('"');
+ int length = string.length();
+ for (int j = 0; j < length; j += 1) {
+ char c = string.charAt(j);
+ if (c >= ' ' && c != '"') {
+ sb.append(c);
+ }
+ }
+ sb.append('"');
+ } else {
+ sb.append(string);
+ }
+ }
+ }
+ sb.append('\n');
+ return sb.toString();
+ }
+
+ /**
+ * Produce a JSONArray of JSONObjects from a comma delimited text string,
+ * using the first row as a source of names.
+ * @param string The comma delimited text.
+ * @return A JSONArray of JSONObjects.
+ * @throws JSONException
+ */
+ public static JSONArray toJSONArray(String string) throws JSONException {
+ return toJSONArray(new JSONTokener(string));
+ }
+
+ /**
+ * Produce a JSONArray of JSONObjects from a comma delimited text string,
+ * using the first row as a source of names.
+ * @param x The JSONTokener containing the comma delimited text.
+ * @return A JSONArray of JSONObjects.
+ * @throws JSONException
+ */
+ public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
+ return toJSONArray(rowToJSONArray(x), x);
+ }
+
+ /**
+ * Produce a JSONArray of JSONObjects from a comma delimited text string
+ * using a supplied JSONArray as the source of element names.
+ * @param names A JSONArray of strings.
+ * @param string The comma delimited text.
+ * @return A JSONArray of JSONObjects.
+ * @throws JSONException
+ */
+ public static JSONArray toJSONArray(JSONArray names, String string)
+ throws JSONException {
+ return toJSONArray(names, new JSONTokener(string));
+ }
+
+ /**
+ * Produce a JSONArray of JSONObjects from a comma delimited text string
+ * using a supplied JSONArray as the source of element names.
+ * @param names A JSONArray of strings.
+ * @param x A JSONTokener of the source text.
+ * @return A JSONArray of JSONObjects.
+ * @throws JSONException
+ */
+ public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
+ throws JSONException {
+ if (names == null || names.length() == 0) {
+ return null;
+ }
+ JSONArray ja = new JSONArray();
+ for (;;) {
+ JSONObject jo = rowToJSONObject(names, x);
+ if (jo == null) {
+ break;
+ }
+ ja.put(jo);
+ }
+ if (ja.length() == 0) {
+ return null;
+ }
+ return ja;
+ }
+
+
+ /**
+ * Produce a comma delimited text from a JSONArray of JSONObjects. The
+ * first row will be a list of names obtained by inspecting the first
+ * JSONObject.
+ * @param ja A JSONArray of JSONObjects.
+ * @return A comma delimited text.
+ * @throws JSONException
+ */
+ public static String toString(JSONArray ja) throws JSONException {
+ JSONObject jo = ja.optJSONObject(0);
+ if (jo != null) {
+ JSONArray names = jo.names();
+ if (names != null) {
+ return rowToString(names) + toString(names, ja);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Produce a comma delimited text from a JSONArray of JSONObjects using
+ * a provided list of names. The list of names is not included in the
+ * output.
+ * @param names A JSONArray of strings.
+ * @param ja A JSONArray of JSONObjects.
+ * @return A comma delimited text.
+ * @throws JSONException
+ */
+ public static String toString(JSONArray names, JSONArray ja)
+ throws JSONException {
+ if (names == null || names.length() == 0) {
+ return null;
+ }
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < ja.length(); i += 1) {
+ JSONObject jo = ja.optJSONObject(i);
+ if (jo != null) {
+ sb.append(rowToString(jo.toJSONArray(names)));
+ }
+ }
+ return sb.toString();
+ }
+}
Added: trunk/MXQuery/src/org/json/JSONArray.java
===================================================================
--- trunk/MXQuery/src/org/json/JSONArray.java (rev 0)
+++ trunk/MXQuery/src/org/json/JSONArray.java 2011-12-20 21:59:06 UTC (rev 4505)
@@ -0,0 +1,920 @@
+package org.json;
+
+/*
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * A JSONArray is an ordered sequence of values. Its external text form is a
+ * string wrapped in square brackets with commas separating the values. The
+ * internal form is an object having <code>get</code> and <code>opt</code>
+ * methods for accessing the values by index, and <code>put</code> methods for
+ * adding or replacing values. The values can be any of these types:
+ * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
+ * <code>Number</code>, <code>String</code>, or the
+ * <code>JSONObject.NULL object</code>.
+ * <p>
+ * The constructor can convert a JSON text into a Java object. The
+ * <code>toString</code> method converts to JSON text.
+ * <p>
+ * A <code>get</code> method returns a value if one can be found, and throws an
+ * exception if one cannot be found. An <code>opt</code> method returns a
+ * default value instead of throwing an exception, and so is useful for
+ * obtaining optional values.
+ * <p>
+ * The generic <code>get()</code> and <code>opt()</code> methods return an
+ * object which you can cast or query for type. There are also typed
+ * <code>get</code> and <code>opt</code> methods that do type checking and type
+ * coercion for you.
+ * <p>
+ * The texts produced by the <code>toString</code> methods strictly conform to
+ * JSON syntax rules. The constructors are more forgiving in the texts they will
+ * accept:
+ * <ul>
+ * <li>An extra <code>,</code> <small>(comma)</small> may appear just
+ * before the closing bracket.</li>
+ * <li>The <code>null</code> value will be inserted when there
+ * is <code>,</code> <small>(comma)</small> elision.</li>
+ * <li>Strings may be quoted with <code>'</code> <small>(single
+ * quote)</small>.</li>
+ * <li>Strings do not need to be quoted at all if they do not begin with a quote
+ * or single quote, and if they do not contain leading or trailing spaces,
+ * and if they do not contain any of these characters:
+ * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers
+ * and if they are not the reserved words <code>true</code>,
+ * <code>false</code>, or <code>null</code>.</li>
+ * <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as
+ * well as by <code>,</code> <small>(comma)</small>.</li>
+ * </ul>
+
+ * @author JSON.org
+ * @version 2011-11-24
+ */
+public class JSONArray {
+
+
+ /**
+ * The arrayList where the JSONArray's properties are kept.
+ */
+ private final ArrayList myArrayList;
+
+
+ /**
+ * Construct an empty JSONArray.
+ */
+ public JSONArray() {
+ this.myArrayList = new ArrayList();
+ }
+
+ /**
+ * Construct a JSONArray from a JSONTokener.
+ * @param x A JSONTokener
+ * @throws JSONException If there is a syntax error.
+ */
+ public JSONArray(JSONTokener x) throws JSONException {
+ this();
+ if (x.nextClean() != '[') {
+ throw x.syntaxError("A JSONArray text must start with '['");
+ }
+ if (x.nextClean() != ']') {
+ x.back();
+ for (;;) {
+ if (x.nextClean() == ',') {
+ x.back();
+ this.myArrayList.add(JSONObject.NULL);
+ } else {
+ x.back();
+ this.myArrayList.add(x.nextValue());
+ }
+ switch (x.nextClean()) {
+ case ';':
+ case ',':
+ if (x.nextClean() == ']') {
+ return;
+ }
+ x.back();
+ break;
+ case ']':
+ return;
+ default:
+ throw x.syntaxError("Expected a ',' or ']'");
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Construct a JSONArray from a source JSON text.
+ * @param source A string that begins with
+ * <code>[</code> <small>(left bracket)</small>
+ * and ends with <code>]</code> <small>(right bracket)</small>.
+ * @throws JSONException If there is a syntax error.
+ */
+ public JSONArray(String source) throws JSONException {
+ this(new JSONTokener(source));
+ }
+
+
+ /**
+ * Construct a JSONArray from a Collection.
+ * @param collection A Collection.
+ */
+ public JSONArray(Collection collection) {
+ this.myArrayList = new ArrayList();
+ if (collection != null) {
+ Iterator iter = collection.iterator();
+ while (iter.hasNext()) {
+ this.myArrayList.add(JSONObject.wrap(iter.next()));
+ }
+ }
+ }
+
+
+ /**
+ * Construct a JSONArray from an array
+ * @throws JSONException If not an array.
+ */
+ public JSONArray(Object array) throws JSONException {
+ this();
+ if (array.getClass().isArray()) {
+ int length = Array.getLength(array);
+ for (int i = 0; i < length; i += 1) {
+ this.put(JSONObject.wrap(Array.get(array, i)));
+ }
+ } else {
+ throw new JSONException(
+"JSONArray initial value should be a string or collection or array.");
+ }
+ }
+
+
+ /**
+ * Get the object value associated with an index.
+ * @param index
+ * The index must be between 0 and length() - 1.
+ * @return An object value.
+ * @throws JSONException If there is no value for the index.
+ */
+ public Object get(int index) throws JSONException {
+ Object object = this.opt(index);
+ if (object == null) {
+ throw new JSONException("JSONArray[" + index + "] not found.");
+ }
+ return object;
+ }
+
+
+ /**
+ * Get the boolean value associated with an index.
+ * The string values "true" and "false" are converted to boolean.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The truth.
+ * @throws JSONException If there is no value for the index or if the
+ * value is not convertible to boolean.
+ */
+ public boolean getBoolean(int index) throws JSONException {
+ Object object = this.get(index);
+ if (object.equals(Boolean.FALSE) ||
+ (object instanceof String &&
+ ((String)object).equalsIgnoreCase("false"))) {
+ return false;
+ } else if (object.equals(Boolean.TRUE) ||
+ (object instanceof String &&
+ ((String)object).equalsIgnoreCase("true"))) {
+ return true;
+ }
+ throw new JSONException("JSONArray[" + index + "] is not a boolean.");
+ }
+
+
+ /**
+ * Get the double value associated with an index.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ * @throws JSONException If the key is not found or if the value cannot
+ * be converted to a number.
+ */
+ public double getDouble(int index) throws JSONException {
+ Object object = this.get(index);
+ try {
+ return object instanceof Number
+ ? ((Number)object).doubleValue()
+ : Double.parseDouble((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONArray[" + index +
+ "] is not a number.");
+ }
+ }
+
+
+ /**
+ * Get the int value associated with an index.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ * @throws JSONException If the key is not found or if the value is not a number.
+ */
+ public int getInt(int index) throws JSONException {
+ Object object = this.get(index);
+ try {
+ return object instanceof Number
+ ? ((Number)object).intValue()
+ : Integer.parseInt((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONArray[" + index +
+ "] is not a number.");
+ }
+ }
+
+
+ /**
+ * Get the JSONArray associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return A JSONArray value.
+ * @throws JSONException If there is no value for the index. or if the
+ * value is not a JSONArray
+ */
+ public JSONArray getJSONArray(int index) throws JSONException {
+ Object object = this.get(index);
+ if (object instanceof JSONArray) {
+ return (JSONArray)object;
+ }
+ throw new JSONException("JSONArray[" + index +
+ "] is not a JSONArray.");
+ }
+
+
+ /**
+ * Get the JSONObject associated with an index.
+ * @param index subscript
+ * @return A JSONObject value.
+ * @throws JSONException If there is no value for the index or if the
+ * value is not a JSONObject
+ */
+ public JSONObject getJSONObject(int index) throws JSONException {
+ Object object = this.get(index);
+ if (object instanceof JSONObject) {
+ return (JSONObject)object;
+ }
+ throw new JSONException("JSONArray[" + index +
+ "] is not a JSONObject.");
+ }
+
+
+ /**
+ * Get the long value associated with an index.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ * @throws JSONException If the key is not found or if the value cannot
+ * be converted to a number.
+ */
+ public long getLong(int index) throws JSONException {
+ Object object = this.get(index);
+ try {
+ return object instanceof Number
+ ? ((Number)object).longValue()
+ : Long.parseLong((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONArray[" + index +
+ "] is not a number.");
+ }
+ }
+
+
+ /**
+ * Get the string associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return A string value.
+ * @throws JSONException If there is no string value for the index.
+ */
+ public String getString(int index) throws JSONException {
+ Object object = this.get(index);
+ if (object instanceof String) {
+ return (String)object;
+ }
+ throw new JSONException("JSONArray[" + index + "] not a string.");
+ }
+
+
+ /**
+ * Determine if the value is null.
+ * @param index The index must be between 0 and length() - 1.
+ * @return true if the value at the index is null, or if there is no value.
+ */
+ public boolean isNull(int index) {
+ return JSONObject.NULL.equals(this.opt(index));
+ }
+
+
+ /**
+ * Make a string from the contents of this JSONArray. The
+ * <code>separator</code> string is inserted between each element.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param separator A string that will be inserted between the elements.
+ * @return a string.
+ * @throws JSONException If the array contains an invalid number.
+ */
+ public String join(String separator) throws JSONException {
+ int len = this.length();
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < len; i += 1) {
+ if (i > 0) {
+ sb.append(separator);
+ }
+ sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * Get the number of elements in the JSONArray, included nulls.
+ *
+ * @return The length (or size).
+ */
+ public int length() {
+ return this.myArrayList.size();
+ }
+
+
+ /**
+ * Get the optional object value associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return An object value, or null if there is no
+ * object at that index.
+ */
+ public Object opt(int index) {
+ return (index < 0 || index >= this.length())
+ ? null
+ : this.myArrayList.get(index);
+ }
+
+
+ /**
+ * Get the optional boolean value associated with an index.
+ * It returns false if there is no value at that index,
+ * or if the value is not Boolean.TRUE or the String "true".
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The truth.
+ */
+ public boolean optBoolean(int index) {
+ return this.optBoolean(index, false);
+ }
+
+
+ /**
+ * Get the optional boolean value associated with an index.
+ * It returns the defaultValue if there is no value at that index or if
+ * it is not a Boolean or the String "true" or "false" (case insensitive).
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue A boolean default.
+ * @return The truth.
+ */
+ public boolean optBoolean(int index, boolean defaultValue) {
+ try {
+ return this.getBoolean(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+
+ /**
+ * Get the optional double value associated with an index.
+ * NaN is returned if there is no value for the index,
+ * or if the value is not a number and cannot be converted to a number.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ */
+ public double optDouble(int index) {
+ return this.optDouble(index, Double.NaN);
+ }
+
+
+ /**
+ * Get the optional double value associated with an index.
+ * The defaultValue is returned if there is no value for the index,
+ * or if the value is not a number and cannot be converted to a number.
+ *
+ * @param index subscript
+ * @param defaultValue The default value.
+ * @return The value.
+ */
+ public double optDouble(int index, double defaultValue) {
+ try {
+ return this.getDouble(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+
+ /**
+ * Get the optional int value associated with an index.
+ * Zero is returned if there is no value for the index,
+ * or if the value is not a number and cannot be converted to a number.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ */
+ public int optInt(int index) {
+ return this.optInt(index, 0);
+ }
+
+
+ /**
+ * Get the optional int value associated with an index.
+ * The defaultValue is returned if there is no value for the index,
+ * or if the value is not a number and cannot be converted to a number.
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return The value.
+ */
+ public int optInt(int index, int defaultValue) {
+ try {
+ return this.getInt(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+
+ /**
+ * Get the optional JSONArray associated with an index.
+ * @param index subscript
+ * @return A JSONArray value, or null if the index has no value,
+ * or if the value is not a JSONArray.
+ */
+ public JSONArray optJSONArray(int index) {
+ Object o = this.opt(index);
+ return o instanceof JSONArray ? (JSONArray)o : null;
+ }
+
+
+ /**
+ * Get the optional JSONObject associated with an index.
+ * Null is returned if the key is not found, or null if the index has
+ * no value, or if the value is not a JSONObject.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return A JSONObject value.
+ */
+ public JSONObject optJSONObject(int index) {
+ Object o = this.opt(index);
+ return o instanceof JSONObject ? (JSONObject)o : null;
+ }
+
+
+ /**
+ * Get the optional long value associated with an index.
+ * Zero is returned if there is no value for the index,
+ * or if the value is not a number and cannot be converted to a number.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ */
+ public long optLong(int index) {
+ return this.optLong(index, 0);
+ }
+
+
+ /**
+ * Get the optional long value associated with an index.
+ * The defaultValue is returned if there is no value for the index,
+ * or if the value is not a number and cannot be converted to a number.
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return The value.
+ */
+ public long optLong(int index, long defaultValue) {
+ try {
+ return this.getLong(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+
+ /**
+ * Get the optional string value associated with an index. It returns an
+ * empty string if there is no value at that index. If the value
+ * is not a string and is not null, then it is coverted to a string.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return A String value.
+ */
+ public String optString(int index) {
+ return this.optString(index, "");
+ }
+
+
+ /**
+ * Get the optional string associated with an index.
+ * The defaultValue is returned if the key is not found.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return A String value.
+ */
+ public String optString(int index, String defaultValue) {
+ Object object = this.opt(index);
+ return JSONObject.NULL.equals(object)
+ ? object.toString()
+ : defaultValue;
+ }
+
+
+ /**
+ * Append a boolean value. This increases the array's length by one.
+ *
+ * @param value A boolean value.
+ * @return this.
+ */
+ public JSONArray put(boolean value) {
+ this.put(value ? Boolean.TRUE : Boolean.FALSE);
+ return this;
+ }
+
+
+ /**
+ * Put a value in the JSONArray, where the value will be a
+ * JSONArray which is produced from a Collection.
+ * @param value A Collection value.
+ * @return this.
+ */
+ public JSONArray put(Collection value) {
+ this.put(new JSONArray(value));
+ return this;
+ }
+
+
+ /**
+ * Append a double value. This increases the array's length by one.
+ *
+ * @param value A double value.
+ * @throws JSONException if the value is not finite.
+ * @return this.
+ */
+ public JSONArray put(double value) throws JSONException {
+ Double d = new Double(value);
+ JSONObject.testValidity(d);
+ this.put(d);
+ return this;
+ }
+
+
+ /**
+ * Append an int value. This increases the array's length by one.
+ *
+ * @param value An int value.
+ * @return this.
+ */
+ public JSONArray put(int value) {
+ this.put(new Integer(value));
+ return this;
+ }
+
+
+ /**
+ * Append an long value. This increases the array's length by one.
+ *
+ * @param value A long value.
+ * @return this.
+ */
+ public JSONArray put(long value) {
+ this.put(new Long(value));
+ return this;
+ }
+
+
+ /**
+ * Put a value in the JSONArray, where the value will be a
+ * JSONObject which is produced from a Map.
+ * @param value A Map value.
+ * @return this.
+ */
+ public JSONArray put(Map value) {
+ this.put(new JSONObject(value));
+ return this;
+ }
+
+
+ /**
+ * Append an object value. This increases the array's length by one.
+ * @param value An object value. The value should be a
+ * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
+ * JSONObject.NULL object.
+ * @return this.
+ */
+ public JSONArray put(Object value) {
+ this.myArrayList.add(value);
+ return this;
+ }
+
+
+ /**
+ * Put or replace a boolean value in the JSONArray. If the index is greater
+ * than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value A boolean value.
+ * @return this.
+ * @throws JSONException If the index is negative.
+ */
+ public JSONArray put(int index, boolean value) throws JSONException {
+ this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
+ return this;
+ }
+
+
+ /**
+ * Put a value in the JSONArray, where the value will be a
+ * JSONArray which is produced from a Collection.
+ * @param index The subscript.
+ * @param value A Collection value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the value is
+ * not finite.
+ */
+ public JSONArray put(int index, Collection value) throws JSONException {
+ this.put(index, new JSONArray(value));
+ return this;
+ }
+
+
+ /**
+ * Put or replace a double value. If the index is greater than the length of
+ * the JSONArray, then null elements will be added as necessary to pad
+ * it out.
+ * @param index The subscript.
+ * @param value A double value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the value is
+ * not finite.
+ */
+ public JSONArray put(int index, double value) throws JSONException {
+ this.put(index, new Double(value));
+ return this;
+ }
+
+
+ /**
+ * Put or replace an int value. If the index is greater than the length of
+ * the JSONArray, then null elements will be added as necessary to pad
+ * it out.
+ * @param index The subscript.
+ * @param value An int value.
+ * @return this.
+ * @throws JSONException If the index is negative.
+ */
+ public JSONArray put(int index, int value) throws JSONException {
+ this.put(index, new Integer(value));
+ return this;
+ }
+
+
+ /**
+ * Put or replace a long value. If the index is greater than the length of
+ * the JSONArray, then null elements will be added as necessary to pad
+ * it out.
+ * @param index The subscript.
+ * @param value A long value.
+ * @return this.
+ * @throws JSONException If the index is negative.
+ */
+ public JSONArray put(int index, long value) throws JSONException {
+ this.put(index, new Long(value));
+ return this;
+ }
+
+
+ /**
+ * Put a value in the JSONArray, where the value will be a
+ * JSONObject that is produced from a Map.
+ * @param index The subscript.
+ * @param value The Map value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the the value is
+ * an invalid number.
+ */
+ public JSONArray put(int index, Map value) throws JSONException {
+ this.put(index, new JSONObject(value));
+ return this;
+ }
+
+
+ /**
+ * Put or replace an object value in the JSONArray. If the index is greater
+ * than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value The value to put into the array. The value should be a
+ * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
+ * JSONObject.NULL object.
+ * @return this.
+ * @throws JSONException If the index is negative or if the the value is
+ * an invalid number.
+ */
+ public JSONArray put(int index, Object value) throws JSONException {
+ JSONObject.testValidity(value);
+ if (index < 0) {
+ throw new JSONException("JSONArray[" + index + "] not found.");
+ }
+ if (index < this.length()) {
+ this.myArrayList.set(index, value);
+ } else {
+ while (index != this.length()) {
+ this.put(JSONObject.NULL);
+ }
+ this.put(value);
+ }
+ return this;
+ }
+
+
+ /**
+ * Remove an index and close the hole.
+ * @param index The index of the element to be removed.
+ * @return The value that was associated with the index,
+ * or null if there was no value.
+ */
+ public Object remove(int index) {
+ Object o = this.opt(index);
+ this.myArrayList.remove(index);
+ return o;
+ }
+
+
+ /**
+ * Produce a JSONObject by combining a JSONArray of names with the values
+ * of this JSONArray.
+ * @param names A JSONArray containing a list of key strings. These will be
+ * paired with the values.
+ * @return A JSONObject, or null if there are no names or if this JSONArray
+ * has no values.
+ * @throws JSONException If any of the names are null.
+ */
+ public JSONObject toJSONObject(JSONArray names) throws JSONException {
+ if (names == null || names.length() == 0 || this.length() == 0) {
+ return null;
+ }
+ JSONObject jo = new JSONObject();
+ for (int i = 0; i < names.length(); i += 1) {
+ jo.put(names.getString(i), this.opt(i));
+ }
+ return jo;
+ }
+
+
+ /**
+ * Make a JSON text of this JSONArray. For compactness, no
+ * unnecessary whitespace is added. If it is not possible to produce a
+ * syntactically correct JSON text then null will be returned instead. This
+ * could occur if the array contains an invalid number.
+ * <p>
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return a printable, displayable, transmittable
+ * representation of the array.
+ */
+ public String toString() {
+ try {
+ return '[' + this.join(",") + ']';
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+
+ /**
+ * Make a prettyprinted JSON text of this JSONArray.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of
+ * indentation.
+ * @return a printable, displayable, transmittable
+ * representation of the object, beginning
+ * with <code>[</code> <small>(left bracket)</small> and ending
+ * with <code>]</code> <small>(right bracket)</small>.
+ * @throws JSONException
+ */
+ public String toString(int indentFactor) throws JSONException {
+ return this.toString(indentFactor, 0);
+ }
+
+
+ /**
+ * Make a prettyprinted JSON text of this JSONArray.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of
+ * indentation.
+ * @param indent The indention of the top level.
+ * @return a printable, displayable, transmittable
+ * representation of the array.
+ * @throws JSONException
+ */
+ String toString(int indentFactor, int indent) throws JSONException {
+ int len = this.length();
+ if (len == 0) {
+ return "[]";
+ }
+ int i;
+ StringBuffer sb = new StringBuffer("[");
+ if (len == 1) {
+ sb.append(JSONObject.valueToString(this.myArrayList.get(0),
+ indentFactor, indent));
+ } else {
+ int newindent = indent + indentFactor;
+ sb.append('\n');
+ for (i = 0; i < len; i += 1) {
+ if (i > 0) {
+ sb.append(",\n");
+ }
+ for (int j = 0; j < newindent; j += 1) {
+ sb.append(' ');
+ }
+ sb.append(JSONObject.valueToString(this.myArrayList.get(i),
+ indentFactor, newindent));
+ }
+ sb.append('\n');
+ for (i = 0; i < indent; i += 1) {
+ sb.append(' ');
+ }
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+
+
+ /**
+ * Write the contents of the JSONArray as JSON text to a writer.
+ * For compactness, no whitespace is added.
+ * <p>
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return The writer.
+ * @throws JSONException
+ */
+ public Writer write(Writer writer) throws JSONException {
+ try {
+ boolean b = false;
+ int len = this.length();
+
+ writer.write('[');
+
+ for (int i = 0; i < len; i += 1) {
+ if (b) {
+ writer.write(',');
+ }
+ Object v = this.myArrayList.get(i);
+ if (v instanceof JSONObject) {
+ ((JSONObject)v).write(writer);
+ } else if (v instanceof JSONArray) {
+ ((JSONArray)v).write(writer);
+ } else {
+ writer.write(JSONObject.valueToString(v));
+ }
+ b = true;
+ }
+ writer.write(']');
+ return writer;
+ } catch (IOException e) {
+ throw new JSONException(e);
+ }
+ }
+}
\ No newline at end of file
Added: trunk/MXQuery/src/org/json/JSONException.java
===================================================================
--- trunk/MXQuery/src/org/json/JSONException.java (rev 0)
+++ trunk/MXQuery/src/org/json/JSONException.java 2011-12-20 21:59:06 UTC (rev 4505)
@@ -0,0 +1,28 @@
+package org.json;
+
+/**
+ * The JSONException is thrown by the JSON.org classes when things are amiss.
+ * @author JSON.org
+ * @version 2010-12-24
+ */
+public class JSONException extends Exception {
+ private static final long serialVersionUID = 0;
+ private Throwable cause;
+
+ /**
+ * Constructs a JSONException with an explanatory message.
+ * @param message Detail about the reason for the exception.
+ */
+ public JSONException(String message) {
+ super(message);
+ }
+
+ public JSONException(Throwable cause) {
+ super(cause.getMessage());
+ this.cause = cause;
+ }
+
+ public Throwable getCause() {
+ return this.cause;
+ }
+}
Added: trunk/MXQuery/src/org/json/JSONML.java
===================================================================
--- trunk/MXQuery/src/org/json/JSONML.java (rev 0)
+++ trunk/MXQuery/src/org/json/JSONML.java 2011-12-20 21:59:06 UTC (rev 4505)
@@ -0,0 +1,465 @@
+package org.json;
+
+/*
+Copyright (c) 2008 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+import java.util.Iterator;
+
+
+/**
+ * This provides static methods to convert an XML text into a JSONArray or
+ * JSONObject, and to covert a JSONArray or JSONObject into an XML text using
+ * the JsonML transform.
+ * @author JSON.org
+ * @version 2011-11-24
+ */
+public class JSONML {
+
+ /**
+ * Parse XML values and store them in a JSONArray.
+ * @param x The XMLTokener containing the source string.
+ * @param arrayForm true if array form, false if object form.
+ * @param ja The JSONArray that is containing the current tag or null
+ * if we are at the outermost level.
+ * @return A JSONArray if the value is the outermost tag, otherwise null.
+ * @throws JSONException
+ */
+ private static Object parse(
+ XMLTokener x,
+ boolean arrayForm,
+ JSONArray ja
+ ) throws JSONException {
+ String attribute;
+ char c;
+ String closeTag = null;
+ int i;
+ JSONArray newja = null;
+ JSONObject newjo = null;
+ Object token;
+ String tagName = null;
+
+// Test for and skip past these forms:
+// <!-- ... -->
+// <![ ... ]]>
+// <! ... >
+// <? ... ?>
+
+ while (true) {
+ if (!x.more()) {
+ throw x.syntaxError("Bad XML");
+ }
+ token = x.nextContent();
+ if (token == XML.LT) {
+ token = x.nextToken();
+ if (token instanceof Character) {
+ if (token == XML.SLASH) {
+
+// Close tag </
+
+ token = x.nextToken();
+ if (!(token instanceof String)) {
+ throw new JSONException(
+ "Expected a closing name instead of '" +
+ token + "'.");
+ }
+ if (x.nextToken() != XML.GT) {
+ throw x.syntaxError("Misshaped close tag");
+ }
+ return token;
+ } else if (token == XML.BANG) {
+
+// <!
+
+ c = x.next();
+ if (c == '-') {
+ if (x.next() == '-') {
+ x.skipPast("-->");
+ }
+ x.back();
+ } else if (c == '[') {
+ token = x.nextToken();
+ if (token.equals("CDATA") && x.next() == '[') {
+ if (ja != null) {
+ ja.put(x.nextCDATA());
+ }
+ } else {
+ throw x.syntaxError("Expected 'CDATA['");
+ }
+ } else {
+ i = 1;
+ do {
+ token = x.nextMeta();
+ if (token == null) {
+ throw x.syntaxError("Missing '>' after '<!'.");
+ } else if (token == XML.LT) {
+ i += 1;
+ } else if (token == XML.GT) {
+ i -= 1;
+ }
+ } while (i > 0);
+ }
+ } else if (token == XML.QUEST) {
+
+// <?
+
+ x.skipPast("?>");
+ } else {
+ throw x.syntaxError("Misshaped tag");
+ }
+
+// Open tag <
+
+ } else {
+ if (!(token instanceof String)) {
+ throw x.syntaxError("Bad tagName '" + token + "'.");
+ }
+ tagName = (String)token;
+ newja = new JSONArray();
+ newjo = new JSONObject();
+ if (arrayForm) {
+ newja.put(tagName);
+ if (ja != null) {
+ ja.put(newja);
+ }
+ } else {
+ newjo.put("tagName", tagName);
+ if (ja != null) {
+ ja.put(newjo);
+ }
+ }
+ token = null;
+ for (;;) {
+ if (token == null) {
+ token = x.nextToken();
+ }
+ if (token == null) {
+ throw x.syntaxError("Misshaped tag");
+ }
+ if (!(token instanceof String)) {
+ break;
+ }
+
+// attribute = value
+
+ attribute = (String)token;
+ if (!arrayForm && (attribute == "tagName" || attribute == "childNode")) {
+ throw x.syntaxError("Reserved attribute.");
+ }
+ token = x.nextToken();
+ if (token == XML.EQ) {
+ token = x.nextToken();
+ if (!(token instanceof String)) {
+ throw x.syntaxError("Missing value");
+ }
+ newjo.accumulate(attribute, XML.stringToValue((String)token));
+ ...
[truncated message content] |
|
From: <pm_...@us...> - 2011-12-19 13:35:42
|
Revision: 4504
http://mxquery.svn.sourceforge.net/mxquery/?rev=4504&view=rev
Author: pm_fischer
Date: 2011-12-19 13:35:31 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
Remove unneeded files
Removed Paths:
-------------
trunk/MXQuery/notm.xml
trunk/MXQuery/tm.xml
Deleted: trunk/MXQuery/notm.xml
===================================================================
--- trunk/MXQuery/notm.xml 2011-12-19 13:34:52 UTC (rev 4503)
+++ trunk/MXQuery/notm.xml 2011-12-19 13:35:31 UTC (rev 4504)
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-19 13:35:05
|
Revision: 4503
http://mxquery.svn.sourceforge.net/mxquery/?rev=4503&view=rev
Author: pm_fischer
Date: 2011-12-19 13:34:52 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
- Projection on XMark
- Add changes to other platforms
Modified Paths:
--------------
trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/DescendantOrSelfIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ForIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/GOrderByIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/LetIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/UserdefFuncCall.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/XMLContent.java
trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java
trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
trunk/MXQuery_Android_App/.classpath
trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
Added Paths:
-----------
trunk/MXQuery_Testing/ProjectionTests/queries/Comp1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Cond2.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Cond3.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Cond4.xq
trunk/MXQuery_Testing/ProjectionTests/queries/ElemConstr1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR2.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Path3.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark02.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark03.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark04.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark05.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark06.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark07.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark08.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark09.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark10.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark11.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark12.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark13.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark14.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark15.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark16.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark17.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark18.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark19.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark20.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionXMarkTests.java
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -18,11 +18,14 @@
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+
import java.util.Vector;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.TokenIterator;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.model.XDMIterator;
@@ -170,4 +173,12 @@
public XDMSerializerSettings getOutputSettings() {
return ser;
}
+
+ public Hashtable getProjectionPaths() throws StaticException {
+ //Preliminary implementation, producing just a single doc
+ ObjectObjectPair paths = iter.getProjectionPaths();
+ Hashtable ht = new Hashtable();
+ ht.put("DOC", paths);
+ return ht;
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -28,6 +28,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.CheckNodeType;
import ch.ethz.mxquery.model.CurrentBasedIterator;
@@ -171,7 +172,7 @@
return AXIS_ATTRIBUTE;
}
- public ObjectObjectPair getProjectionPaths() {
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
XDMIterator curSub; // TODO: deal with context item
curSub = subIters[0];
ObjectObjectPair paths = curSub.getProjectionPaths();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -29,6 +29,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.CheckNodeType;
import ch.ethz.mxquery.model.CurrentBasedIterator;
@@ -265,7 +266,7 @@
}
}
- public ObjectObjectPair getProjectionPaths() {
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
XDMIterator curSub; // TODO: deal with context item
curSub = subIters[0];
ObjectObjectPair paths = curSub.getProjectionPaths();
@@ -286,8 +287,5 @@
returned.add(res);
}
return new ObjectObjectPair(returned, paths.getSecond());
- }
-
-
-
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -28,6 +28,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.Constants;
import ch.ethz.mxquery.model.TokenBasedIterator;
@@ -322,7 +323,7 @@
return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_ZERO_OR_ONE);
}
- public ObjectObjectPair getProjectionPaths() {
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
Set returned = new Set();
Set used = new Set();
for (int i=0;i<subIters.length;i++){
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/DescendantOrSelfIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/DescendantOrSelfIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/DescendantOrSelfIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -16,6 +16,7 @@
package ch.ethz.mxquery.iterators;
+import java.util.Enumeration;
import java.util.Vector;
import ch.ethz.mxquery.contextConfig.Context;
@@ -30,6 +31,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.CheckNodeType;
import ch.ethz.mxquery.model.CurrentBasedIterator;
@@ -39,6 +41,8 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.IntegerList;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
/**
*
@@ -447,5 +451,29 @@
}
return super.staticInit();
}
+
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
+ XDMIterator curSub; // TODO: deal with context item
+ curSub = subIters[0];
+ ObjectObjectPair paths = curSub.getProjectionPaths();
+ Set returnedBelow = (Set)paths.getFirst();
+ Set returned = new Set();
+ Enumeration pathEnum = returnedBelow.elements();
+ while (pathEnum.hasMoreElements()) {
+ String res = (String) pathEnum.nextElement();
+ if (res.endsWith("/"))
+ res = res.substring(0, res.length()-1);
+ if (step_uri != null)
+ res = res+"//{"+step_uri+"}:";
+ if (step_local != null) {
+ if (step_uri == null)
+ res = res+"//";
+ res = res+step_local;
+ }
+ returned.add(res);
+ }
+ return new ObjectObjectPair(returned, paths.getSecond());
+ }
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/ForIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/ForIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/ForIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -27,6 +27,7 @@
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.EmptySequenceIterator;
import ch.ethz.mxquery.model.VariableHolder;
@@ -34,6 +35,8 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.ContextPair;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
public class ForIterator extends CurrentBasedIterator {
// private static String vi =
@@ -267,5 +270,14 @@
return this;
}
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
+ ObjectObjectPair curPath = subIters[0].getProjectionPaths();
+ varHolder.setProjectionPaths(new ObjectObjectPair(curPath.getFirst(), new Set()));
+ Set usedAll = new Set();
+ usedAll.addAll((Set) curPath.getFirst());
+ usedAll.addAll((Set) curPath.getSecond());
+ return new ObjectObjectPair(new Set(), usedAll);
+ }
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/GOrderByIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/GOrderByIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/GOrderByIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -13,6 +13,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.VariableHolder;
@@ -20,8 +21,10 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.Comparator;
import ch.ethz.mxquery.util.MergeSort;
+import ch.ethz.mxquery.util.ObjectObjectPair;
import ch.ethz.mxquery.util.OrderOptions;
import ch.ethz.mxquery.util.QuickSort;
+import ch.ethz.mxquery.util.Set;
/**
* Mad props to David Alexander Graf, who did the original order by iterator. I
@@ -311,5 +314,20 @@
}
return this;
}
+
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
+ Set returned = new Set();
+ Set used = new Set();
+ if (subIters != null)
+ for (int i=0;i<subIters.length;i++){
+ ObjectObjectPair cur = subIters[i].getProjectionPaths();
+ used.addAll((Set)cur.getFirst());
+ used.addAll((Set)cur.getSecond());
+ }
+ return new ObjectObjectPair(returned, used);
+
+ }
+
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -22,6 +22,7 @@
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.model.updatePrimitives.PendingUpdateList;
@@ -125,7 +126,7 @@
}
}
- public ObjectObjectPair getProjectionPaths() {
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
Set returned = new Set();
Set used = new Set();
ObjectObjectPair cur = subIters[0].getProjectionPaths();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/LetIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/LetIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/LetIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -26,12 +26,15 @@
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.ContextPair;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
public class LetIterator extends CurrentBasedIterator {
@@ -172,5 +175,14 @@
return this;
}
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
+ ObjectObjectPair curPath = subIters[0].getProjectionPaths();
+ varHolder.setProjectionPaths(new ObjectObjectPair(curPath.getFirst(), new Set()));
+ Set usedAll = new Set();
+ //usedAll.addAll((Set) curPath.getFirst());
+ usedAll.addAll((Set) curPath.getSecond());
+ return new ObjectObjectPair(new Set(), usedAll);
+ }
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/UserdefFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/UserdefFuncCall.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/UserdefFuncCall.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -36,6 +36,8 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.model.updatePrimitives.PendingUpdateList;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
public class UserdefFuncCall extends CurrentBasedIterator {
protected QName[] paramNames;
@@ -376,5 +378,18 @@
public QName [] getClosure() {
return closure;
}
+
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
+ Set used = new Set();
+ for (int i = 0; i < this.subIters.length; i++) {
+ ObjectObjectPair paths = subIters[i].getProjectionPaths();
+ used.addAll((Set) paths.getSecond());
+ VariableHolder vh = this.context.getVariable(this.paramNames[i]);
+ vh.setProjectionPaths(new ObjectObjectPair(paths.getFirst(), new Set()));
+ }
+ ObjectObjectPair functPaths = function.getProjectionPaths();
+ used.addAll((Set) functPaths.getSecond());
+ return new ObjectObjectPair(functPaths.getFirst(), used);
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/XMLContent.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/XMLContent.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/XMLContent.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -15,6 +15,7 @@
package ch.ethz.mxquery.iterators;
+import java.util.Enumeration;
import java.util.Vector;
import ch.ethz.mxquery.bindings.WindowFactory;
@@ -44,6 +45,7 @@
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
import ch.ethz.mxquery.util.Set;
import ch.ethz.mxquery.util.URIUtils;
@@ -607,6 +609,25 @@
this.pendingUpdateList.merge(constElemIterator.getPendingUpdateList());
}
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
+ Set returned = new Set();
+ Set used = new Set();
+
+ if (subIters != null)
+ for (int i=0;i<subIters.length;i++){
+ ObjectObjectPair cur = subIters[i].getProjectionPaths();
+ Enumeration returnedPaths = ((Set)cur.getFirst()).elements();
+ while (returnedPaths.hasMoreElements()) {
+ String curRetPath = (String)returnedPaths.nextElement();
+ used.add(curRetPath+" #");
+ }
+ used.addAll((Set)cur.getSecond());
+ }
+ return new ObjectObjectPair(returned, used);
+
+ }
+
+
// public void setContext(Context context, boolean recursive)
// throws MXQueryException {
// this.context.setParent(context);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -879,7 +879,7 @@
return arg.getText();
}
- public ObjectObjectPair getProjectionPaths() {
+ public ObjectObjectPair getProjectionPaths() throws StaticException {
XDMIterator [] subs = getAllSubIters();
if (subs != null && subs.length == 1)
return subs[0].getProjectionPaths();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -24,6 +24,7 @@
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.updatePrimitives.PendingUpdateList;
import ch.ethz.mxquery.util.KXmlSerializer;
import ch.ethz.mxquery.util.ObjectObjectPair;
@@ -212,7 +213,8 @@
* - returned
* - used
* @return Pair of Path Sets, first is returned, second is used
+ * @throws StaticException
*/
- public abstract ObjectObjectPair getProjectionPaths();
+ public abstract ObjectObjectPair getProjectionPaths() throws StaticException;
}
\ No newline at end of file
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -22,6 +22,7 @@
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.xdmio.StoreSet;
@@ -147,7 +148,8 @@
/**
* Get the projection paths for all accessed resources
* @return a mapping from resourcename (URI, variable QName) -> Pair (returned, used) Paths
+ * @throws StaticException
*/
- public Hashtable getProjectionPaths();
+ public Hashtable getProjectionPaths() throws StaticException;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -31,6 +31,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -182,7 +183,7 @@
return ser;
}
- public Hashtable getProjectionPaths() {
+ public Hashtable getProjectionPaths() throws StaticException {
//Preliminary implementation, producing just a single doc
ObjectObjectPair paths = iter.getProjectionPaths();
Hashtable ht = new Hashtable();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -3915,13 +3915,16 @@
inscopevars[i], true, getCurrentLoc());
// orderedVars[i].setResettable(true);
}
- extendCurrentContextScope();
+ createNewContextScope();
for (int i = 0; i < inscopevars.length; i++) {
getCurrentContext().registerVariable(inscopevars[i], true);
}
- return new GOrderByIterator(getCurrentContext(), getCurrentLoc(),
+ GOrderByIterator ret = new GOrderByIterator(getCurrentContext(), getCurrentLoc(),
arrOptions, stable, orderedVars, arrExprs);
+ removeContextScope();
+
+ return ret;
}
private void collationSpecification() throws MXQueryException,
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -15,6 +15,8 @@
package ch.ethz.mxquery.query.impl;
import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+
import java.util.Vector;
import com.google.gwt.dom.client.Document;
@@ -30,6 +32,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -175,4 +178,11 @@
this.addExternalResource(new QName(varname), resource);
}
+ public Hashtable getProjectionPaths() throws StaticException {
+ //Preliminary implementation, producing just a single doc
+ ObjectObjectPair paths = iter.getProjectionPaths();
+ Hashtable ht = new Hashtable();
+ ht.put("DOC", paths);
+ return ht;
+ }
}
Modified: trunk/MXQuery_Android_App/.classpath
===================================================================
--- trunk/MXQuery_Android_App/.classpath 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery_Android_App/.classpath 2011-12-19 13:34:52 UTC (rev 4503)
@@ -4,5 +4,5 @@
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="/MXQuery/dist/mxquery-android.jar" sourcepath="/MXQuery/dist/mxquery-android-source.jar"/>
- <classpathentry kind="output" path="bin"/>
+ <classpathentry kind="output" path="bin/classes"/>
</classpath>
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Comp1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Comp1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Comp1.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1 @@
+doc("xmark.xml")/site/regions/* = 3
Modified: trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -1,3 +1,3 @@
-if(true)
+if(true())
then doc("xmark.xml")/site/people/person
-else doc("xmark.xml")/site/open_auctions/open_auctions
\ No newline at end of file
+else doc("xmark.xml")/site/open_auctions/open_auction
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Cond2.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Cond2.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Cond2.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+(if(true())
+then doc("xmark.xml")/site/people/person
+else doc("xmark.xml")/site/open_auctions/open_auction)/@id
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Cond3.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Cond3.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Cond3.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+(if(doc("xmark.xml")/site/regions)
+then doc("xmark.xml")/site/people/person
+else doc("xmark.xml")/site/open_auctions/open_auction)/@id
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Cond4.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Cond4.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Cond4.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+(if(count(doc("xmark.xml")/site/regions/*) = 3)
+then doc("xmark.xml")/site/people/person
+else doc("xmark.xml")/site/open_auctions/open_auction)/@id
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/ElemConstr1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/ElemConstr1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/ElemConstr1.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+<elem>{if(true())
+then doc("xmark.xml")/site/people/person
+else doc("xmark.xml")/site/open_auctions/open_auction}</elem>/@id
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR2.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR2.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR2.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+for $a in doc("xmark.xml")/site/people/person
+order by $a/emailaddress
+return $a/name
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Path3.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Path3.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Path3.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1 @@
+doc("xmark.xml")/site/people/person/@id
\ No newline at end of file
Modified: trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -1,3 +1,4 @@
-let $auction := doc()
-return for $b in $auction/site/people/person[@id = 'person0']
+let $auction := doc("xmark.xml")
+return for $b in $auction/site/people/person
+where $b/@id = 'person0'
return $b/name/text()
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark02.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark02.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark02.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+let $auction := doc("auction.xml") return
+for $b in $auction/site/open_auctions/open_auction
+return <increase>{$b/bidder[1]/increase/text()}</increase>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark03.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark03.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark03.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,7 @@
+let $auction := doc("auction.xml") return
+for $b in $auction/site/open_auctions/open_auction
+where $b/bidder[1]/increase * 2 <= $b/bidder[last()]/increase
+return
+ <increase
+ first="{$b/bidder[1]/increase}"
+ last="{$b/bidder[last()]/increase}"/>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark04.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark04.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark04.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,7 @@
+let $auction := doc("auction.xml") return
+for $b in $auction/site/open_auctions/open_auction
+where
+ some $pr1 in $b/bidder/personref[person = "person20"],
+ $pr2 in $b/bidder/personref[person = "person51"]
+ satisfies $pr1 << $pr2
+return <history>{$b/reserve/text()}</history>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark05.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark05.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark05.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,5 @@
+let $auction := doc("auction.xml") return
+count(
+ for $i in $auction/site/closed_auctions/closed_auction
+ where $i/price >= 40
+ return $i/price)
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark06.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark06.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark06.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,2 @@
+let $auction := doc("auction.xml") return
+for $b in $auction//site/regions return count($b//item)
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark07.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark07.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark07.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,4 @@
+let $auction := doc("auction.xml") return
+for $p in $auction/site
+return
+ count($p//description) + count($p//annotation) + count($p//emailaddress)
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark08.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark08.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark08.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,7 @@
+let $auction := doc("auction.xml") return
+for $p in $auction/site/people/person
+let $a :=
+ for $t in $auction/site/closed_auctions/closed_auction
+ where $t/buyer/person = $p/id
+ return $t
+return <item person="{$p/name}">{count($a)}</item>
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark09.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark09.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark09.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,12 @@
+let $auction := doc("auction.xml") return
+let $ca := $auction/site/closed_auctions/closed_auction return
+let
+ $ei := $auction/site/regions/europe/item
+for $p in $auction/site/people/person
+let $a :=
+ for $t in $ca
+ where $p/id = $t/buyer/person
+ return
+ let $n := for $t2 in $ei where $t/itemref/item = $t2/id return $t2
+ return <item>{$n/name}</item>
+return <person name="{$p/name}">{$a}</person>
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark10.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark10.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark10.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,27 @@
+let $auction := doc("auction.xml") return
+for $i in
+ distinct-values($auction/site/people/person/profile/interest/category)
+let $p :=
+ for $t in $auction/site/people/person
+ where $t/profile/interest/category = $i
+ return
+ <personne>
+ <statistiques>
+ <sexe>{$t/profile/gender}</sexe>
+ <age>{$t/profile/age}</age>
+ <education>{$t/profile/education}</education>
+ <revenu>{fn:data($t/profile/income)}</revenu>
+ </statistiques>
+ <coordonnees>
+ <nom>{$t/name}</nom>
+ <rue>{$t/address/street}</rue>
+ <ville>{$t/address/city}</ville>
+ <pays>{$t/address/country}</pays>
+ <reseau>
+ <courrier>{$t/emailaddress}</courrier>
+ <pagePerso>{$t/homepage}</pagePerso>
+ </reseau>
+ </coordonnees>
+ <cartePaiement>{$t/creditcard}</cartePaiement>
+ </personne>
+return <categorie>{<id>{$i}</id>, $p}</categorie>
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark11.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark11.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark11.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,7 @@
+let $auction := doc("auction.xml") return
+for $p in $auction/site/people/person
+let $l :=
+ for $i in $auction/site/open_auctions/open_auction/initial
+ where $p/profile/income > 5000 * $i
+ return $i
+return <items name="{$p/name}">{count($l)}</items>
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark12.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark12.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark12.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,8 @@
+let $auction := doc("auction.xml") return
+for $p in $auction/site/people/person
+let $l :=
+ for $i in $auction/site/open_auctions/open_auction/initial
+ where $p/profile/income > 5000 * $i
+ return $i
+where $p/profile/income > 50000
+return <items person="{$p/profile/income}">{count($l)}</items>
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark13.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark13.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark13.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,3 @@
+let $auction := doc("auction.xml") return
+for $i in $auction/site/regions/australia/item
+return <item name="{$i/name}">{$i/description}</item>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark14.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark14.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark14.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,4 @@
+let $auction := doc("auction.xml") return
+for $i in $auction/site//item
+where contains($i/description, "gold")
+return $i/name
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark15.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark15.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark15.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,11 @@
+let $auction := doc("auction.xml") return
+for $a in
+ $auction/site/closed_auctions/closed_auction/annotation/description/parlist/
+ listitem/
+ parlist/
+ listitem/
+ text/
+ emph/
+ keyword/
+ text()
+return <text>{$a}</text>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark16.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark16.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark16.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,10 @@
+let $auction := doc("auction.xml") return
+for $a in $auction/site/closed_auctions/closed_auction
+where
+ not(
+ empty(
+ $a/annotation/description/parlist/listitem/parlist/listitem/text/emph/
+ keyword
+ )
+ )
+return <person id="{$a/seller/person}"/>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark17.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark17.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark17.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,4 @@
+let $auction := doc("auction.xml") return
+for $p in $auction/site/people/person
+where empty($p/homepage)
+return <person name="{$p/name}"/>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark18.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark18.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark18.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,9 @@
+declare namespace local = "http://www.foobar.org";
+declare function local:convert($v as xs:decimal?) as xs:decimal?
+{
+ 2.20371 * $v (: convert Dfl to Euro :)
+};
+
+let $auction := doc("auction.xml") return
+for $i in $auction/site/open_auctions/open_auction
+return local:convert($i/reserve)
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark19.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark19.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark19.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,5 @@
+let $auction := doc("auction.xml") return
+for $b in $auction/site/regions//item
+let $k := $b/name
+order by $b/location ascending empty greatest
+return <item name="{$k}">{$b/location}</item>
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark20.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark20.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark20.xq 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,26 @@
+let $auction := doc("auction.xml") return
+<result>
+ <preferred>
+ {count($auction/site/people/person/profile[income >= 100000])}
+ </preferred>
+ <standard>
+ {
+ count(
+ $auction/site/people/person/
+ profile[income < 100000 and income >= 30000]
+ )
+ }
+ </standard>
+ <challenge>
+ {count($auction/site/people/person/profile[income < 30000])}
+ </challenge>
+ <na>
+ {
+ count(
+ for $p in $auction/site/people/person
+ where empty($p/profile/income)
+ return $p
+ )
+ }
+ </na>
+</result>
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java 2011-12-19 13:28:47 UTC (rev 4502)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -87,6 +87,15 @@
//assertEquals(resultBuffer.toString().trim(), "false");
}
+ public void test_Comp1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Comp1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
public void test_FLWOR1() throws Exception{
String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"FLWOR1.xq");
@@ -97,16 +106,24 @@
//assertEquals(resultBuffer.toString().trim(), "false");
}
-
- public void test_XMark01() throws Exception{
- String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark01.xq");
+ public void test_FLWOR2() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"FLWOR2.xq");
PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
Hashtable ht = pi.getProjectionPaths();
handleProjectionPaths(ht);
//assertEquals(resultBuffer.toString().trim(), "false");
- };
+ }
+ public void test_ElemConstr1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"ElemConstr1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
private void handleProjectionPaths(Hashtable projPaths) {
ObjectObjectPair paths = (ObjectObjectPair) projPaths.get("DOC");
Set returned = (Set) paths.getFirst();
Added: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionXMarkTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionXMarkTests.java (rev 0)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionXMarkTests.java 2011-12-19 13:34:52 UTC (rev 4503)
@@ -0,0 +1,231 @@
+/**
+ *
+ */
+package ch.ethz.mxquery.test;
+
+import java.util.Enumeration;
+
+
+import ch.ethz.mxquery.query.PreparedStatement;
+import ch.ethz.mxquery.testsuite.XQueryTestBase;
+import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
+
+
+/**
+ * @author petfisch
+ *
+ */
+public class ProjectionXMarkTests extends XQueryTestBase{
+
+ private static final String TEST_PROJECTION_PREFIX = "ProjectionTests";
+ private static final String TEST_PROJECTION_QUERY_PREFIX = TEST_PROJECTION_PREFIX+"/queries/";
+
+ public void test_XMark01() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark01.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark02() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark02.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark03() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark03.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark04() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark04.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark05() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark05.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark06() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark06.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark07() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark07.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark08() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark08.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark09() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark09.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark10() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark10.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark11() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark11.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark12() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark12.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark13() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark13.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark14() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark14.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark15() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark15.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark16() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark16.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+
+ public void test_XMark17() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark17.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark18() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark18.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark19() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark19.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ public void test_XMark20() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark20.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ private void handleProjectionPaths(Hashtable projPaths) {
+ ObjectObjectPair paths = (ObjectObjectPair) projPaths.get("DOC");
+ Set returned = (Set) paths.getFirst();
+ Set used = (Set) paths.getSecond();
+ Enumeration en = returned.elements();
+ while (en.hasMoreElements()) {
+ String curPath = (String) en.nextElement();
+ System.out.println(curPath+" #");
+ }
+ en = used.elements();
+ while (en.hasMoreElements()) {
+ String curPath = (String) en.nextElement();
+ System.out.println(curPath);
+ }
+ };
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-19 13:28:53
|
Revision: 4502
http://mxquery.svn.sourceforge.net/mxquery/?rev=4502&view=rev
Author: pm_fischer
Date: 2011-12-19 13:28:47 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
- Attribute Iterator is now also an Axis Iterator
- Projection for Attribute
- Test for complex conditionals
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/AxisIterator.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java 2011-12-19 13:26:50 UTC (rev 4501)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/AttributeIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
@@ -15,6 +15,7 @@
package ch.ethz.mxquery.iterators;
+import java.util.Enumeration;
import java.util.Vector;
import ch.ethz.mxquery.contextConfig.Context;
@@ -32,6 +33,8 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
/**
* Event of an Attribute Declaration in XQuery ('@attributename')
@@ -39,7 +42,7 @@
* @author Matthias Braun
*
*/
-public class AttributeIterator extends CurrentBasedIterator {
+public class AttributeIterator extends CurrentBasedIterator implements AxisIterator{
private String local = null;
@@ -163,5 +166,34 @@
return super.staticInit();
}
+ public int getDirection() {
+ // TODO Auto-generated method stub
+ return AXIS_ATTRIBUTE;
+ }
+
+ public ObjectObjectPair getProjectionPaths() {
+ XDMIterator curSub; // TODO: deal with context item
+ curSub = subIters[0];
+ ObjectObjectPair paths = curSub.getProjectionPaths();
+ Set returnedBelow = (Set)paths.getFirst();
+ Set returned = new Set();
+ Enumeration pathEnum = returnedBelow.elements();
+ while (pathEnum.hasMoreElements()) {
+ String res = (String) pathEnum.nextElement();
+ if (res.endsWith("/"))
+ res = res.substring(0, res.length()-1);
+ if (namespace != null)
+ res = res+"/@{"+namespace+"}:";
+ if (local != null) {
+ if (namespace == null)
+ res = res+"/@";
+ res = res+local;
+ }
+ returned.add(res);
+ }
+ return new ObjectObjectPair(returned, paths.getSecond());
+ }
+
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/AxisIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/AxisIterator.java 2011-12-19 13:26:50 UTC (rev 4501)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/AxisIterator.java 2011-12-19 13:28:47 UTC (rev 4502)
@@ -15,7 +15,7 @@
public static final int AXIS_PRECEDING_SIBLING = 24;
public static final int BACKWARD_AXIS_MASK = 16;
public static final int SELF_AXIS_MASK = 1;
-
+ public static final int AXIS_ATTRIBUTE = 10;
public abstract int getDirection();
}
\ No newline at end of file
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java 2011-12-19 13:26:50 UTC (rev 4501)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java 2011-12-19 13:28:47 UTC (rev 4502)
@@ -40,6 +40,54 @@
//assertEquals(resultBuffer.toString().trim(), "false");
}
+ public void test_Path3() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Path3.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+
+ public void test_Cond1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Cond1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+
+ public void test_Cond2() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Cond2.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+ public void test_Cond3() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Cond3.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+ public void test_Cond4() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Cond4.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+
public void test_FLWOR1() throws Exception{
String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"FLWOR1.xq");
PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-19 13:27:01
|
Revision: 4501
http://mxquery.svn.sourceforge.net/mxquery/?rev=4501&view=rev
Author: pm_fischer
Date: 2011-12-19 13:26:50 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
- Extend PreparedStatement to expose Projections paths
- Support projection paths in doc() and Child step
- Test cases for simple paths expressions, FLWOR, Conditional, XMark Q1
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java
trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
Added Paths:
-----------
trunk/MXQuery_Testing/ProjectionTests/
trunk/MXQuery_Testing/ProjectionTests/expectedPaths/
trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt
trunk/MXQuery_Testing/ProjectionTests/queries/
trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -36,6 +36,8 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.IOLib;
import ch.ethz.mxquery.util.LineReader;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
import ch.ethz.mxquery.util.URIUtils;
import ch.ethz.mxquery.xdmio.XDMInputFactory;
import ch.ethz.mxquery.xdmio.XMLSource;
@@ -251,4 +253,12 @@
else
return null;
}
+
+ public ObjectObjectPair getProjectionPaths() {
+ Set returned = new Set();
+ returned.add("/");
+ return new ObjectObjectPair(returned, new Set());
+ }
+
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -15,6 +15,7 @@
package ch.ethz.mxquery.iterators;
+import java.util.Enumeration;
import java.util.Vector;
import ch.ethz.mxquery.contextConfig.Context;
@@ -35,6 +36,8 @@
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
/**
*
@@ -261,5 +264,30 @@
exprCategory = checkExprDefault(subIters,isScripting);
}
}
+
+ public ObjectObjectPair getProjectionPaths() {
+ XDMIterator curSub; // TODO: deal with context item
+ curSub = subIters[0];
+ ObjectObjectPair paths = curSub.getProjectionPaths();
+ Set returnedBelow = (Set)paths.getFirst();
+ Set returned = new Set();
+ Enumeration pathEnum = returnedBelow.elements();
+ while (pathEnum.hasMoreElements()) {
+ String res = (String) pathEnum.nextElement();
+ if (res.endsWith("/"))
+ res = res.substring(0, res.length()-1);
+ if (step_uri != null)
+ res = res+"/{"+step_uri+"}:";
+ if (step_local != null) {
+ if (step_uri == null)
+ res = res+"/";
+ res = res+step_local;
+ }
+ returned.add(res);
+ }
+ return new ObjectObjectPair(returned, paths.getSecond());
+ }
+
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -387,10 +387,7 @@
throw new DynamicException(ErrorCodes.U0021_UPDATE_DYNAMIC_INVALID_XDM,"Duplicate attribute names in updates",null);
else
seenAttrNames.add(attName);
- } else {
- if (seenAttrNames.size() > 0)
- seenAttrNames = new Set();
- }
+ }
else {
if (seenAttrNames.size() > 0)
seenAttrNames = new Set();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -23,6 +23,7 @@
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.xdmio.StoreSet;
import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
@@ -143,5 +144,10 @@
* @return null if no output settings in the query, the settings object otherwise
*/
public XDMSerializerSettings getOutputSettings();
+ /**
+ * Get the projection paths for all accessed resources
+ * @return a mapping from resourcename (URI, variable QName) -> Pair (returned, used) Paths
+ */
+ public Hashtable getProjectionPaths();
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -17,6 +17,7 @@
import java.util.Enumeration;
import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
import java.util.Vector;
@@ -180,4 +181,12 @@
public XDMSerializerSettings getOutputSettings() {
return ser;
}
+
+ public Hashtable getProjectionPaths() {
+ //Preliminary implementation, producing just a single doc
+ ObjectObjectPair paths = iter.getProjectionPaths();
+ Hashtable ht = new Hashtable();
+ ht.put("DOC", paths);
+ return ht;
+ }
}
Added: trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,2 @@
+/site/people/person/@id
+/site/peope/person/name #
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,3 @@
+if(true)
+then doc("xmark.xml")/site/people/person
+else doc("xmark.xml")/site/open_auctions/open_auctions
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,2 @@
+for $a in doc("xmark.xml")/site/people/person
+return $a/name
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1 @@
+doc("xmark.xml")/site
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1 @@
+doc("xmark.xml")/site/people/person
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,3 @@
+let $auction := doc()
+return for $b in $auction/site/people/person[@id = 'person0']
+return $b/name/text()
\ No newline at end of file
Added: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java (rev 0)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,78 @@
+/**
+ *
+ */
+package ch.ethz.mxquery.test;
+
+import java.util.Enumeration;
+
+
+import ch.ethz.mxquery.query.PreparedStatement;
+import ch.ethz.mxquery.testsuite.XQueryTestBase;
+import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
+
+
+/**
+ * @author petfisch
+ *
+ */
+public class ProjectionTests extends XQueryTestBase{
+
+ private static final String TEST_PROJECTION_PREFIX = "ProjectionTests";
+ private static final String TEST_PROJECTION_QUERY_PREFIX = TEST_PROJECTION_PREFIX+"/queries/";
+
+ public void test_Path1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Path1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+ public void test_Path2() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Path2.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+ public void test_FLWOR1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"FLWOR1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+
+ public void test_XMark01() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark01.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ private void handleProjectionPaths(Hashtable projPaths) {
+ ObjectObjectPair paths = (ObjectObjectPair) projPaths.get("DOC");
+ Set returned = (Set) paths.getFirst();
+ Set used = (Set) paths.getSecond();
+ Enumeration en = returned.elements();
+ while (en.hasMoreElements()) {
+ String curPath = (String) en.nextElement();
+ System.out.println(curPath+" #");
+ }
+ en = used.elements();
+ while (en.hasMoreElements()) {
+ String curPath = (String) en.nextElement();
+ System.out.println(curPath);
+ }
+ };
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-12-19 13:23:35
|
Revision: 4500
http://mxquery.svn.sourceforge.net/mxquery/?rev=4500&view=rev
Author: pm_fischer
Date: 2011-12-19 13:23:24 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
Foundations of projection path generator
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/VariableIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/TokenBasedIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java
trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/CompareIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -33,6 +33,8 @@
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
/**
*
@@ -319,5 +321,17 @@
public TypeInfo getStaticType() {
return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_ZERO_OR_ONE);
}
+
+ public ObjectObjectPair getProjectionPaths() {
+ Set returned = new Set();
+ Set used = new Set();
+ for (int i=0;i<subIters.length;i++){
+ ObjectObjectPair cur = subIters[i].getProjectionPaths();
+ used.addAll((Set)cur.getFirst());
+ used.addAll((Set)cur.getSecond());
+ }
+ return new ObjectObjectPair(returned, used);
+ }
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/IfThenElseIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -26,6 +26,8 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.model.updatePrimitives.PendingUpdateList;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
/**
*
@@ -123,6 +125,22 @@
}
}
+ public ObjectObjectPair getProjectionPaths() {
+ Set returned = new Set();
+ Set used = new Set();
+ ObjectObjectPair cur = subIters[0].getProjectionPaths();
+ // Conditionals used and returned go to to used
+ used.addAll((Set)cur.getFirst());
+ used.addAll((Set)cur.getSecond());
+ for (int i=1;i<subIters.length;i++){
+ cur = subIters[i].getProjectionPaths();
+ returned.addAll((Set)cur.getFirst());
+ used.addAll((Set)cur.getSecond());
+ }
+ return new ObjectObjectPair(returned, used);
+ }
+
+
// public TypeInfo getReturnType() {
// // TODO Auto-generated method stub
// return super.getReturnType();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/VariableIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/VariableIterator.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/VariableIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -35,6 +35,7 @@
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
/**
*
@@ -258,5 +259,7 @@
return false;
}
-
+ public ObjectObjectPair getProjectionPaths() {
+ return valueHolder.getProjectionPaths();
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -43,6 +43,8 @@
import ch.ethz.mxquery.sms.interfaces.MaterializingStore;
import ch.ethz.mxquery.util.ContextPair;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
import ch.ethz.mxquery.util.Utils;
/**
@@ -875,5 +877,22 @@
if (source.next().getEventType() != Type.END_SEQUENCE)
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Single Item expected", loc);
return arg.getText();
+ }
+
+ public ObjectObjectPair getProjectionPaths() {
+ XDMIterator [] subs = getAllSubIters();
+ if (subs != null && subs.length == 1)
+ return subs[0].getProjectionPaths();
+ else {
+ Set returned = new Set();
+ Set used = new Set();
+ if (subs != null)
+ for (int i=0;i<subs.length;i++){
+ ObjectObjectPair cur = subs[i].getProjectionPaths();
+ returned.addAll((Set)cur.getFirst());
+ used.addAll((Set)cur.getSecond());
+ }
+ return new ObjectObjectPair(returned, used);
+ }
}
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/TokenBasedIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/TokenBasedIterator.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/TokenBasedIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -20,6 +20,8 @@
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
public abstract class TokenBasedIterator extends Iterator{
@@ -80,5 +82,5 @@
protected void resetImpl() throws MXQueryException {
super.resetImpl();
currentToken = Token.START_SEQUENCE_TOKEN;
- }
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -31,6 +31,7 @@
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.VariableIterator;
import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
public class VariableHolder {
@@ -47,6 +48,7 @@
private int contextPos;
private Context ctx;
private XDMIterator seqTypeIt = null;
+ private ObjectObjectPair projectionPaths;
@@ -251,4 +253,13 @@
public Hashtable getAnnotations(){
return annotations;
}
+
+ public void setProjectionPaths(ObjectObjectPair paths) {
+ projectionPaths = paths;
+ }
+
+ public ObjectObjectPair getProjectionPaths() {
+ return projectionPaths;
+ }
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -26,6 +26,7 @@
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.model.updatePrimitives.PendingUpdateList;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
import ch.ethz.mxquery.util.Traversable;
/**
@@ -205,5 +206,13 @@
public KXmlSerializer traverseIteratorTree(KXmlSerializer serializer) throws Exception;
public abstract boolean isScoring();
+ /**
+ * Get the projection path (=minimum requirement document fragments)
+ * There are two types of paths:
+ * - returned
+ * - used
+ * @return Pair of Path Sets, first is returned, second is used
+ */
+ public abstract ObjectObjectPair getProjectionPaths();
}
\ No newline at end of file
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2011-10-21 20:16:23 UTC (rev 4499)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2011-12-19 13:23:24 UTC (rev 4500)
@@ -387,6 +387,9 @@
throw new DynamicException(ErrorCodes.U0021_UPDATE_DYNAMIC_INVALID_XDM,"Duplicate attribute names in updates",null);
else
seenAttrNames.add(attName);
+ } else {
+ if (seenAttrNames.size() > 0)
+ seenAttrNames = new Set();
}
else {
if (seenAttrNames.size() > 0)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-21 20:16:29
|
Revision: 4499
http://mxquery.svn.sourceforge.net/mxquery/?rev=4499&view=rev
Author: etterth
Date: 2011-10-21 20:16:23 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
- Fixed a bug that caused attributes to be returned twice
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-10-21 19:32:27 UTC (rev 4498)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-10-21 20:16:23 UTC (rev 4499)
@@ -97,10 +97,7 @@
public List<Attribute> elementGetAttributes(Element el) {
LinkedList<Attribute> ret = new LinkedList<Attribute>();
- JsArray<Attribute> attrs = nativeElementGetAttributes(el);
- for (int i = 0; i < attrs.length(); i++) {
- ret.add(attrs.get(i));
- }
+
//TODO more input element types
if ("input".equals(el.getLocalName())) {
if ("http://www.w3.org/1999/xhtml".equals(el.getNameSpaceURI())) {
@@ -108,13 +105,15 @@
if ("checkbox".equals(input.getType())
|| "radio".equals(input.getType())) {
el.setAttributeNS("", "checked", Boolean.toString(input.getPropertyBoolean("checked")));
- ret.add((Attribute) el.getAttributeNode("checked"));
} else {
el.setAttributeNS("", "value", input.getValue());
- ret.add((Attribute) el.getAttributeNode("value"));
}
}
}
+ JsArray<Attribute> attrs = nativeElementGetAttributes(el);
+ for (int i = 0; i < attrs.length(); i++) {
+ ret.add(attrs.get(i));
+ }
return ret;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-21 19:32:34
|
Revision: 4498
http://mxquery.svn.sourceforge.net/mxquery/?rev=4498&view=rev
Author: etterth
Date: 2011-10-21 19:32:27 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
- history.html working slowly (except for the history support, need to add some event-handler)
Modified Paths:
--------------
trunk/MXQuery/xqib_samples/history.html
Modified: trunk/MXQuery/xqib_samples/history.html
===================================================================
--- trunk/MXQuery/xqib_samples/history.html 2011-10-21 14:29:46 UTC (rev 4497)
+++ trunk/MXQuery/xqib_samples/history.html 2011-10-21 19:32:27 UTC (rev 4498)
@@ -9,10 +9,10 @@
module namespace h = "http://www.XQIB.org/history";
declare default element namespace "http://www.w3.org/1999/xhtml";
- declare function h:stateChanged($loc, $evtObj){
+ declare updating function h:stateChanged($loc, $evtObj){
h:stateChanged()
};
- declare function h:writeUrl(){
+ declare updating function h:writeUrl(){
let $location := b:getLocation()
let $hashstring := (
let $doc := fn:doc('historysrc.xml')
@@ -27,18 +27,21 @@
b:setHash(if (count($hashstring)) then string-join($hashstring) else '#')
};
- declare function h:stateChanged(){
- h:writeUrl()
+ declare updating function h:stateChanged(){
+ h:writeUrl(),h:recalculate()
+
};
declare updating function h:recalculate(){
let $doc := fn:doc('historysrc.xml')
let $filteredcategories := for $featuregroup in $doc/*:store/*:feature-groups/*:feature-group
- where b:dom()//input[@groupid = $featuregroup/@groupid and @checked]
- return $featuregroup/@groupid/string-value
- return replace node b:dom()//id('results') with <div id='results'>{
+ where b:dom()//input[@groupid = $featuregroup/@groupid and @checked = 'true']
+ return data($featuregroup/@groupid)
+ return (replace node b:dom()//id('results') with <div id='results'>{
for $product in $doc/*:store/*:product
-
+ where not((for $feature in $product/*:feature
+return if (b:dom()//input[@groupid = $feature/@groupid and $feature/@value = @groupvalue]/@checked = 'true') then 1 else (if (not ($filteredcategories=$feature/@groupid)) then 1 else 0)
+)=0)
return
<div class=''>
<div>{
@@ -48,7 +51,8 @@
}</div>
}</div>
</div>
- }</div>
+ }</div>,replace node b:dom()//id('debug') with <div id='debug'>{
+ string-join($filteredcategories,',')}</div>)
};
declare updating function h:readUrl(){
@@ -85,15 +89,20 @@
h:readUrl();
h:writeUrl();
h:stateChanged();
- h:recalculate();
</script>
+<script type="application/xquery" >
+ import module namespace h = "http://www.XQIB.org/history";
+
+ h:recalculate()
+ </script>
<script type="text/javascript" >
</script>
</head>
<body>
<div id="results"><p>random content</p><p/></div>
+<div id="debug"/>
<a href="javascript:document.location.hash='#2=1024x764=croeu#1=15"=10"';document.location.reload()">test-link</a>
</body>
</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-21 14:29:52
|
Revision: 4497
http://mxquery.svn.sourceforge.net/mxquery/?rev=4497&view=rev
Author: etterth
Date: 2011-10-21 14:29:46 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
- Updated history.html (hash synchronization with checkboxes is now working)
- Fixed a bug in fn:doc (reset was faulty)
- The mapping from DOM input element properties to attributes should now be more complete
Modified Paths:
--------------
trunk/MXQuery/xqib_samples/history.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Doc.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java
Modified: trunk/MXQuery/xqib_samples/history.html
===================================================================
--- trunk/MXQuery/xqib_samples/history.html 2011-10-21 07:09:22 UTC (rev 4496)
+++ trunk/MXQuery/xqib_samples/history.html 2011-10-21 14:29:46 UTC (rev 4497)
@@ -17,18 +17,18 @@
let $hashstring := (
let $doc := fn:doc('historysrc.xml')
let $newhash := '#'
- for $activefeature in b:dom()//input[@type=checkbox and @checked=true]
+ for $activefeature in b:dom()//input[@type='checkbox' and @checked='true']
let $activated := $activefeature/@groupid
group by $activated
return
- '#eouoeuoeu'
+ concat('#', $activated, '=', string-join($activefeature/following-sibling::text(), '='))
)
return
- b:setHash(if ($hashstring) then $hashstring else '#')
+ b:setHash(if (count($hashstring)) then string-join($hashstring) else '#')
};
declare function h:stateChanged(){
- 1
+ h:writeUrl()
};
declare updating function h:recalculate(){
@@ -38,11 +38,16 @@
return $featuregroup/@groupid/string-value
return replace node b:dom()//id('results') with <div id='results'>{
for $product in $doc/*:store/*:product
- where $product
+
return
- <div class=''>{
- 1
- }</div>
+ <div class=''>
+ <div>{
+ data($product/@name),
+ <div>{
+ 1
+ }</div>
+ }</div>
+ </div>
}</div>
};
@@ -59,7 +64,7 @@
let $checkbox := b:dom()//input[b:getClasses(.)='categorycheckbox' and @groupvalue = $value ]
where $checkbox
return
- replace value of node $checkbox/@checked with 'true'
+ insert node attribute checked { 'true' } into $checkbox
@@ -69,18 +74,19 @@
import module namespace h = "http://www.XQIB.org/history";
declare variable $doc := fn:doc('historysrc.xml');
- block {
for $featuregroup in $doc/*:store/*:feature-groups/*:feature-group
return insert node <div>{data($featuregroup/@name)}{
for $value in fn:distinct-values($doc/*:store/*:product/*:feature[@groupid = $featuregroup/@groupid]/@value)
return
- <div><input type="checkbox" class="categorycheckbox" groupvalue="{$value}" checked="no">{$featuregroup/@groupid}</input>{$value}</div>
+ <div><input type="checkbox" class="categorycheckbox" groupvalue="{$value}" >{$featuregroup/@groupid}</input>{$value}</div>
}</div> as first into b:dom()//body;
+ for $cb in b:dom()//input[@type='checkbox']
+ return b:addEventListener($cb, 'click', h:stateChanged#2);
h:readUrl();
- (:h:writeUrl();:)
+ h:writeUrl();
h:stateChanged();
h:recalculate();
-}
+
</script>
<script type="text/javascript" >
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Doc.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Doc.java 2011-10-21 07:09:22 UTC (rev 4496)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Doc.java 2011-10-21 14:29:46 UTC (rev 4497)
@@ -162,10 +162,13 @@
public void setReturnType(int type) throws MXQueryException {
}
+
@Override
protected void resetImpl() throws MXQueryException {
- if (baseIterator != null)
+ if (baseIterator != null) {
+ baseIterator.setResettable(true);
baseIterator.reset();
+ }
}
public String getSystemID() {
if (current != null)
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-10-21 07:09:22 UTC (rev 4496)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-10-21 14:29:46 UTC (rev 4497)
@@ -6,6 +6,7 @@
import java.util.List;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.dom.client.InputElement;
@@ -61,12 +62,13 @@
// elementattributes.get(attr.getLocalName()));
//
// }
+ //TODO more input element types
if ("input".equals(ownername)) {
String attrname = attr.getNodeName();
if ("value".equals(attrname)) {
return ((InputElement) owner.getAsGwtNode()).getValue();
} else if ("checked".equals(attrname)) {
- return nativeInputGetChecked(owner);
+ return Boolean.toString(((InputElement) owner.getAsGwtNode()).isChecked());
}
}
}
@@ -76,13 +78,6 @@
// }
}
- protected native String nativeInputGetChecked(Element input)/*-{
- return input.checked
- }-*/;
- // protected native String getSpecialAttributeValue(Element owner,
- // String string) /*-{
- // return eval(attr + '.' + string);
- // }-*/;
protected native String nativeNodeGetValue(Node node)/*-{
return node.nodeValue;
@@ -106,6 +101,20 @@
for (int i = 0; i < attrs.length(); i++) {
ret.add(attrs.get(i));
}
+ //TODO more input element types
+ if ("input".equals(el.getLocalName())) {
+ if ("http://www.w3.org/1999/xhtml".equals(el.getNameSpaceURI())) {
+ InputElement input = (InputElement)(JavaScriptObject)el;
+ if ("checkbox".equals(input.getType())
+ || "radio".equals(input.getType())) {
+ el.setAttributeNS("", "checked", Boolean.toString(input.getPropertyBoolean("checked")));
+ ret.add((Attribute) el.getAttributeNode("checked"));
+ } else {
+ el.setAttributeNS("", "value", input.getValue());
+ ret.add((Attribute) el.getAttributeNode("value"));
+ }
+ }
+ }
return ret;
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java 2011-10-21 07:09:22 UTC (rev 4496)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java 2011-10-21 14:29:46 UTC (rev 4497)
@@ -36,9 +36,13 @@
if ("input".equals(this.getLocalName())) {
InputElement el = (InputElement) this.getAsGwtElement();
if ("value".equals(localName)) {
+ DOMImpl.impl.elementSetAttributeNS(this, namespace, localName, value);
el.setValue(value);
+ return;
} else if ("checked".equals(localName)) {
+ DOMImpl.impl.elementSetAttributeNS(this, namespace, localName, value);
el.setChecked("true".equals(value));
+ return;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-21 07:09:28
|
Revision: 4496
http://mxquery.svn.sourceforge.net/mxquery/?rev=4496&view=rev
Author: etterth
Date: 2011-10-21 07:09:22 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
- Fixed a bug when inserting newly constructed attributes
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeStore.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeStore.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeStore.java 2011-10-20 20:00:53 UTC (rev 4495)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeStore.java 2011-10-21 07:09:22 UTC (rev 4496)
@@ -323,9 +323,16 @@
current = current.getNext();
}
while (current != null && !Type.isEndType(current.getToken().getEventType())){
- AttributeNodeToken attr = (AttributeNodeToken) current.getToken();
+
+ final TokenInterface attrtok = current.getToken();
+ if (attrtok instanceof AttributeNodeToken) {
+ AttributeNodeToken attr = (AttributeNodeToken) attrtok;
el.setAttributeNS(attr.getNS(), attr.getLocal(), attr.getValueAsString());
- current = current.getNext();
+ }
+ else {
+ el.setAttributeNS(attrtok.getNS(), attrtok.getLocal(), attrtok.getValueAsString());
+ }
+ current = current.getNext();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-20 20:00:59
|
Revision: 4495
http://mxquery.svn.sourceforge.net/mxquery/?rev=4495&view=rev
Author: etterth
Date: 2011-10-20 20:00:53 +0000 (Thu, 20 Oct 2011)
Log Message:
-----------
- Fixed another bug in memory (used ancestor:: with predicate instead of parent -> axes rule)
Modified Paths:
--------------
trunk/MXQuery/xqib_samples/prague/memory.htm
Modified: trunk/MXQuery/xqib_samples/prague/memory.htm
===================================================================
--- trunk/MXQuery/xqib_samples/prague/memory.htm 2011-10-20 19:17:48 UTC (rev 4494)
+++ trunk/MXQuery/xqib_samples/prague/memory.htm 2011-10-20 20:00:53 UTC (rev 4495)
@@ -89,7 +89,7 @@
return
(if (count($opendivs) < 2) then
if (b:getClasses($loc) ='found') then () else
- b:addClass($loc/.., 'open')
+ b:addClass($loc/ancestor::div[b:getClasses(.)='panel'], 'open')
else ()
,
m:testwin())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-20 19:17:54
|
Revision: 4494
http://mxquery.svn.sourceforge.net/mxquery/?rev=4494&view=rev
Author: etterth
Date: 2011-10-20 19:17:48 +0000 (Thu, 20 Oct 2011)
Log Message:
-----------
- Fixed memory
- Removed dependence of NodeStoreIterator on Window -> removed a bug that prevented fixing the memory
Modified Paths:
--------------
trunk/MXQuery/xqib_samples/prague/memory.htm
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/NodeStoreIterator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
Modified: trunk/MXQuery/xqib_samples/prague/memory.htm
===================================================================
--- trunk/MXQuery/xqib_samples/prague/memory.htm 2011-10-19 23:51:52 UTC (rev 4493)
+++ trunk/MXQuery/xqib_samples/prague/memory.htm 2011-10-20 19:17:48 UTC (rev 4494)
@@ -89,7 +89,7 @@
return
(if (count($opendivs) < 2) then
if (b:getClasses($loc) ='found') then () else
- b:addClass($loc, 'open')
+ b:addClass($loc/.., 'open')
else ()
,
m:testwin())
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/NodeStoreIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/NodeStoreIterator.java 2011-10-19 23:51:52 UTC (rev 4493)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/NodeStoreIterator.java 2011-10-20 19:17:48 UTC (rev 4494)
@@ -26,15 +26,15 @@
import ch.ethz.mxquery.util.browser.dom.Element;
import ch.ethz.mxquery.util.browser.dom.Node;
-public class NodeStoreIterator extends Window {
+public class NodeStoreIterator extends Iterator {
protected Node store;
protected NodeToken current;
int attributeindex;
public NodeStoreIterator(Node store) {
- super();
- this.store = (Node)(Object)store;
+ super(null, null);
+ this.store = store;
}
public AttributeNodeToken getAttributeAt(Node node,int index){
@@ -138,122 +138,5 @@
called = 0;
}
- @Override
- public boolean hasItem(int position) throws MXQueryException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public XDMIterator getItem(int position) throws MXQueryException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean hasNextItem() throws MXQueryException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public XDMIterator nextItem() throws MXQueryException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Window getNewItemWindow(IntegerList values) throws MXQueryException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Window getNewWindow(int startPosition, int endPosition)
- throws MXQueryException {
- if (startPosition == 1
- && endPosition == Window.END_OF_STREAM_POSITION) {
- Window ret = new NodeStoreIterator(store);
- ret.setContext(context,false);
- return ret;
- } else {
- throw new MXQueryException("dont use window with integer parameters", "", null);
- }
- }
-
- @Override
- public int getStartNode() throws MXQueryException {
- // TODO Auto-generated method stub
- return 0;
- }
-
-
- public Window getNewWindow(int startPosition,
- int endPosition, long openTime, long closeTime) throws MXQueryException {
- //TODO: Add implementation
- return null;
- }
-
-
- public Window getNewWindow(int startPosition,
- int endPosition, long openTime, long closeTime, Object queryId) throws MXQueryException{
- //TODO: Add implementation
- return null;
- }
-
-
-
- public Window getEmptyWindow() throws MXQueryException{
- //TODO: Add implementation
- return null;
- }
-
- @Override
- public void destroyWindow() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean equals(Object other) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public int getWindowId() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- protected int getNodeId() throws MXQueryException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public boolean isWindowInUse() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void setWindowInUse(boolean windowInUse) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public int getPosition() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public Source getStore() {
- // TODO Auto-generated method stub
- return null;
- }
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java 2011-10-19 23:51:52 UTC (rev 4493)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java 2011-10-20 19:17:48 UTC (rev 4494)
@@ -50,18 +50,6 @@
}
- @Override
- public Window getNewWindow(int startPosition, int endPosition)
- throws MXQueryException {
- if (startPosition == 1
- && endPosition == Window.END_OF_STREAM_POSITION) {
- Window ret = new SingleNodeIterator(store);
- ret.setContext(context,false);
- return ret;
- } else {
- throw new MXQueryException("dont use window with integer parameters", "", null);
- }
- }
@Override
protected XDMIterator copy(Context context, XDMIterator[] subIters,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-19 23:51:58
|
Revision: 4493
http://mxquery.svn.sourceforge.net/mxquery/?rev=4493&view=rev
Author: etterth
Date: 2011-10-19 23:51:52 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
- added the functions b:preventDefault() and b:stopPropagation()
- added overloads for capturing in b:addEventListener()
- added a test for capturing and b:stopPropagation
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/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java
Added Paths:
-----------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -126,7 +126,7 @@
JavaScriptObject handler = createHandler(fi);
- nativeAddEventListener(el, eventName, handler, false);
+ nativeAddEventListener(el, eventName, handler, captures);
lst.add(new FunctionItemAndHandler(fi, handler,captures));
}
@@ -314,9 +314,6 @@
e.printStackTrace();
}
// }
- // TODO decide this dynamically
- event.stopPropagation();
- event.preventDefault();
}
/**
* the callback called by any listened window event
@@ -566,6 +563,14 @@
return false;
}
+ public static void stopPropagation() {
+ current_event.stopPropagation();
+ }
+
+ public static void preventDefault() {
+ current_event.preventDefault();
+ }
+
}
class NodeAndEventName {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-10-19 23:51:52 UTC (rev 4493)
@@ -237,10 +237,12 @@
</parameters>
<className>RemoveAnonymousEventListener</className>
</functionDescription>
+<!-- dom -->
<functionDescription>
<functionName>dom</functionName>
<className>Dom</className>
</functionDescription>
+<!-- windowinfo -->
<functionDescription>
<functionName>windowInfo</functionName>
<className>WindowInfo</className>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -43,6 +43,7 @@
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 node__ = new TypeInfo(FunctionGallery.getType("node()",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
+ TypeInfo xs_boolean = new TypeInfo(FunctionGallery.getType("xs:boolean",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);
TypeInfo xs_date_quest = new TypeInfo(FunctionGallery.getType("xs:date?",ctx), Type.OCCURRENCE_IND_ZERO_OR_ONE,null);
@@ -694,6 +695,30 @@
qn = new QName(
"http://xqib.org",
"b",
+ "addEventListener");
+ paramTypes = new TypeInfo[4];
+
+ paramTypes[0] = node___plus;
+ paramTypes[1] = xs_string;
+ paramTypes[2] = function__;
+ paramTypes[3] = xs_boolean;
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.AddEventListener iter = new ch.ethz.mxquery.functions.b.AddEventListener();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"removeEventListener");
paramTypes = new TypeInfo[3];
@@ -717,6 +742,30 @@
qn = new QName(
"http://xqib.org",
"b",
+ "removeEventListener");
+ paramTypes = new TypeInfo[4];
+
+ paramTypes[0] = node__;
+ paramTypes[1] = xs_string;
+ paramTypes[2] = function__;
+ paramTypes[3] = xs_boolean;
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.RemoveEventListener iter = new ch.ethz.mxquery.functions.b.RemoveEventListener();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"removeAnonymousEventListeners");
paramTypes = new TypeInfo[2];
@@ -739,6 +788,46 @@
qn = new QName(
"http://xqib.org",
"b",
+ "preventDefault");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.PreventDefault iter = new ch.ethz.mxquery.functions.b.PreventDefault();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "stopPropagation");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.StopPropagation iter = new ch.ethz.mxquery.functions.b.StopPropagation();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"dom");
paramTypes = new TypeInfo[0];
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -0,0 +1,34 @@
+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.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class PreventDefault extends Iterator {
+
+ public PreventDefault() {
+ super(null,null);
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ Environment.preventDefault();
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ PreventDefault copy = new PreventDefault();
+ copy.setContext(context, true);
+ return copy;
+ }
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -0,0 +1,35 @@
+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.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.EmptySequenceIterator;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class StopPropagation extends Iterator {
+
+ public StopPropagation() {
+ super(null,null);
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ Environment.stopPropagation();
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ StopPropagation copy = new StopPropagation();
+ copy.setContext(context, true);
+ return copy;
+ }
+
+}
Modified: trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java
===================================================================
--- trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -35,6 +35,34 @@
@Test
/**
+ * test the b:addEventListener with capturing and stopPropagation
+ */
+ public void event_add_listener_stopPropagation() throws Exception {
+ driver.get(executionpath + "/test/test.html");
+ executeNewScript("insert node <div id='b1_parent'><div id='b1' type='button'>text</div></div> as first into b:dom()//body");
+ executeNewScript("declare updating function local:onclick($loc, $evtObj) {\n" +
+ " insert node <p name='b1_fired'/> as last into b:dom()//body\n" +
+ "};\n" +
+ "b:addEventListener(b:dom()/id('b1'), \"onclick\", local:onclick#2, true())");
+ executeNewScript("declare updating function local:onclick($loc, $evtObj) {\n" +
+ " insert node <p name='parent_fired'/> as last into b:dom()//body\n" +
+ ", b:stopPropagation()\n" +
+ "};\n" +
+ "b:addEventListener(b:dom()/id('b1_parent'), \"onclick\", local:onclick#2, true())");
+
+ WebElement button = driver.findElementById("b1");
+ button.click();
+ button.click();
+
+ //if the capture fails, 4 are added
+ Assert.assertEquals(2,driver.findElementsByTagName("p").size());
+ //if the capture is correct, all elements created are from the parent
+ Assert.assertEquals(2,driver.findElementsByName("parent_fired").size());
+ }
+
+
+ @Test
+ /**
* test b:removeEventListener
* the click should only trigger an insert once
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-19 12:37:31
|
Revision: 4492
http://mxquery.svn.sourceforge.net/mxquery/?rev=4492&view=rev
Author: etterth
Date: 2011-10-19 12:37:25 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
- Changed event system to allow for event capturing/bubbling control
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-10-19 10:54:16 UTC (rev 4491)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-10-19 12:37:25 UTC (rev 4492)
@@ -44,12 +44,13 @@
public class Environment {
- static Hashtable<NodeAndEventName, List<FunctionItemToken>> handlers;
+ static Hashtable<NodeAndEventName, List<FunctionItemAndHandler>> handlers;
static Hashtable<String, Context> modules = new Hashtable<String, Context>();
static Context modCtx = new Context();
static CompilerOptions co;
static int contextcounter = 0;
private static Hashtable<String, List<FunctionItemToken>> windowhandlers;
+ private static NativeEvent current_event;
public static CompilerOptions getCompilerOptions() {
if (co != null)
@@ -109,26 +110,33 @@
}
public static void addEventListener(Element el, String eventName,
- FunctionItemToken fi, Context ctx) {
+ FunctionItemToken fi, Context ctx, boolean captures) {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
if (handlers == null)
- handlers = new Hashtable<NodeAndEventName, List<FunctionItemToken>>();
+ handlers = new Hashtable<NodeAndEventName, List<FunctionItemAndHandler>>();
NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<FunctionItemToken> lst = handlers.get(test);
+ List<FunctionItemAndHandler> lst = handlers.get(test);
if (lst == null) {
- lst = new ArrayList<FunctionItemToken>();
+ lst = new ArrayList<FunctionItemAndHandler>();
handlers.put(test, lst);
}
- lst.add(fi);
-
-
- nativeAddEventListener(el, eventName);
+ JavaScriptObject handler = createHandler(fi);
+
+ nativeAddEventListener(el, eventName, handler, false);
+ lst.add(new FunctionItemAndHandler(fi, handler,captures));
}
-
+
+ private static native JavaScriptObject createHandler(FunctionItemToken fi) /*-{
+ ret = function(ev) {
+ @ch.ethz.mxqjs.client.Environment::eventCallback(Lcom/google/gwt/dom/client/NativeEvent;Lch/ethz/mxquery/datamodel/xdm/FunctionItemToken;)(ev,fi);
+ };
+ return ret;
+ }-*/;
+
public static void addWindowListener(String eventName,
FunctionItemToken fi, Context ctx) {
if (eventName.startsWith("on"))
@@ -154,39 +162,42 @@
}-*/;
public static void removeEventListener(Element el, String eventName,
- FunctionItemToken fi, Context ctx) throws MXQueryException {
+ FunctionItemToken fi, Context ctx, boolean capture) throws MXQueryException {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
if (handlers == null)
throw new MXQueryException("Eventlistener cannot be removed",
"handler to remove cannot be found", null);
-
- NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<FunctionItemToken> lst = handlers.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);
- }
- handlers.remove(test);
- handlers.put(test, lstnew);
- if (lst.isEmpty()) {
- handlers.put(test, null);
- nativeRemoveEventListener(el, eventName);
- }
+ NodeAndEventName test = new NodeAndEventName(el, eventName);
+ List<FunctionItemAndHandler> lst = handlers.get(test);
+ if (lst == null) {
+ throw new MXQueryException("Eventlistener cannot be removed",
+ "handler to remove cannot be found", null);
+ }
+ ArrayList<FunctionItemAndHandler> lstnew = new ArrayList<FunctionItemAndHandler>();
+ ListIterator<FunctionItemAndHandler> it = lst.listIterator();
-
+ while (it.hasNext()) {
+ FunctionItemAndHandler ft = it.next();
+ FunctionSignature fts = ft.fi.getFunction().getFunctionSignature();
+ FunctionSignature fis = fi.getFunction().getFunctionSignature();
+ if (!fis.getName().equals(fts.getName())
+ || (ft.captures != capture)
+ || fts.getArity() != fis.getArity())
+ lstnew.add(ft);
+ else {// match
+ nativeRemoveEventListener(el, eventName, ft.handler, ft.captures);
+ }
+ }
+ handlers.remove(test);
+ handlers.put(test, lstnew);
+ if (lst.isEmpty()) {
+ handlers.put(test, null);
+ }
+
+
}
public static void removeWindowListener(String eventName,
@@ -233,25 +244,27 @@
throw new MXQueryException("Eventlistener cannot be removed",
"handler to remove cannot be found", null);
NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<FunctionItemToken> lst = handlers.get(test);
+ List<FunctionItemAndHandler> lst = handlers.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>();
+ List<FunctionItemAndHandler> lstnew = new ArrayList<FunctionItemAndHandler>();
- ListIterator<FunctionItemToken> it = lst.listIterator();
+ ListIterator<FunctionItemAndHandler> it = lst.listIterator();
while (it.hasNext()) {
- FunctionItemToken fi = it.next();
- if (fi.getFunction().getFunctionSignature().getName() != null)
+ FunctionItemAndHandler fi = it.next();
+ if (fi.fi.getFunction().getFunctionSignature().getName() != null)
lstnew.add(fi);
+ else {// match
+ nativeRemoveEventListener(el, eventName, fi.handler, fi.captures);
+ }
}
handlers.remove(test);
handlers.put(test, lstnew);
if (lst.isEmpty()) {
handlers.put(test, null);
- nativeRemoveEventListener(el, eventName);
}
}
@@ -260,16 +273,17 @@
*
* @param event
*/
- public static void eventCallback(NativeEvent event) {
+ public static void eventCallback(NativeEvent event, FunctionItemToken fi) {
// TODO add arity
+ current_event = event;
Logger log = Logger.getLogger(Environment.class.toString());
log.log(LogLevel.FINER, "Got an event: " + event.getString());
NodeAndEventName test = new NodeAndEventName(event);
- while (test.node.getParentElement() != null
- && handlers.get(test) == null) {
- test.node = test.node.getParentElement();
- }
- for (FunctionItemToken fi : handlers.get(test)) {
+// while (test.node.getParentElement() != null
+// && handlers.get(test) == null) {
+// test.node = test.node.getParentElement();
+// }
+// for (FunctionItemToken fi : handlers.get(test)) {
Iterator nodeiter;
if (JsToMxQuery.isNode(test.node)) {
@@ -299,7 +313,7 @@
true);
e.printStackTrace();
}
- }
+// }
// TODO decide this dynamically
event.stopPropagation();
event.preventDefault();
@@ -310,6 +324,7 @@
* @param event
*/
public static void windowEventCallback(NativeEvent event) {
+ current_event = event;
// TODO add arity
Logger log = Logger.getLogger(Environment.class.toString());
log.log(LogLevel.FINER, "Got a window event: " + event.getString());
@@ -446,9 +461,9 @@
// }
// }
private static final native void nativeAddEventListener(
- Element el, String eventName)/*-{
+ Element el, String eventName,JavaScriptObject handler, boolean capture)/*-{
// 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);
+ el.addEventListener(eventName, handler, capture);
}-*/;
@@ -459,10 +474,12 @@
}-*/;
+ //TODO change signature (handler)
private static final native void nativeRemoveEventListener(Element el,
- String eventName)/*-{
+ String eventName, JavaScriptObject handler, boolean capture)/*-{
// 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);
+ //TODO el.removeEventListener(eventName, @ch.ethz.mxqjs.client.Environment::eventCallback(Lcom/google/gwt/dom/client/NativeEvent;), false);
+ el.removeEventListener(eventName, handler, capture);
}-*/;
@@ -545,6 +562,10 @@
}-*/;
+ public static boolean getDefaultCapture() {
+ return false;
+ }
+
}
class NodeAndEventName {
@@ -582,3 +603,14 @@
String eventName;
}
+
+class FunctionItemAndHandler{
+ public FunctionItemAndHandler(FunctionItemToken fi, JavaScriptObject handler, boolean captures) {
+ this.fi = fi;
+ this.handler = handler;
+ this.captures = captures;
+ }
+ public FunctionItemToken fi;
+ public JavaScriptObject handler;
+ public boolean captures;
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java 2011-10-19 10:54:16 UTC (rev 4491)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java 2011-10-19 12:37:25 UTC (rev 4492)
@@ -33,6 +33,12 @@
eventname = getStringValue(subIters[1]);
XDMIterator functioniter = subIters[2];
+ boolean capture = Environment.getDefaultCapture();
+ if (subIters.length>= 4) {
+ XDMIterator captureiter = subIters[3];
+ TokenInterface capturetoken = captureiter.next();
+ capture = capturetoken.getBoolean();
+ }
TokenInterface functiontoken = functioniter.next();
if (functiontoken.getEventType() != Type.FUNCTION_ITEM || functioniter.next().getEventType() != Type.END_SEQUENCE)
@@ -67,12 +73,12 @@
}
} while (type != Type.END_SEQUENCE);
for (TokenInterface token:tokens){
- addEventHandler(token, eventname, (FunctionItemToken)functiontoken);
+ addEventHandler(token, eventname, (FunctionItemToken)functiontoken, capture);
}
}
private void addEventHandler(TokenInterface tok, String eventname,
- FunctionItemToken fi) throws MXQueryException {
+ FunctionItemToken fi, boolean capture) throws MXQueryException {
if (!(tok instanceof ElementNodeToken)){
return;
}
@@ -86,7 +92,7 @@
// throw new MXQueryException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
// "function not available in addEventListener", getLoc());
//}
- Environment.addEventListener(el, eventname, fi,ctx);
+ Environment.addEventListener(el, eventname, fi,ctx, capture);
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java 2011-10-19 10:54:16 UTC (rev 4491)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java 2011-10-19 12:37:25 UTC (rev 4492)
@@ -36,6 +36,13 @@
if (functiontoken.getEventType() != Type.FUNCTION_ITEM && subIters[2].next().getEventType() != Type.END_SEQUENCE)
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Function Item expected", loc);
+ boolean capture = Environment.getDefaultCapture();
+ if (subIters.length>= 4) {
+ XDMIterator captureiter = subIters[3];
+ TokenInterface capturetoken = captureiter.next();
+ capture = capturetoken.getBoolean();
+ }
+
FunctionItemToken ft = (FunctionItemToken)functiontoken;
if (ft.getFunction().getFunctionSignature().getName() == null)
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Cannot remove anonymous functions individually", loc);
@@ -63,12 +70,12 @@
}
} while (type != Type.END_SEQUENCE);
for (TokenInterface token:tokens){
- removeEventHandler(token, eventname, ft);
+ removeEventHandler(token, eventname, ft, capture);
}
}
private void removeEventHandler(TokenInterface tok, String eventname,
- FunctionItemToken fi) throws MXQueryException {
+ FunctionItemToken fi, boolean capture) throws MXQueryException {
if (!(tok instanceof ElementNodeToken)){
return;
}
@@ -78,7 +85,7 @@
//resolve functionname
// qfunctionname.setNamespaceURI(this.getContext().getNamespace(qfunctionname.getNamespacePrefix()).getURI());
Context ctx = this.getContext().getParent();//Environment.getContext();
- Environment.removeEventListener(el, eventname, fi, ctx);
+ Environment.removeEventListener(el, eventname, fi, ctx, capture);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-19 10:54:23
|
Revision: 4491
http://mxquery.svn.sourceforge.net/mxquery/?rev=4491&view=rev
Author: etterth
Date: 2011-10-19 10:54:16 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
- Added expath read tests
Modified Paths:
--------------
trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/Expath.java
Modified: trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/Expath.java
===================================================================
--- trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/Expath.java 2011-10-18 10:37:59 UTC (rev 4490)
+++ trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/Expath.java 2011-10-19 10:54:16 UTC (rev 4491)
@@ -29,7 +29,7 @@
@Test
/**
- * test the expath send-request() function
+ * test the expath async-request() function
*/
public void async_send_request_success() throws Exception {
driver.get(executionpath + "/test/test.html");
@@ -41,8 +41,37 @@
value = driver.findElementById("result").getText();
Assert.assertEquals("Zurich", value);
}
+
+ @Test
+ /**
+ * test the expath read() function
+ */
+ public void sync_read_success() throws Exception {
+ driver.get(executionpath + "/test/test.html");
+ String value = executeNewScript(" import module namespace http-client = \"http://expath.org/ns/http-client\";" +
+ "http-client:read(\n" +
+ " \"forecast2.xml\"\n" +
+ " )[2]/*:forecast/*:city[1]/data(@*:name)");
+
+ Assert.assertEquals("Zurich", value);
+ }
+ @Test
+ /**
+ * test the expath async-read() function
+ */
+ public void async_read_success() throws Exception {
+ driver.get(executionpath + "/test/test.html");
+ String value = executeNewScript(" import module namespace http-client = \"http://expath.org/ns/http-client\";" +
+ "http-client:async-read(\"forecast2.xml\" ,\n" +
+ " %updating function($result){insert node <div id=\"result\">{$result[2]/*:forecast/*:city[1]/data(@*:name)}</div> as last into b:dom()//body}\n" +
+ " )");
+ Thread.sleep(3000);
+ value = driver.findElementById("result").getText();
+ Assert.assertEquals("Zurich", value);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-10-18 10:38:09
|
Revision: 4490
http://mxquery.svn.sourceforge.net/mxquery/?rev=4490&view=rev
Author: etterth
Date: 2011-10-18 10:37:59 +0000 (Tue, 18 Oct 2011)
Log Message:
-----------
- url tests now also test the history
Modified Paths:
--------------
trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/UrlManipulation.java
Modified: trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/UrlManipulation.java
===================================================================
--- trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/UrlManipulation.java 2011-10-17 22:18:38 UTC (rev 4489)
+++ trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/UrlManipulation.java 2011-10-18 10:37:59 UTC (rev 4490)
@@ -32,9 +32,11 @@
String newurl = executionpath + "/test/test.html#some_stuff";
String value = executeNewScript("b:setHref('" + newurl + "')");
Assert.assertEquals(newurl, driver.getCurrentUrl());
+ driver.navigate().back();
+ Assert.assertEquals(executionpath + "/test/test.html", driver.getCurrentUrl());
}
-
+
@Test
/**
* test the b:setHash function
@@ -47,6 +49,8 @@
Assert.assertEquals(newurl, driver.getCurrentUrl());
String state = (String) driver.executeScript("return window.stateHasToStay;", new Object[0]);
Assert.assertEquals("state stays", state);
+ driver.navigate().back();
+ Assert.assertEquals(executionpath + "/test/test.html", driver.getCurrentUrl());
}
@Test
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|