KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > grid > util > StringFilter


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  */

16 package com.blandware.atleap.webapp.taglib.core.grid.util;
17
18 import com.blandware.atleap.common.util.StringUtil;
19
20 /**
21  * <p>Filter for strings</p>
22  * <p><a HREF="StringFilter.java.htm"><i>View Source</i></a></p>
23  *
24  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
25  * @version $Revision: 1.5 $ $Date: 2005/08/05 17:48:34 $
26  */

27 public class StringFilter extends BaseFilter {
28
29     // ~ Instance variables
30

31     private String JavaDoc firstCondition = FilterConditions.STRING_CONTAINS;
32     private String JavaDoc firstValue = new String JavaDoc();
33     private String JavaDoc secondCondition = FilterConditions.CONDITION_NOT_SET;
34     private String JavaDoc secondValue = new String JavaDoc();
35     private String JavaDoc logicCopula = FilterConditions.LOGIC_COPULA_AND;
36
37     /**
38      * Creates new instance of StringFilter
39      *
40      * @param fieldName Name of field to associate filter with
41      */

42     public StringFilter(String JavaDoc fieldName) {
43         super(fieldName);
44     }
45
46     /**
47      * Creates clause from specified condition and string to compare our field to
48      *
49      * @param condition Condition to insert into clause
50      * @param compareTo String to compare to
51      * @return Constructed clause
52      */

53     private String JavaDoc createClause(String JavaDoc condition, String JavaDoc compareTo) {
54         if ( condition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL) || condition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL) ) {
55             return createNullComparison(condition);
56         }
57         int k = condition.indexOf("{0}");
58         StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc(condition);
59         stringBuffer.replace(k, k + 3, StringUtil.escape(compareTo));
60         return fieldName + " " + stringBuffer.toString();
61     }
62
63     /**
64      * Creates first clause
65      *
66      * @param condition Congruence condition
67      * @param compareTo Number to compare to
68      */

69     public void createFirstClause(String JavaDoc condition, String JavaDoc compareTo) {
70         this.firstCondition = condition;
71         this.firstValue = compareTo;
72         setFirstClause(createClause(condition, compareTo));
73     }
74
75     /**
76      * Creates second clause
77      *
78      * @param condition Congruence condition
79      * @param compareTo Number to compare to
80      * @param logicCopula Logic copula to place between first and second conditions
81      */

82     public void createSecondClause(String JavaDoc condition, String JavaDoc compareTo, String JavaDoc logicCopula) {
83         this.secondCondition = condition;
84         this.secondValue = compareTo;
85         this.logicCopula = logicCopula;
86         setSecondClause(createClause(condition, compareTo), logicCopula);
87     }
88
89     /**
90      * Creates second clause with AND logic copula
91      *
92      * @param condition Congruence condition
93      * @param compareTo Number to compare to
94      */

95     public void createSecondClause(String JavaDoc condition, String JavaDoc compareTo) {
96         createSecondClause(condition, compareTo, FilterConditions.LOGIC_COPULA_AND);
97     }
98
99     /**
100      * Returns first condition
101      *
102      * @return first condition
103      */

104     public String JavaDoc getFirstCondition() {
105         return firstCondition;
106     }
107
108     /**
109      * Returns first value
110      *
111      * @return first value
112      */

113     public String JavaDoc getFirstValue() {
114         return firstValue;
115     }
116
117     /**
118      * Returns second condition
119      *
120      * @return second condition
121      */

122     public String JavaDoc getSecondCondition() {
123         return secondCondition;
124     }
125
126     /**
127      * Returns second value
128      *
129      * @return second value
130      */

131     public String JavaDoc getSecondValue() {
132         return secondValue;
133     }
134
135     /**
136      * Returns logic copula
137      *
138      * @return logic copula
139      */

140     public String JavaDoc getLogicCopula() {
141         return logicCopula;
142     }
143
144 }
145
Popular Tags