use of org.javarosa.xpath.expr.XPathExpression in project javarosa by opendatakit.
the class XPathReference method getPathExpr.
public static XPathPathExpr getPathExpr(String nodeset) {
XPathExpression path;
boolean validNonPathExpr = false;
try {
path = XPathParseTool.parseXPath(nodeset);
if (!(path instanceof XPathPathExpr)) {
validNonPathExpr = true;
throw new XPathSyntaxException();
}
} catch (XPathSyntaxException xse) {
// make these checked exceptions?
if (validNonPathExpr) {
throw new XPathTypeMismatchException("Expected XPath path, got XPath expression: [" + nodeset + "]," + xse.getMessage());
} else {
Std.printStack(xse);
throw new XPathException("Parse error in XPath path: [" + nodeset + "]." + (xse.getMessage() == null ? "" : "\n" + xse.getMessage()));
}
}
return (XPathPathExpr) path;
}
use of org.javarosa.xpath.expr.XPathExpression in project javarosa by opendatakit.
the class ASTNodeLocPath method build.
public XPathExpression build() throws XPathSyntaxException {
Vector<XPathStep> steps = new Vector<XPathStep>();
XPathExpression filtExpr = null;
int offset = isAbsolute() ? 1 : 0;
for (int i = 0; i < clauses.size() + offset; i++) {
if (offset == 0 || i > 0) {
if (clauses.elementAt(i - offset) instanceof ASTNodePathStep) {
steps.addElement(((ASTNodePathStep) clauses.elementAt(i - offset)).getStep());
} else {
filtExpr = clauses.elementAt(i - offset).build();
}
}
if (i < separators.size()) {
if (Parser.vectInt(separators, i) == Token.DBL_SLASH) {
steps.addElement(XPathStep.ABBR_DESCENDANTS());
}
}
}
XPathStep[] stepArr = new XPathStep[steps.size()];
for (int i = 0; i < stepArr.length; i++) stepArr[i] = steps.elementAt(i);
if (filtExpr == null) {
return new XPathPathExpr(isAbsolute() ? XPathPathExpr.INIT_CONTEXT_ROOT : XPathPathExpr.INIT_CONTEXT_RELATIVE, stepArr);
} else {
if (filtExpr instanceof XPathFilterExpr) {
return new XPathPathExpr((XPathFilterExpr) filtExpr, stepArr);
} else {
return new XPathPathExpr(new XPathFilterExpr(filtExpr, new XPathExpression[0]), stepArr);
}
}
}
use of org.javarosa.xpath.expr.XPathExpression in project javarosa by opendatakit.
the class XPathParseTest method testXPathValid.
private void testXPathValid(String expr, String expected) {
try {
XPathExpression xpe = XPathParseTool.parseXPath(expr);
String result = (xpe != null ? xpe.toString() : null);
if (result == null || !result.equals(expected)) {
fail("XPath Parse Failed! Incorrect parse tree." + "\n expression:[" + expr + "]" + "\n expected:[" + expected + "]" + "\n result:[" + result + "]");
}
// test serialization of parse tree
ExternalizableTest.testExternalizable(new ExtWrapTagged(xpe), new ExtWrapTagged(), pf, this, "XPath");
} catch (XPathSyntaxException xse) {
fail("XPath Parse Failed! Unexpected syntax error." + "\n expression:[" + expr + "]");
}
}
use of org.javarosa.xpath.expr.XPathExpression in project javarosa by opendatakit.
the class XPathParseTest method testXPathInvalid.
private void testXPathInvalid(String expr) {
try {
XPathExpression xpe = XPathParseTool.parseXPath(expr);
String result = (xpe != null ? xpe.toString() : null);
fail("XPath Parse Failed! Did not get syntax error as expected." + "\n expression:[" + expr + "]" + "\n result:[" + (result == null ? "(null)" : result) + "]");
} catch (XPathSyntaxException xse) {
// success: syntax error as expected
}
}
Aggregations