View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.match.basic;
19  
20  /**
21   * Base class for match function that match one string value against a given string value.
22   */
23  public abstract class AbstractStringMatchFunctor extends AbstractMatchFunctor {
24  
25      /** String to match for a positive evaluation. */
26      private String matchString;
27  
28      /** Whether the match evaluation is case sensitive. */
29      private boolean caseSensitive;
30  
31      /**
32       * Gets the string to match for a positive evaluation.
33       * 
34       * @return string to match for a positive evaluation
35       */
36      public String getMatchString() {
37          return matchString;
38      }
39  
40      /**
41       * Sets the string to match for a positive evaluation.
42       * 
43       * @param match string to match for a positive evaluation
44       */
45      public void setMatchString(String match) {
46          matchString = match;
47      }
48  
49      /**
50       * Gets whether the match evaluation is case sensitive.
51       * 
52       * @return whether the match evaluation is case sensitive
53       */
54      public boolean isCaseSensitive() {
55          return caseSensitive;
56      }
57  
58      /**
59       * Sets whether the match evaluation is case sensitive.
60       * 
61       * @param isCaseSensitive whether the match evaluation is case sensitive
62       */
63      public void setCaseSensitive(boolean isCaseSensitive) {
64          caseSensitive = isCaseSensitive;
65      }
66  
67      /**
68       * Matches the given value against the provided match string. {@link Object#toString()} is used to produce the
69       * string value to evaluate.
70       * 
71       * @param value the value to evaluate
72       * 
73       * @return true if the value matches the given match string, false if not
74       */
75      protected boolean isMatch(Object value) {
76          if (value == null) {
77              return matchString == null;
78          }
79  
80          if (caseSensitive) {
81              return value.toString().equals(matchString);
82          } else {
83              return value.toString().equalsIgnoreCase(matchString);
84          }
85      }
86  }