Package org.apache.camel.util
Class OgnlHelper
- java.lang.Object
-
- org.apache.camel.util.OgnlHelper
-
public final class OgnlHelper extends Object
Helper for Camel OGNL (Object-Graph Navigation Language) expressions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isInvalidValidOgnlExpression(String expression)
static boolean
isNullSafeOperator(String ognlExpression)
Tests whether or not the given Camel OGNL expression is using the null safe operator or not.static KeyValueHolder<String,String>
isOgnlIndex(String ognlExpression)
static boolean
isValidOgnlExpression(String expression)
Tests whether or not the given String is a Camel OGNL expression.static String
methodAsDoubleQuotes(String ognl)
static String
removeLeadingOperators(String ognlExpression)
Removes any leading operators from the Camel OGNL expression.static String
removeOperators(String ognlExpression)
static String
removeTrailingOperators(String ognlExpression)
Removes any trailing operators from the Camel OGNL expression.static List<String>
splitOgnl(String ognl)
Regular expression with repeating groups is a pain to get right and then nobody understands the reg exp afterwards.static void
validateMethodName(String method)
Validates whether the method name is using valid java identifiers in the name Will throwIllegalArgumentException
if the method name is invalid.
-
-
-
Method Detail
-
isValidOgnlExpression
public static boolean isValidOgnlExpression(String expression)
Tests whether or not the given String is a Camel OGNL expression. An expression is considered an OGNL expression when it contains either one of the following chars: . or [- Parameters:
expression
- the String- Returns:
- true if a Camel OGNL expression, otherwise false.
-
isInvalidValidOgnlExpression
public static boolean isInvalidValidOgnlExpression(String expression)
-
validateMethodName
public static void validateMethodName(String method)
Validates whether the method name is using valid java identifiers in the name Will throwIllegalArgumentException
if the method name is invalid.
-
isNullSafeOperator
public static boolean isNullSafeOperator(String ognlExpression)
Tests whether or not the given Camel OGNL expression is using the null safe operator or not.- Parameters:
ognlExpression
- the Camel OGNL expression- Returns:
- true if the null safe operator is used, otherwise false.
-
removeLeadingOperators
public static String removeLeadingOperators(String ognlExpression)
Removes any leading operators from the Camel OGNL expression. Will remove any leading of the following chars: ? or .- Parameters:
ognlExpression
- the Camel OGNL expression- Returns:
- the Camel OGNL expression without any leading operators.
-
removeTrailingOperators
public static String removeTrailingOperators(String ognlExpression)
Removes any trailing operators from the Camel OGNL expression.- Parameters:
ognlExpression
- the Camel OGNL expression- Returns:
- the Camel OGNL expression without any trailing operators.
-
removeOperators
public static String removeOperators(String ognlExpression)
-
isOgnlIndex
public static KeyValueHolder<String,String> isOgnlIndex(String ognlExpression)
-
splitOgnl
public static List<String> splitOgnl(String ognl)
Regular expression with repeating groups is a pain to get right and then nobody understands the reg exp afterwards. So we use a bit ugly/low-level Java code to split the OGNL into methods.- Parameters:
ognl
- the ognl expression- Returns:
- a list of methods, will return an empty list, if ognl expression has no methods
- Throws:
IllegalArgumentException
- if the last method has a missing ending parenthesis
-
methodAsDoubleQuotes
public static String methodAsDoubleQuotes(String ognl)
-
-