| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.language.simple; |
| 18 |
|
|
| 19 |
|
import org.apache.camel.Exchange; |
| 20 |
|
import org.apache.camel.Expression; |
| 21 |
|
import org.apache.camel.Predicate; |
| 22 |
|
import org.apache.camel.builder.ExpressionBuilder; |
| 23 |
|
import org.apache.camel.builder.PredicateBuilder; |
| 24 |
|
import org.apache.camel.language.IllegalSyntaxException; |
| 25 |
|
import org.apache.camel.spi.Language; |
| 26 |
|
import org.apache.camel.util.ObjectHelper; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
21 |
public class SimpleLanguage implements Language { |
| 44 |
|
|
| 45 |
|
public Predicate<Exchange> createPredicate(String expression) { |
| 46 |
9 |
return PredicateBuilder.toPredicate(createExpression(expression)); |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
public Expression<Exchange> createExpression(String expression) { |
| 50 |
21 |
if (ObjectHelper.isEqualToAny(expression, "body", "in.body")) { |
| 51 |
9 |
return ExpressionBuilder.bodyExpression(); |
| 52 |
12 |
} else if (ObjectHelper.equals(expression, "out.body")) { |
| 53 |
0 |
return ExpressionBuilder.outBodyExpression(); |
| 54 |
|
} |
| 55 |
12 |
String remainder = ifStartsWithReturnRemainder("in.header.", expression); |
| 56 |
12 |
if (remainder == null) { |
| 57 |
9 |
remainder = ifStartsWithReturnRemainder("header.", expression); |
| 58 |
|
} |
| 59 |
12 |
if (remainder != null) { |
| 60 |
12 |
return ExpressionBuilder.headerExpression(remainder); |
| 61 |
|
} |
| 62 |
0 |
remainder = ifStartsWithReturnRemainder("out.header.", expression); |
| 63 |
0 |
if (remainder != null) { |
| 64 |
0 |
return ExpressionBuilder.outHeaderExpression(remainder); |
| 65 |
|
} |
| 66 |
0 |
remainder = ifStartsWithReturnRemainder("property.", expression); |
| 67 |
0 |
if (remainder != null) { |
| 68 |
0 |
return ExpressionBuilder.propertyExpression(remainder); |
| 69 |
|
} |
| 70 |
0 |
remainder = ifStartsWithReturnRemainder("sys.", expression); |
| 71 |
0 |
if (remainder != null) { |
| 72 |
0 |
return ExpressionBuilder.propertyExpression(remainder); |
| 73 |
|
} |
| 74 |
0 |
throw new IllegalSyntaxException(this, expression); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
protected String ifStartsWithReturnRemainder(String prefix, String text) { |
| 78 |
21 |
if (text.startsWith(prefix)) { |
| 79 |
12 |
String remainder = text.substring(prefix.length()); |
| 80 |
12 |
if (remainder.length() > 0) { |
| 81 |
|
|
| 82 |
12 |
return remainder; |
| 83 |
|
} |
| 84 |
|
} |
| 85 |
9 |
return null; |
| 86 |
|
} |
| 87 |
|
} |