}
inProp = false;
inValue = true;
firstValueChar = true;
} else {
throw new QueryParseException("Found <end-of-string> "
+ "immediately following '>' operator, but "
+ "expected a value.");
}
} else if (c == '<') {
if (i + 1 < query.length()) {
char d = query.charAt(i + 1);
if (d == '=') {
i++;
oper = Operator.LESS_OR_EQUAL;
} else {
oper = Operator.LESS_THAN;
}
inProp = false;
inValue = true;
firstValueChar = true;
} else {
throw new QueryParseException("Found <end-of-string> "
+ "immediately following '<' operator, but "
+ "expected a value.");
}
} else if ((c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A)) {
prop.append(c);
} else {
throw new QueryParseException("Found ' " + c
+ "' at character " + i
+ " but expected operator");
}
} else if (inValue) {
if (prop.toString().length() == 0) {
throw new QueryParseException("Found "
+ "operator but expected a non-zero length "
+ "property.");
}
if (firstValueChar) {
// allow ', and mark it if it's there, add one to i
if (c == '\'') {
i++;
if (i >= query.length()) {
throw new QueryParseException("Found <end-of-string> "
+ "immediately following start quote, but "
+ "expected a value.");
}
c = query.charAt(i);
valueStartsWithQuote = true;
}
firstValueChar = false;
}
if (c == '\'') {
if (!valueStartsWithQuote) {
throw new QueryParseException("Found ' character in "
+ "value at position " + i + ", but the value "
+ "did not start with a string, so this can't "
+ " be a value terminator.");
}
// end of value part
// next must be space or empty... check
i++;
if (i < query.length()) {
if (query.charAt(i) != ' ') {
throw new QueryParseException("Found value-terminator "
+ "' but it was not followed by <end-of-string> "
+ "or <space>.");
}
}
ret
.add(new Condition(prop.toString(), oper, val
.toString()));
prop = new StringBuffer();
oper = null;
val = new StringBuffer();
inValue = false;
inProp = true;
valueStartsWithQuote = false;
} else if (c == '\\') {
i++;
if (i >= query.length()) {
throw new QueryParseException("Found character-escaping "
+ "character as last item in string.");
}
val.append(query.charAt(i));
} else if (c == ' ') {
// end of value part... or inside string?
if (valueStartsWithQuote) {
// was inside string..ok
val.append(c);
} else {
// end of value part...cuz not quotes
ret.add(new Condition(prop.toString(), oper, val
.toString()));
prop = new StringBuffer();
oper = null;
val = new StringBuffer();
inValue = false;
inProp = true;
}
} else if (c == '=') {
throw new QueryParseException("Found <operator> at position "
+ i + ", but expected <value>");
} else if (c == '~') {
throw new QueryParseException("Found <operator> at position "
+ i + ", but expected <value>");
} else if (c == '>') {
throw new QueryParseException("Found <operator> at position "
+ i + ", but expected <value>");
} else if (c == '<') {
throw new QueryParseException("Found <operator> at position "
+ i + ", but expected <value>");
} else {
val.append(c);
}
}
}
if (inProp) {
if (prop.toString().length() > 0) {
throw new QueryParseException("String ended before operator "
+ "was found");
}
}
if (inValue) {
if (valueStartsWithQuote) {
throw new QueryParseException("String ended before quoted value"
+ "'s ending quote.");
}
ret.add(new Condition(prop.toString(), oper, val.toString()));
}
return ret;