// bodyAs
String remainder = ifStartsWithReturnRemainder("bodyAs", expression);
if (remainder != null) {
String type = ObjectHelper.between(remainder, "(", ")");
if (type == null) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${bodyAs(type)} was: " + expression);
}
type = StringHelper.removeQuotes(type);
return ExpressionBuilder.bodyExpression(type);
}
// mandatoryBodyAs
remainder = ifStartsWithReturnRemainder("mandatoryBodyAs", expression);
if (remainder != null) {
String type = ObjectHelper.between(remainder, "(", ")");
if (type == null) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${mandatoryBodyAs(type)} was: " + expression);
}
type = StringHelper.removeQuotes(type);
return ExpressionBuilder.mandatoryBodyExpression(type);
}
// body OGNL
remainder = ifStartsWithReturnRemainder("body", expression);
if (remainder == null) {
remainder = ifStartsWithReturnRemainder("in.body", expression);
}
if (remainder != null) {
boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder);
if (invalid) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${body.OGNL} was: " + expression);
}
return ExpressionBuilder.bodyOgnlExpression(remainder);
}
// Exception OGNL
remainder = ifStartsWithReturnRemainder("exception", expression);
if (remainder != null) {
boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder);
if (invalid) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${exception.OGNL} was: " + expression);
}
return ExpressionBuilder.exchangeExceptionOgnlExpression(remainder);
}
// headerAs
remainder = ifStartsWithReturnRemainder("headerAs", expression);
if (remainder != null) {
String keyAndType = ObjectHelper.between(remainder, "(", ")");
if (keyAndType == null) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${headerAs(key, type)} was: " + expression);
}
String key = ObjectHelper.before(keyAndType, ",");
String type = ObjectHelper.after(keyAndType, ",");
if (ObjectHelper.isEmpty(key) || ObjectHelper.isEmpty(type)) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${headerAs(key, type)} was: " + expression);
}
key = StringHelper.removeQuotes(key);
type = StringHelper.removeQuotes(type);
return ExpressionBuilder.headerExpression(key, type);
}
// in header expression
remainder = ifStartsWithReturnRemainder("in.headers", expression);
if (remainder == null) {
remainder = ifStartsWithReturnRemainder("in.header", expression);
}
if (remainder == null) {
remainder = ifStartsWithReturnRemainder("headers", expression);
}
if (remainder == null) {
remainder = ifStartsWithReturnRemainder("header", expression);
}
if (remainder != null) {
// remove leading character (dot or ?)
remainder = remainder.substring(1);
// validate syntax
boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder);
if (invalid) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${header.name[key]} was: " + expression);
}
if (OgnlHelper.isValidOgnlExpression(remainder)) {
// ognl based header
return ExpressionBuilder.headersOgnlExpression(remainder);
} else {
// regular header
return ExpressionBuilder.headerExpression(remainder);
}
}
// out header expression
remainder = ifStartsWithReturnRemainder("out.header.", expression);
if (remainder == null) {
remainder = ifStartsWithReturnRemainder("out.headers.", expression);
}
if (remainder != null) {
return ExpressionBuilder.outHeaderExpression(remainder);
}
// property
remainder = ifStartsWithReturnRemainder("property", expression);
if (remainder != null) {
// remove leading character (dot or ?)
remainder = remainder.substring(1);
// validate syntax
boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder);
if (invalid) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${property.OGNL} was: " + expression);
}
if (OgnlHelper.isValidOgnlExpression(remainder)) {
// ognl based property
return ExpressionBuilder.propertyOgnlExpression(remainder);
} else {
// regular property
return ExpressionBuilder.propertyExpression(remainder);
}
}
// system property
remainder = ifStartsWithReturnRemainder("sys.", expression);
if (remainder != null) {
return ExpressionBuilder.systemPropertyExpression(remainder);
}
// system property
remainder = ifStartsWithReturnRemainder("sysenv.", expression);
if (remainder != null) {
return ExpressionBuilder.systemEnvironmentExpression(remainder);
}
// file: prefix
remainder = ifStartsWithReturnRemainder("file:", expression);
if (remainder != null) {
Expression fileExpression = createSimpleFileExpression(remainder);
if (expression != null) {
return fileExpression;
}
}
// date: prefix
remainder = ifStartsWithReturnRemainder("date:", expression);
if (remainder != null) {
String[] parts = remainder.split(":");
if (parts.length < 2) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${date:command:pattern} was: " + expression);
}
String command = ObjectHelper.before(remainder, ":");
String pattern = ObjectHelper.after(remainder, ":");
return ExpressionBuilder.dateExpression(command, pattern);
}
// bean: prefix
remainder = ifStartsWithReturnRemainder("bean:", expression);
if (remainder != null) {
return ExpressionBuilder.beanExpression(remainder);
}
// properties: prefix
remainder = ifStartsWithReturnRemainder("properties:", expression);
if (remainder != null) {
String[] parts = remainder.split(":");
if (parts.length > 2) {
throw new ExpressionIllegalSyntaxException("Valid syntax: ${properties:[locations]:key} was: " + expression);
}
String locations = null;
String key = remainder;
if (parts.length == 2) {
locations = ObjectHelper.before(remainder, ":");
key = ObjectHelper.after(remainder, ":");
}
return ExpressionBuilder.propertiesComponentExpression(key, locations);
}
// ref: prefix
remainder = ifStartsWithReturnRemainder("ref:", expression);
if (remainder != null) {
return ExpressionBuilder.refExpression(remainder);
}
if (strict) {
throw new ExpressionIllegalSyntaxException(expression);
} else {
return ExpressionBuilder.constantExpression(expression);
}
}