View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
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  
17  package edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.match.basic;
18  
19  /**
20   * Base class for match function that match one string value against a given string value.
21   */
22  public abstract class AbstractStringMatchFunctor extends AbstractMatchFunctor {
23  
24      /** String to match for a positive evaluation. */
25      private String matchString;
26  
27      /** Whether the match evaluation is case sensitive. */
28      private boolean caseSensitive;
29  
30      /**
31       * Gets the string to match for a positive evaluation.
32       * 
33       * @return string to match for a positive evaluation
34       */
35      public String getMatchString() {
36          return matchString;
37      }
38  
39      /**
40       * Sets the string to match for a positive evaluation.
41       * 
42       * @param match string to match for a positive evaluation
43       */
44      public void setMatchString(String match) {
45          matchString = match;
46      }
47  
48      /**
49       * Gets whether the match evaluation is case sensitive.
50       * 
51       * @return whether the match evaluation is case sensitive
52       */
53      public boolean isCaseSensitive() {
54          return caseSensitive;
55      }
56  
57      /**
58       * Sets whether the match evaluation is case sensitive.
59       * 
60       * @param isCaseSensitive whether the match evaluation is case sensitive
61       */
62      public void setCaseSensitive(boolean isCaseSensitive) {
63          caseSensitive = isCaseSensitive;
64      }
65  
66      /**
67       * Matches the given value against the provided match string. {@link Object#toString()} is used to produce the
68       * string value to evaluate.
69       * 
70       * @param value the value to evaluate
71       * 
72       * @return true if the value matches the given match string, false if not
73       */
74      protected boolean isMatch(Object value) {
75          if (value == null) {
76              return matchString == null;
77          }
78  
79          if (caseSensitive) {
80              return value.toString().equals(matchString);
81          } else {
82              return value.toString().equalsIgnoreCase(matchString);
83          }
84      }
85  }