use of org.apache.commons.jexl3.parser.ASTStringLiteral in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method getLiteral.
private static ASTStringLiteral getLiteral(String fieldValue) {
ASTStringLiteral literal = new ASTStringLiteral(ParserTreeConstants.JJTSTRINGLITERAL);
literal.image = fieldValue;
return literal;
}
use of org.apache.commons.jexl3.parser.ASTStringLiteral in project commons-jexl by apache.
the class Engine method getVariables.
/**
* Fills up the list of variables accessed by a node.
* @param script the owning script
* @param node the node
* @param collector the variable collector
*/
protected void getVariables(final ASTJexlScript script, final JexlNode node, final VarCollector collector) {
if (node instanceof ASTIdentifier) {
final JexlNode parent = node.jjtGetParent();
if (parent instanceof ASTMethodNode || parent instanceof ASTFunctionNode) {
// skip identifiers for methods and functions
collector.collect(null);
return;
}
final ASTIdentifier identifier = (ASTIdentifier) node;
final int symbol = identifier.getSymbol();
// symbols that are captured are considered "global" variables
if (symbol >= 0 && script != null && !script.isCapturedSymbol(symbol)) {
collector.collect(null);
} else {
// start collecting from identifier
collector.collect(identifier);
collector.add(identifier.getName());
}
} else if (node instanceof ASTIdentifierAccess) {
final JexlNode parent = node.jjtGetParent();
if (parent instanceof ASTMethodNode || parent instanceof ASTFunctionNode) {
// skip identifiers for methods and functions
collector.collect(null);
return;
}
// belt and suspender since an identifier should have been seen first
if (collector.isCollecting()) {
collector.add(((ASTIdentifierAccess) node).getName());
}
} else if (node instanceof ASTArrayAccess && collector.mode > 0) {
final int num = node.jjtGetNumChildren();
// collect only if array access is const and follows an identifier
boolean collecting = collector.isCollecting();
for (int i = 0; i < num; ++i) {
final JexlNode child = node.jjtGetChild(i);
if (collecting && child.isConstant()) {
// collect all constants or only string and number literals
final boolean collect = collector.mode > 1 || (child instanceof ASTStringLiteral || child instanceof ASTNumberLiteral);
if (collect) {
final String image = child.toString();
collector.add(image);
}
} else {
collecting = false;
collector.collect(null);
getVariables(script, child, collector);
collector.collect(null);
}
}
} else {
final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
getVariables(script, node.jjtGetChild(i), collector);
}
collector.collect(null);
}
}
use of org.apache.commons.jexl3.parser.ASTStringLiteral in project nexus-public by sonatype.
the class DatastoreCselToSql method transformMatchesOperator.
protected SelectorSqlBuilder transformMatchesOperator(final JexlNode node, final String operator, final SelectorSqlBuilder builder) {
JexlNode leftChild = node.jjtGetChild(LEFT);
JexlNode rightChild = node.jjtGetChild(RIGHT);
leftChild.jjtAccept(this, builder);
builder.appendOperator(operator);
if (rightChild instanceof ASTStringLiteral) {
String pattern = ((ASTStringLiteral) rightChild).getLiteral();
if (pattern.charAt(0) != '^') {
// match entire string
pattern = "^(" + pattern + ")$";
}
builder.appendLiteral(pattern);
} else {
throw new JexlException(node, EXPECTED_STRING_LITERAL);
}
return builder;
}
use of org.apache.commons.jexl3.parser.ASTStringLiteral in project nexus-public by sonatype.
the class DatastoreCselToSql method visit.
/**
* Transform `a != b` into `(a is null or a <> b)`
*/
@Override
protected Object visit(final ASTNENode node, final Object data) {
JexlNode leftChild = node.jjtGetChild(LEFT);
JexlNode rightChild = node.jjtGetChild(RIGHT);
if (rightChild instanceof ASTStringLiteral) {
transformNotEqualsOperator(leftChild, (ASTStringLiteral) rightChild, (SelectorSqlBuilder) data);
} else if (leftChild instanceof ASTStringLiteral) {
transformNotEqualsOperator(rightChild, (ASTStringLiteral) leftChild, (SelectorSqlBuilder) data);
} else {
throw new JexlException(node, EXPECTED_STRING_LITERAL);
}
return data;
}
use of org.apache.commons.jexl3.parser.ASTStringLiteral in project nexus-public by sonatype.
the class LeadingSlashScriptTransformer method doVisit.
@Override
protected Object doVisit(final JexlNode node, final Object data) {
if (node.jjtGetNumChildren() == 2) {
Node leftChild = node.jjtGetChild(LEFT);
Node rightChild = node.jjtGetChild(RIGHT);
if (isPathExpression(leftChild, rightChild)) {
transformPathLiteral((ASTStringLiteral) rightChild);
} else if (isPathExpression(rightChild, leftChild)) {
transformPathLiteral((ASTStringLiteral) leftChild);
} else {
leftChild.jjtAccept(this, data);
rightChild.jjtAccept(this, data);
}
} else {
node.childrenAccept(this, data);
}
return data;
}
Aggregations