01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.backend.list.memorybased.expression.compare;
16:
17: import org.apache.commons.lang.ObjectUtils;
18: import org.araneaframework.backend.list.memorybased.Expression;
19: import org.araneaframework.backend.list.memorybased.ExpressionEvaluationException;
20: import org.araneaframework.backend.list.memorybased.expression.CompositeExpression;
21: import org.araneaframework.backend.list.memorybased.expression.StringExpression;
22: import org.araneaframework.backend.list.memorybased.expression.Value;
23: import org.araneaframework.backend.list.memorybased.expression.VariableResolver;
24: import org.araneaframework.uilib.list.util.like.LikeConfiguration;
25: import org.araneaframework.uilib.list.util.like.RegexpLikeUtil;
26:
27: public class LikeExpression implements CompositeExpression,
28: StringExpression {
29:
30: private static final long serialVersionUID = 1L;
31:
32: private Expression expr;
33:
34: private Value mask;
35:
36: private boolean ignoreCase;
37:
38: private LikeConfiguration configuration;
39:
40: public LikeExpression(Expression expr, Value mask,
41: boolean ignoreCase, LikeConfiguration configuration) {
42: if (expr == null) {
43: throw new IllegalArgumentException(
44: "Expression must be provided");
45: }
46: if (mask == null) {
47: throw new IllegalArgumentException("Value must be provided");
48: }
49: this .expr = expr;
50: this .mask = mask;
51: this .ignoreCase = ignoreCase;
52: this .configuration = configuration;
53: }
54:
55: public boolean getIgnoreCase() {
56: return this .ignoreCase;
57: }
58:
59: public Value getMask() {
60: return this .mask;
61: }
62:
63: public LikeConfiguration getConfiguration() {
64: return configuration;
65: }
66:
67: public Object evaluate(VariableResolver resolver)
68: throws ExpressionEvaluationException {
69: return RegexpLikeUtil.isLike(ObjectUtils.toString(this .expr
70: .evaluate(resolver)), ObjectUtils.toString(this .mask
71: .getValue()), this .ignoreCase, this .configuration) ? Boolean.TRUE
72: : Boolean.FALSE;
73: }
74:
75: public Expression[] getChildren() {
76: return new Expression[] { this.expr };
77: }
78: }
|