| 66 | "(([\\w-\\[\\]$]|%[0-9A-Fa-f]{2})(\\.?([\\w-\\[\\]$]|%[0-9A-Fa-f]{2}))*(:.*|\\*)?)(,(([\\w-\\[\\]$]|%[0-9A-Fa-f]{2})(\\.?([\\w-\\[\\]$]|%[0-9A-Fa-f]{2}))*(:.*|\\*)?))*"); |
| 67 | |
| 68 | public static Expression create(final String value) { |
| 69 | |
| 70 | /* remove the start and end braces */ |
| 71 | final String expression = stripBraces(value); |
| 72 | if (expression == null || expression.isEmpty()) { |
| 73 | throw new IllegalArgumentException("an expression is required."); |
| 74 | } |
| 75 | |
| 76 | /* Check if the expression is too long */ |
| 77 | if (expression.length() > MAX_EXPRESSION_LENGTH) { |
| 78 | throw new IllegalArgumentException( |
| 79 | "expression is too long. Max length: " + MAX_EXPRESSION_LENGTH); |
| 80 | } |
| 81 | |
| 82 | /* create a new regular expression matcher for the expression */ |
| 83 | String variableName = null; |
| 84 | String variablePattern = null; |
| 85 | String operator = null; |
| 86 | Matcher matcher = EXPRESSION_PATTERN.matcher(value); |
| 87 | if (matcher.matches()) { |
| 88 | /* grab the operator */ |
| 89 | operator = matcher.group(2).trim(); |
| 90 | |
| 91 | /* we have a valid variable expression, extract the name from the first group */ |
| 92 | variableName = matcher.group(3).trim(); |
| 93 | if (variableName.contains(":")) { |
| 94 | /* split on the colon and ensure the size of parts array must be 2 */ |
| 95 | String[] parts = variableName.split(":", 2); |
| 96 | variableName = parts[0]; |
| 97 | variablePattern = parts[1]; |
| 98 | } |
| 99 | |
| 100 | /* look for nested expressions */ |
| 101 | if (variableName.contains("{")) { |
| 102 | /* nested, literal */ |
| 103 | return null; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* check for an operator */ |
| 108 | if (PATH_STYLE_OPERATOR.equalsIgnoreCase(operator)) { |
| 109 | return new PathStyleExpression(variableName, variablePattern); |
| 110 | } |
| 111 | |
| 112 | /* default to simple */ |
| 113 | return SimpleExpression.isSimpleExpression(value) |
| 114 | ? new SimpleExpression(variableName, variablePattern) |
| 115 | : null; // Return null if it can't be validated as a Simple Expression -- Probably a Literal |
| 116 | } |
| 117 | |
| 118 | private static String stripBraces(String expression) { |
| 119 | if (expression == null) { |