|
From: <pm_...@us...> - 2011-05-17 10:21:14
|
Revision: 4350
http://mxquery.svn.sourceforge.net/mxquery/?rev=4350&view=rev
Author: pm_fischer
Date: 2011-05-17 10:21:05 +0000 (Tue, 17 May 2011)
Log Message:
-----------
refactoring/simplification of string parameter handling
Modified Paths:
--------------
trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/IRItoURI.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/LowerCase.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Matches.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Namespace_uri_for_prefix.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeSpace.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Parse.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Replace.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/ResolveQName.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringJoin.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/String_Length.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Tokenize.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Trace.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/UpperCase.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ComputedPIConstrIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
trunk/MXQuery/src/ch/ethz/mxquery/util/Utils.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/IRItoURI.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Matches.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Replace.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Tokenize.java
Modified: trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java
===================================================================
--- trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -146,7 +146,7 @@
break;
case TRANSMATH_ATAN2:
MXQueryDouble y = null;
- XDMIterator input2 = subIters[0];
+ XDMIterator input2 = subIters[1];
TokenInterface inputToken2 = input2.next();
int type2 = Type.getEventTypeSubstituted(inputToken2.getEventType(), Context.getDictionary());
@@ -155,16 +155,16 @@
currentToken = Token.END_SEQUENCE_TOKEN;
return;
case Type.INTEGER:
- y = new MXQueryDouble(inputToken.getLong());
+ y = new MXQueryDouble(inputToken2.getLong());
break;
case Type.UNTYPED_ATOMIC:
case Type.UNTYPED:
- y = new MXQueryDouble(inputToken.getText());
+ y = new MXQueryDouble(inputToken2.getText());
break;
case Type.DOUBLE:
case Type.FLOAT:
case Type.DECIMAL:
- y = inputToken.getDouble();
+ y = inputToken2.getDouble();
break;
default:
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -31,25 +31,13 @@
public class Replace extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0],context);
- TokenInterface tok = input.next();
-
- int type = tok.getEventType();
-
- if (type == Type.END_SEQUENCE) {
- currentToken = new TextToken(null,"");
+ String res = getStringValueOrEmpty(subIters[0]);
+ if (res == null){
+ currentToken = new TextToken(null, "");
return;
- }
- if (type != Type.STRING)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+type,loc);
- String res = tok.getText();
- TokenInterface tok1 = subIters[1].next();
-
- String pattern = tok1.getText();
-
- TokenInterface tok2 = subIters[2].next();
-
- String replacement = tok2.getText();
+ }
+ String pattern = getStringValue(subIters[1]);
+ String replacement = getStringValue(subIters[2]);
//currentToken.setText(res.replaceAll(pattern, replacement));
//FIXME: Dummy implementation
currentToken = new TextToken(null,res);
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -36,23 +36,11 @@
String toTranslate = null;
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0],context);
- TokenInterface inputToken =input.next();
- int type = Type.getEventTypeSubstituted( inputToken.getEventType(),null );
-
- switch (type) {
- case(Type.END_SEQUENCE):
- currentToken = new TextToken(null, "");
- break;
- case(Type.STRING):
- case(Type.UNTYPED_ATOMIC):
- case Type.UNTYPED:
- String res = inputToken.getText();
- toTranslate = res;
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type,null),loc);
- }
+ toTranslate = getStringValueOrEmpty(subIters[0]);
+ if (toTranslate==null||toTranslate.equals("")) {
+ currentToken = new TextToken(null, "");
+ return;
+ }
}
public TokenInterface next() throws MXQueryException {
if (called == 0)
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -20,6 +20,7 @@
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.functions.fn.FNString;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.datamodel.types.Type;
@@ -36,40 +37,22 @@
public class String_Length extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input;
- if (subIters != null && subIters.length == 1) {
- input = DataValuesIterator.getDataIterator(subIters[0], context);
- } else {
- VariableHolder contextVarHolder = context.getContextItem();
- if (contextVarHolder != null) {
- input = contextVarHolder.getIter();
- if (input == null) {
- throw new DynamicException(ErrorCodes.E0002_DYNAMIC_NO_VALUE_ASSIGNED, "Context Item Iterator not set", loc);
- } else {
- input = DataValuesIterator.getDataIterator(input, context);
- }
- } else {
- throw new RuntimeException("Context Item not set");
- }
- }
+ XDMIterator input;
+ if (subIters.length > 0 )
+ input = subIters[0];
+ else {
+ input = new FNString();
+ input.setContext(context, false);
+ }
+ String content = getStringValueOrEmpty(input);
+
+ if (content == null){
+ currentToken = new LongToken(Type.INTEGER, null,0);
+ } else {
+ int charCount = content.length();
+ currentToken = new LongToken(Type.INTEGER, null, charCount );
+ }
- TokenInterface inputToken = input.next();
- int type = inputToken.getEventType();
- if (type == Type.START_DOCUMENT) {
- inputToken = input.next();
- type = inputToken.getEventType();
- }
-
- if ( Type.isAttribute(type) )
- type = Type.getAttributeValueType(type);
-
- if ( Type.isAtomicType(type, null) ){
- String content = inputToken.getValueAsString();
- int charCount = content.length();
- currentToken = new LongToken(Type.INTEGER, null, charCount );
- } else if (type == Type.END_SEQUENCE){
- currentToken = new LongToken(Type.INTEGER, null,0);
- }
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -29,16 +29,12 @@
public class SubString extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0], context);
- TokenInterface inputToken = input.next();
- int type = inputToken.getEventType();
+ String res = getStringValueOrEmpty(subIters[0]);
- if (type == Type.END_SEQUENCE) {
+ if (res == null) {
currentToken = new TextToken(null, "");
return;
}
-
- String res = inputToken.getText();
TokenInterface inputToken1 = subIters[1].next();
int type1 = Type.getEventTypeSubstituted(inputToken1.getEventType(), Context.getDictionary());
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -41,34 +41,19 @@
}
private void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0],context);
- TokenInterface tok1 = input.next();
- int type = tok1.getEventType();
- String res = tok1.getText();
- XDMIterator input2 = DataValuesIterator.getDataIterator(subIters[1],context);
- TokenInterface tok2 = input2.next();
- int type2 = tok2.getEventType();
- String delimiter = tok2.getText();
- if (type2 != Type.STRING || delimiter.length() == 0)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type,null),loc);
- switch (type) {
- case(Type.END_SEQUENCE):
+ String res = getStringValueOrEmpty(subIters[0]);
+ String delimiter = getStringValue(subIters[1]);
+ if (delimiter.length() == 0)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Separator must not be empty", loc);
+
+ if (res==null || res.length() == 0)
current = new TokenIterator(context, "", loc);
- break;
-
- case(Type.STRING):
- if (res.length() == 0)
- current = new TokenIterator(context, "",loc);
- else {
- String [] splitted = Utils.split(res,delimiter,true);
- TokenIterator [] toks = new TokenIterator[splitted.length];
- for (int i =0;i<toks.length;i++)
- toks[i] = new TokenIterator(context, splitted[i],loc);
- current = new SequenceIterator(null, toks,loc);
- }
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+type,loc);
+ else {
+ String [] splitted = Utils.split(res,delimiter,true);
+ TokenIterator [] toks = new TokenIterator[splitted.length];
+ for (int i =0;i<toks.length;i++)
+ toks[i] = new TokenIterator(context, splitted[i],loc);
+ current = new SequenceIterator(null, toks,loc);
}
}
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -34,25 +34,16 @@
private Vector remove = new Vector();
protected void init() throws MXQueryException {
- TokenInterface arg = subIters[0].next();
- TokenInterface mapString = subIters[1].next();
- TokenInterface transString = subIters[2].next();
+ String sArg = getStringValueOrEmpty(subIters[0]);
- if (arg.getEventType() == Type.END_SEQUENCE) {
+ if (sArg == null || sArg.equals("")) {
currentToken = new TextToken(null, "");
return;
}
+
+ String sMap = getStringValue(subIters[1]);
+ String sTrans = getStringValue(subIters[2]);
- if (arg.getEventType() != Type.STRING ||
- mapString.getEventType() != Type.STRING ||
- transString.getEventType() != Type.STRING) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:translate!", loc);
- }
-
- String sArg = arg.getText();
- String sMap = mapString.getText();
- String sTrans = transString.getText();
-
int transPos = 0;
for (int i=0; i<sMap.length(); i++) {
int sMapChar = sMap.charAt(i);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -14,8 +14,6 @@
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.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
@@ -26,19 +24,12 @@
public class SignString extends TokenBasedIterator {
protected void init() throws MXQueryException {
- TokenInterface method = subIters[0].next();
- if (method == Token.END_SEQUENCE_TOKEN || !(method.getEventType() == Type.UNTYPED_ATOMIC || Type.isTypeOrSubTypeOf(method.getEventType(), Type.STRING, Context.getDictionary())))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Element of Type String Expected",loc);
- String macMethod = method.getText();
- TokenInterface key = subIters[1].next();
- if (key == Token.END_SEQUENCE_TOKEN || !(key.getEventType() == Type.UNTYPED_ATOMIC || Type.isTypeOrSubTypeOf(key.getEventType(), Type.STRING, Context.getDictionary())))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Element of Type String Expected",loc);
- String keyChars = key.getText();
- TokenInterface content = subIters[2].next();
- if (content == Token.END_SEQUENCE_TOKEN || !(content.getEventType() == Type.UNTYPED_ATOMIC || Type.isTypeOrSubTypeOf(content.getEventType(), Type.STRING, Context.getDictionary())))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Element of Type String Expected",loc);
- String contentChars = content.getText();
+ String macMethod = getStringValue(subIters[0]);
+ String keyChars = getStringValue(subIters[1]);
+
+ String contentChars = getStringValue(subIters[2]);
+
Mac mac;
try {
mac = Mac.getInstance(macMethod);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -241,27 +241,7 @@
if (username!=null && (password==null||authmethod==null))
throw new DynamicException(EHC005_DYNAMIC_INVALID_REQUEST_ELEM, "If username is given, password and method also need to be provided", loc);
if (subIters.length > 1) {
- String urlParam = null;
- TokenInterface urlToken = subIters[1].next();
-
- switch (urlToken.getEventType()) {
- case Type.UNTYPED_ATOMIC:
- urlParam = urlToken.getText();
- break;
- case Type.END_SEQUENCE:
- break;
- default:
- if (Type.isTypeOrSubTypeOf(urlToken.getEventType(), Type.STRING,
- Context.getDictionary()))
- urlParam = urlToken.getText();
- else
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Expected String type for URL", loc);
- break;
- }
- if (urlParam != null)
- url = urlParam;
+ url = getStringValueOrEmpty(subIters[1]);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -148,25 +148,7 @@
private void init() throws MXQueryException {
TokenInterface urlToken = subIters[0].next();
- String url;
- switch (urlToken.getEventType()) {
- case Type.END_SEQUENCE:
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Emtpy sequence not allowed for URL", loc);
- case Type.UNTYPED_ATOMIC:
- url = urlToken.getText();
- break;
- default:
- if (Type.isTypeOrSubTypeOf(urlToken.getEventType(), Type.STRING,
- Context.getDictionary()))
- url = urlToken.getText();
- else
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Expected String type for URL", loc);
- break;
- }
+ String url = getStringValue(subIters[0]);
if (request_type != REQUEST_TYPE_GET && url.indexOf('?') >= 0) {
throw new DynamicException(
ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -29,89 +29,76 @@
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.types.TypeLexicalConstraints;
import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class DocAvailable extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator parameter = subIters[0];
- if (parameter == null) {
- // this should never happen!!!
- throw new IllegalArgumentException("No parameter for fn:doc-available() function given!");
+ String add = getStringValueOrEmpty(subIters[0]);
+
+ if (add == null) {
+ currentToken = BooleanToken.FALSE_TOKEN;
+ return;
}
- TokenInterface tok = parameter.next();
- int type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
+ URI uri;
- if (type == Type.END_SEQUENCE) {
+ if (!TypeLexicalConstraints.isValidURI(add))
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ try {
+ if (TypeLexicalConstraints.isAbsoluteURI(add)) {
+ uri = new URI(add);
+ } else {
+ String base = context.getBaseURI();
+ String add1 = add;
+ if (add1.startsWith("/"))
+ add1 = add1.substring(1);
+ uri = new URI(base + add1);
+ }
+ } catch (URISyntaxException se) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ }
+ if(add.startsWith("http://")){
+
+ URL url;
+ try {
+ url = uri.toURL();
+ } catch (MalformedURLException e) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ }
+ try {
+ InputStream in = url.openStream();
+ in.close();
+ } catch (IOException e) {
currentToken = BooleanToken.FALSE_TOKEN;
return;
+ }
+ currentToken = BooleanToken.TRUE_TOKEN;
+ // }
+ // catch(Exception e){
+ // throw new DynamicException(ErrorCodes.A0006_EC_URI_NOT_FOUND, "Remote Data cannot be accessed: " + e);
+ // }
}
- if (Type.typePromoteableTo(type, Type.STRING,Context.getDictionary()) || type == Type.UNTYPED_ATOMIC) {
- String add=tok.getText();
- URI uri;
-
- if (!TypeLexicalConstraints.isValidURI(add))
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ else {
+ File xml;
+ try {
+ xml = new File(uri);
+ }catch(IllegalArgumentException ia) {
try {
- if (TypeLexicalConstraints.isAbsoluteURI(add)) {
- uri = new URI(add);
- } else {
- String base = context.getBaseURI();
- String add1 = add;
- if (add1.startsWith("/"))
- add1 = add1.substring(1);
- uri = new URI(base + add1);
- }
- } catch (URISyntaxException se) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
- }
- if(add.startsWith("http://")){
-
- URL url;
- try {
- url = uri.toURL();
- } catch (MalformedURLException e) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
- }
- try {
- InputStream in = url.openStream();
- in.close();
- } catch (IOException e) {
- currentToken = BooleanToken.FALSE_TOKEN;
- return;
- }
- currentToken = BooleanToken.TRUE_TOKEN;
-// }
-// catch(Exception e){
-// throw new DynamicException(ErrorCodes.A0006_EC_URI_NOT_FOUND, "Remote Data cannot be accessed: " + e);
-// }
+ xml = new File(add);
+ } catch (IllegalArgumentException ia2) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
}
- else {
- File xml;
- try {
- xml = new File(uri);
- }catch(IllegalArgumentException ia) {
- try {
- xml = new File(add);
- } catch (IllegalArgumentException ia2) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
- }
- }
- if (xml.exists()) {
- currentToken = BooleanToken.TRUE_TOKEN;
- } else {
- currentToken = BooleanToken.FALSE_TOKEN;
- }
- }
- }
- else
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument given to fn:doc-available", loc);
+ }
+ if (xml.exists()) {
+ currentToken = BooleanToken.TRUE_TOKEN;
+ } else {
+ currentToken = BooleanToken.FALSE_TOKEN;
+ }
+ }
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -21,10 +21,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.BitSet;
@@ -44,19 +41,13 @@
}
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface uri = input.next();
+ String uri = getStringValueOrEmpty(subIters[0]);
- if (uri.getEventType() == Type.END_SEQUENCE) {
+ if (uri == null || uri.equals("")) {
currentToken = new TextToken(null, "");
return;
- }
-
- if (!(Type.isTypeOrSubTypeOf(uri.getEventType(), Type.STRING,Context.getDictionary()) || uri.getEventType()==Type.UNTYPED_ATOMIC)) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:encode-for-uri!", loc);
- }
-
- currentToken = new TextToken(null, encode(uri.getText()));
+ }
+ currentToken = new TextToken(null, encode(uri));
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -21,10 +21,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.Utils;
@@ -34,19 +31,13 @@
private int eRange = 126;
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface uri = input.next();
+ String uri = getStringValueOrEmpty(subIters[0]);
- if (uri.getEventType() == Type.END_SEQUENCE) {
+ if (uri == null || uri.equals("")) {
currentToken = new TextToken(null, "");
return;
- }
-
- if (!(Type.isTypeOrSubTypeOf(uri.getEventType(), Type.STRING,Context.getDictionary()) || uri.getEventType()==Type.UNTYPED_ATOMIC)) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:encode-for-uri!", loc);
- }
-
- currentToken = new TextToken(null, encode(uri.getText()));
+ }
+ currentToken = new TextToken(null, encode(uri));
}
private String encode(String input) {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -22,73 +22,31 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.QNameToken;
-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.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class FNQName extends TokenBasedIterator {
protected void init() throws MXQueryException {
- if (subIters[0] == null) {
- throw new IllegalArgumentException();
- }
- XDMIterator paramQNameIt;
- TokenInterface nsToken = subIters[0].next();
- paramQNameIt = subIters[1];
- String nsString = null;
- if (!(nsToken.getText() == null || nsToken.getText().equals("")))
- nsString = nsToken.getText();
- if (!(Type.getEventTypeSubstituted(nsToken.getEventType(), Context
- .getDictionary()) == Type.STRING
- || nsToken.getEventType() == Type.UNTYPED_ATOMIC
- || nsToken.getEventType() == Type.UNTYPED || nsToken
- .getEventType() == Type.END_SEQUENCE))
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Wrong data type for fn:QName", loc);
- TokenInterface paramToken = paramQNameIt.next();
- int type = Type.getEventTypeSubstituted(paramToken.getEventType(),
- Context.getDictionary());
+ String nsString = getStringValueOrEmpty(subIters[0]);
- switch (type) {
- case Type.END_SEQUENCE:
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "QName expected", loc);
- case Type.STRING:
- case Type.UNTYPED_ATOMIC:
- case Type.UNTYPED:
- String qNameText = paramToken.getText();
+ String qNameText = getStringValue(subIters[1]);
+
if (qNameText.equals(""))
throw new DynamicException(
ErrorCodes.F0005_INVALID_LEXICAL_VALUE,
"Empty QName not possible", loc);
QName qToGen = new QName(qNameText);
if (qToGen.getNamespacePrefix() != null
- && (nsToken.getEventType() == Type.END_SEQUENCE || nsToken
- .getText().equals("")))
+ && (nsString == null || nsString.equals("")))
throw new DynamicException(
ErrorCodes.F0005_INVALID_LEXICAL_VALUE,
"Prefix not allow with empty namespace", loc);
qToGen.setNamespaceURI(nsString);
currentToken = new QNameToken(null, qToGen);
- break;
- default:
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Wrong data type for fn:QName", loc);
- }
-
- if (paramQNameIt.next() != Token.END_SEQUENCE_TOKEN)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Could not cast sequence to atomic type "
- + Type.getTypeQName(Type.QNAME, Context
- .getDictionary()), loc);
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/IRItoURI.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/IRItoURI.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/IRItoURI.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -22,11 +22,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.Utils;
@@ -50,22 +46,14 @@
}
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface iri = input.next();
+ String iri = getStringValueOrEmpty(subIters[0]);
- if (iri.getEventType() == Type.END_SEQUENCE) {
+ if (iri == null || iri.equals("")) {
currentToken = new TextToken(null, "");
return;
}
-
- if (input.next() != Token.END_SEQUENCE_TOKEN)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Expected single value, encountered multiple",loc);
-
- if (!(iri.getEventType()==Type.UNTYPED_ATOMIC || Type.typePromoteableTo(iri.getEventType(), Type.STRING, Context.getDictionary()))) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:encode-for-uri!", loc);
- }
-
- currentToken = new TextToken(null, encode(iri.getText()));
+
+ currentToken = new TextToken(null, encode(iri));
}
private String encode(String input) {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/LowerCase.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/LowerCase.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/LowerCase.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -20,33 +20,19 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class LowerCase extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface inputToken =input.next();
- int type = Type.getEventTypeSubstituted( inputToken.getEventType(), Context.getDictionary() );
-
- switch (type) {
- case(Type.END_SEQUENCE):
- currentToken = new TextToken(null, "");
- break;
- case(Type.STRING):
- case(Type.UNTYPED_ATOMIC):
- case Type.UNTYPED:
- String res = inputToken.getText();
+ String res = getStringValueOrEmpty(subIters[0]);
+ if (res==null)
+ currentToken = new TextToken(null, "");
+ else
currentToken = new TextToken(null, res.toLowerCase());
- break;
- default:
- throw new TypeException(ErrorCodes.F0028_INVALID_ARGUMENT_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
- }
+
}
public TypeInfo getStaticType() {
return new TypeInfo(Type.STRING,Type.OCCURRENCE_IND_EXACTLY_ONE);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Matches.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Matches.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Matches.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -24,42 +24,26 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
-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.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class Matches extends TokenBasedIterator {
protected void init() throws MXQueryException {
- if (subIters == null || subIters.length == 1 || subIters.length > 3) {
- throw new IllegalArgumentException();
- }
+ String text = getStringValueOrEmpty(subIters[0]);
+ if (text == null)
+ text = "";
- TokenInterface input = subIters[0].next();
- int ev = Type.getEventTypeSubstituted(input.getEventType(),Context.getDictionary());
- if (!(ev == Type.STRING || input == Token.END_SEQUENCE_TOKEN))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Expected String, got "+Type.getTypeQName(ev, Context.getDictionary()),loc);
-
- String text;
- if (input == Token.END_SEQUENCE_TOKEN)
- text = "";
- else
- text = input.getText();
-
-
- TokenInterface pattern = subIters[1].next();
-
int f = computeFlags(subIters, 3, loc);
- String pat = pattern.getText();
+ String pat = getStringValue(subIters[1]);
- if (pat == null || pat.equals("")) {
+ if (pat.equals("")) {
throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Pattern must be a String value!", loc);
}
@@ -71,8 +55,10 @@
Pattern p = null;
try {
- String translated = Translator.translate(pat);
- p = Pattern.compile(translated, f);
+ String toMatch = pat;
+ if ((f & Pattern.LITERAL) == 0)
+ toMatch = Translator.translate(pat);
+ p = Pattern.compile(toMatch, f);
} catch (Exception e) {
throw new DynamicException(ErrorCodes.F0032_INVALID_REGULAR_EXPRESSION, "Invalid regular expression!", loc);
}
@@ -114,6 +100,7 @@
static int computeFlags(XDMIterator [] subIters, int pos, QueryLocation loc) throws MXQueryException {
int f = 0;
if (subIters.length == pos) {
+
TokenInterface flags = subIters[pos-1].next();
String theFlags = flags.getText();
@@ -122,7 +109,7 @@
}
if (!theFlags.equals("")) { // if flags are empty, skip
- if (!theFlags.matches("[smix]+")) {
+ if (!theFlags.matches("[smixq]+")) {
throw new DynamicException(ErrorCodes.F0031_INVALID_REGULAR_EXPRESSION_FLAGS, "Invalid regular expression flags!", loc);
}
@@ -137,7 +124,11 @@
}
if (theFlags.indexOf("x") >= 0) {
f += Pattern.COMMENTS;
+ }
+ if (theFlags.indexOf("q") >= 0) {
+ f += Pattern.LITERAL;
}
+
}
}
return f;
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Namespace_uri_for_prefix.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Namespace_uri_for_prefix.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Namespace_uri_for_prefix.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -32,19 +32,9 @@
public class Namespace_uri_for_prefix extends TokenBasedIterator {
protected void init() throws MXQueryException {
- if (subIters == null || subIters.length != 2) {
- throw new IllegalArgumentException();
- }
-
- XDMIterator prefixIter = subIters[0];
-
- TokenInterface t1 = prefixIter.next();
- String prefixToTest;
- if (t1.getEventType() == Type.END_SEQUENCE)
+ String prefixToTest = getStringValueOrEmpty(subIters[0]);
+ if (prefixToTest == null)
prefixToTest = "";
- else
- prefixToTest = t1.getText();
-
TokenInterface t2 = subIters[1].next();
if (t2.getEventType() == Type.START_TAG) {
XDMScope scope = t2.getDynamicScope();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeSpace.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeSpace.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeSpace.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -20,10 +20,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.Utils;
@@ -31,28 +28,11 @@
public class NormalizeSpace extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(getNodeIteratorOrContext(subIters, 1,context, loc), context);
-
- TokenInterface tok = input.next();
-
- int type = Type.getEventTypeSubstituted( tok.getEventType(), Context.getDictionary() );
- String res = tok.getText();
-
- switch (type) {
- case(Type.END_SEQUENCE):
- currentToken = new TextToken(null, "");
- break;
- case Type.STRING:
- case Type.UNTYPED_ATOMIC:
- case Type.UNTYPED: {
- currentToken = new TextToken(null, Utils.normalizeString(res));
- }
- break;
- default:
- throw new TypeException(ErrorCodes.F0028_INVALID_ARGUMENT_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
- }
- if (input.next().getEventType() != Type.END_SEQUENCE)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "No sequences allow as input to normalize-space()", loc);
+ String res = getStringValueOrEmpty(DataValuesIterator.getDataIterator(getNodeIteratorOrContext(subIters, 1,context, loc), context));
+ if (res == null)
+ currentToken = new TextToken(null, "");
+ else
+ currentToken = new TextToken(null, Utils.normalizeString(res));
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -20,11 +20,8 @@
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.types.TypeDictionary;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
@@ -34,56 +31,32 @@
public class NormalizeUnicode extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface tok = input.next();
- TypeDictionary tdic = Context.getDictionary();
- int type = tok.getEventType();
- if (!(Type.isTypeOrSubTypeOf(type, Type.STRING,tdic)||tok == Token.END_SEQUENCE_TOKEN)) {
- throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "String expected for normalize-unicode, got "+Type.getTypeQName(type, tdic),loc);
- }
+
+ String toNormalize = getStringValueOrEmpty(subIters[0]);
- if (input.next() != Token.END_SEQUENCE_TOKEN) {
- throw new DynamicException(ErrorCodes.E0001_STATIC_NO_VALUE_ASSIGNED, "More than a single value given to normalize-unicode",loc);
- }
-
- String toNormalize;
-
- if (tok == Token.END_SEQUENCE_TOKEN)
+ if (toNormalize == null)
toNormalize = "";
- else
- toNormalize = tok.getText();
try {
Normalizer.Form normalForm = Normalizer.Form.NFC;
-
if (subIters.length == 2) {
- XDMIterator inputNF = subIters[1];
- TokenInterface tokNF = inputNF.next();
- int type1 = tokNF.getEventType();
- if (!(Type.isTypeOrSubTypeOf(type1, Type.STRING,tdic))) {
- throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "String expected for normalize-unicode, got "+Type.getTypeQName(type, tdic),loc);
- }
-
- if (inputNF.next() != Token.END_SEQUENCE_TOKEN) {
- throw new DynamicException(ErrorCodes.E0001_STATIC_NO_VALUE_ASSIGNED, "More than a single value given to normalize-unicode",loc);
- }
-
- if (tokNF.getText().equals("")) {
+ String nf = getStringValue(subIters[1]).trim();
+ if (nf.equals("")) {
currentToken = new TextToken(null,toNormalize);
return;
}
- if (tokNF.getText().trim().equalsIgnoreCase("NFC"))
+ if (nf.equalsIgnoreCase("NFC"))
normalForm = Normalizer.Form.NFC;
- else if (tokNF.getText().trim().equalsIgnoreCase("NFD"))
+ else if (nf.equalsIgnoreCase("NFD"))
normalForm = Normalizer.Form.NFD;
- else if (tokNF.getText().trim().equalsIgnoreCase("NFKC"))
+ else if (nf.equalsIgnoreCase("NFKC"))
normalForm = Normalizer.Form.NFKC;
- else if (tokNF.getText().trim().equalsIgnoreCase("NFKD"))
+ else if (nf.equalsIgnoreCase("NFKD"))
normalForm = Normalizer.Form.NFKD;
else
- throw new DynamicException(ErrorCodes.F0011_UNSUPPORTED_NORMALIZATION_FORM, "Normalizaton form "+tokNF.getText()+" not supported",loc);
+ throw new DynamicException(ErrorCodes.F0011_UNSUPPORTED_NORMALIZATION_FORM, "Normalizaton form "+nf+" not supported",loc);
}
String normalized = Normalizer.normalize(toNormalize, normalForm);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Parse.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Parse.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Parse.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -23,7 +23,6 @@
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.CurrentBasedIterator;
import ch.ethz.mxquery.model.EmptySequenceIterator;
@@ -54,23 +53,16 @@
public void init() throws MXQueryException {
- XDMIterator parameter = subIters[0];
- TokenInterface tok = parameter.next();
- int type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
- if (type == Type.END_SEQUENCE) {
- current = new EmptySequenceIterator(context,loc);
- return;
- }
- if (type == Type.STRING || type == Type.UNTYPED_ATOMIC || type == Type.UNTYPED) {
- String add=tok.getText();
- if (!useTidy)
- current = XDMInputFactory.createXMLInput(context, new StringReader(add),false,context.getInputValidationMode(),loc);
- else
- current = XDMInputFactory.createTidyInput(context, new StringReader(add), loc);
- } else {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Type "+Type.getTypeQName(type, Context.getDictionary())+" not correct at parse-string-to-XML", loc);
- }
+ String add = getStringValueOrEmpty(subIters[0]);
+ if (add == null || add.equals("")) {
+ current = new EmptySequenceIterator(context,loc);
return;
+ }
+ if (!useTidy)
+ current = XDMInputFactory.createXMLInput(context, new StringReader(add),false,context.getInputValidationMode(),loc);
+ else
+ current = XDMInputFactory.createTidyInput(context, new StringReader(add), loc);
+ return;
}
public TypeInfo getStaticType() {
return new TypeInfo(Type.START_TAG,Type.OCCURRENCE_IND_ZERO_OR_ONE);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Replace.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Replace.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Replace.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -24,43 +24,24 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
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.DynamicException;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.ObjectObjectPair;
public class Replace extends TokenBasedIterator {
- protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface inputToken1 = input.next();
- int type = Type.getEventTypeSubstituted( inputToken1.getEventType(), Context.getDictionary() );
-
- if (type == Type.END_SEQUENCE) {
+ protected void init() throws MXQueryException {
+ String res = getStringValueOrEmpty(subIters[0]);
+ if (res == null){
currentToken = new TextToken(null, "");
return;
- }
+ }
+ String pattern = getStringValue(subIters[1]);
+ String replacement = getStringValue(subIters[2]);
- if (!(type == Type.STRING||type == Type.UNTYPED_ATOMIC||type == Type.UNTYPED))
- throw new TypeException(ErrorCodes.F0028_INVALID_ARGUMENT_TYPE, "Invalid argument type"+type, loc);
-
- String res = inputToken1.getText();
-
- TokenInterface inputToken2 = subIters[1].next();
- if (inputToken2.getEventType() == Type.END_SEQUENCE)
- throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid pattern", loc);
-
- String pattern = inputToken2.getText();
-
- TokenInterface inputToken3 = subIters[2].next();
- if (inputToken3.getEventType() == Type.END_SEQUENCE)
- throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid replacement (empty squence)!", loc);
- String replacement = inputToken3.getText();
-
int f = Matches.computeFlags(subIters, 4, loc);
Pattern p = null;
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/ResolveQName.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/ResolveQName.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/ResolveQName.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -35,51 +35,30 @@
public class ResolveQName extends TokenBasedIterator {
protected void init() throws MXQueryException {
- if (subIters[0] == null) {
- throw new IllegalArgumentException();
- }
+ String val = getStringValueOrEmpty(subIters[0]);
+ if (val == null)
+ currentToken = Token.END_SEQUENCE_TOKEN;
+ else if (val.equals(""))
+ throw new TypeException(ErrorCodes.F0023_INVALID_VALUE_FOR_CAST_CONSTRUCTOR, "Invalid lexical value: " + val, loc);
+ else {
+ TokenInterface contextNode = subIters[1].next();
- XDMIterator iter = subIters[0];
- TokenInterface inputToken = iter.next();
-
- int type = Type.getEventTypeSubstituted( inputToken.getEventType(), Context.getDictionary() );
-
- switch (type) {
- case Type.END_SEQUENCE:
- currentToken = Token.END_SEQUENCE_TOKEN;
- break;
- case Type.STRING:
- case Type.UNTYPED_ATOMIC:
- String val = inputToken.getText().trim();
- if (val.equals(""))
- throw new TypeException(ErrorCodes.F0023_INVALID_VALUE_FOR_CAST_CONSTRUCTOR, "Invalid lexical value: " + val, loc);
-
- TokenInterface contextNode = subIters[1].next();
-
- QName res = new QName(val);
-
- currentToken = new QNameToken(null, res);
-
- if (contextNode.getEventType() == Type.START_TAG) {
- XDMScope ns = contextNode.getDynamicScope();
- String nm = ns.getNsURI(res.getNamespacePrefix());
- if (nm != null) {
- res.setNamespaceURI(nm);
- } else if (res.getNamespacePrefix() != null) {
- throw new DynamicException(ErrorCodes.F0021_NO_NAMESPACE_FOUND,"No namespace found for the given prefix and context node",loc);
- }
-
- } else
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Need element node for fn-resolve-qname()",loc);
+ QName res = new QName(val);
-
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Could not cast type " + Type.getTypeQName(type, Context.getDictionary()) + " to type " + Type.getTypeQName(Type.QNAME, Context.getDictionary()), loc);
- }
-
- if ( iter.next() != Token.END_SEQUENCE_TOKEN )
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Could not cast sequence to atomic type " + Type.getTypeQName(Type.QNAME, Context.getDictionary()), loc);
+ currentToken = new QNameToken(null, res);
+
+ if (contextNode.getEventType() == Type.START_TAG) {
+ XDMScope ns = contextNode.getDynamicScope();
+ String nm = ns.getNsURI(res.getNamespacePrefix());
+ if (nm != null) {
+ res.setNamespaceURI(nm);
+ } else if (res.getNamespacePrefix() != null) {
+ throw new DynamicException(ErrorCodes.F0021_NO_NAMESPACE_FOUND,"No namespace found for the given prefix and context node",loc);
+ }
+
+ } else
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Need element node for fn-resolve-qname()",loc);
+ }
}
public TypeInfo getStaticType() {
return new TypeInfo(Type.QNAME,Type.OCCURRENCE_IND_ZERO_OR_ONE);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringJoin.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringJoin.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringJoin.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -36,14 +36,7 @@
if (subIters.length > 1) {
- TokenInterface inputToken2 = subIters[1].next();
- int type2 = inputToken2.getEventType();
-
-
- if (type2 != Type.END_SEQUENCE)
- sep = inputToken2.getText();
- else
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Empty Sequence not allowed as separator in string-join", loc);
+ sep = getStringValue(subIters[1]);
}
StringBuffer res = new StringBuffer();
@@ -51,6 +44,12 @@
TokenInterface tok = it.next();
+ int aType = tok.getEventType();
+
+ if ( !(Type.typePromoteableTo(aType, Type.STRING,Context.getDictionary()) ||aType == Type.UNTYPED_ATOMIC || aType == Type.END_SEQUENCE)) {
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Item of type "+"xs:string"+" expected", loc);
+ }
+
String curString = tok.getValueAsString();
if (curString == null) {
curString = "";
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -24,9 +24,7 @@
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.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
@@ -34,23 +32,11 @@
String toTranslate = null;
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface inputToken =input.next();
- int type = Type.getEventTypeSubstituted( inputToken.getEventType(), Context.getDictionary() );
-
- switch (type) {
- case(Type.END_SEQUENCE):
- currentToken = new TextToken(null, "");
- break;
- case(Type.STRING):
- case(Type.UNTYPED_ATOMIC):
- case Type.UNTYPED:
- String res = inputToken.getText();
- toTranslate = res;
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
- }
+ toTranslate = getStringValueOrEmpty(subIters[0]);
+ if (toTranslate==null||toTranslate.equals("")) {
+ currentToken = new TextToken(null, "");
+ return;
+ }
}
public TokenInterface next() throws MXQueryException {
if (called == 0)
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/String_Length.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/String_Length.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/String_Length.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -21,10 +21,6 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.LongToken;
-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.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
@@ -43,23 +39,17 @@
input = new FNString();
input.setContext(context, false);
}
-
- TokenInterface inputToken = input.next();
- int type = inputToken.getEventType();
+ String content = getStringValueOrEmpty(input);
- if (type == Type.END_SEQUENCE){
+ if (content == null){
currentToken = new LongToken(Type.INTEGER, null,0);
- } else if ( (Type.isTypeOrSubTypeOf(type, Type.STRING, Context.getDictionary()) || type == Type.UNTYPED_ATOMIC )&&
- input.next() == Token.END_SEQUENCE_TOKEN){
- String content = inputToken.getValueAsString();
+ } else {
int charCount = content.length();
//TODO: performance improvement: annotate string token if they contain only non BMP-codepoints
//=> counting CP is unnecessary then
int characterCount = content.codePointCount(0, charCount);
currentToken = new LongToken(Type.INTEGER, null, characterCount );
- } else {
- throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Value of type xs:string expected",loc);
- }
+ }
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Tokenize.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Tokenize.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Tokenize.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -45,16 +45,10 @@
}
private void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface tok1 = input.next();
- int type = tok1.getEventType();
- String res = tok1.getText();
- XDMIterator input2 = subIters[1];
- TokenInterface tok2 = input2.next();
- int type2 = Type.getEventTypeSubstituted( tok2.getEventType(), Context.getDictionary());
- String delimiter = tok2.getText();
- if (type2 != Type.STRING || delimiter.length() == 0)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
+ String res = getStringValueOrEmpty(subIters[0]);
+ String delimiter = getStringValue(subIters[1]);
+ if (delimiter.length() == 0)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Separator must not be empty", loc);
int f = Matches.computeFlags(subIters, 3, loc);
@@ -73,26 +67,15 @@
if (m.find())
throw new DynamicException(ErrorCodes.F0033_REGULAR_EXPRESSION_MATCHES_EMPTY,"Pattern matches empty string",loc);
- switch (type) {
- case(Type.END_SEQUENCE):
- current = new EmptySequenceIterator(context,loc);
- break;
-
- case Type.STRING:
- case Type.UNTYPED_ATOMIC:
- if (res.length() == 0)
- current = new EmptySequenceIterator(context,loc);
- else {
- //String [] splitted = Utils.split(res,delimiter);
- String [] splitted = p.split(res,-1);
- TokenIterator [] toks = new TokenIterator[splitted.length];
- for (int i =0;i<toks.length;i++)
- toks[i] = new TokenIterator(context, splitted[i],loc);
- current = new SequenceIterator(context, toks,loc);
- }
- break;
- default:
- throw new TypeException(ErrorCodes.F0028_INVALID_ARGUMENT_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
+ if (res == null || res.length() == 0)
+ current = new EmptySequenceIterator(context,loc);
+ else {
+ //String [] splitted = Utils.split(res,delimiter);
+ String [] splitted = p.split(res,-1);
+ TokenIterator [] toks = new TokenIterator[splitted.length];
+ for (int i =0;i<toks.length;i++)
+ toks[i] = new TokenIterator(context, splitted[i],loc);
+ current = new SequenceIterator(context, toks,loc);
}
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Trace.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Trace.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/f...
[truncated message content] |