View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.dsmlv2.request;
21  
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  
27  /**
28   * A Object that stores the substring filter. 
29   * 
30   * A substring filter follow this
31   * grammar : 
32   * 
33   * substring = attr "=" ( ([initial] any [final] | 
34   *                        (initial [any] [final) | 
35   *                        ([initial] [any] final) ) 
36   *                       
37   * initial = value 
38   * any = "*" *(value "*")
39   * final = value
40   * 
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  public class SubstringFilter extends Filter
44  {
45      /** The substring filter type (an attributeDescription) */
46      private String type;
47  
48      /** The initial filter */
49      private String initialSubstrings;
50  
51      /** The any filter. It's a list of LdapString */
52      private List<String> anySubstrings = new ArrayList<String>( 1 );
53  
54      /** The final filter */
55      private String finalSubstrings;
56  
57  
58      /**
59       * Get the internal substrings
60       * 
61       * @return Returns the anySubstrings.
62       */
63      public List<String> getAnySubstrings()
64      {
65          return anySubstrings;
66      }
67  
68  
69      /**
70       * Add a internal substring
71       * 
72       * @param any The anySubstrings to set.
73       */
74      public void addAnySubstrings( String any )
75      {
76          this.anySubstrings.add( any );
77      }
78  
79  
80      /**
81       * Get the final substring
82       * 
83       * @return Returns the finalSubstrings.
84       */
85      public String getFinalSubstrings()
86      {
87          return finalSubstrings;
88      }
89  
90  
91      /**
92       * Set the final substring
93       * 
94       * @param finalSubstrings The finalSubstrings to set.
95       */
96      public void setFinalSubstrings( String finalSubstrings )
97      {
98          this.finalSubstrings = finalSubstrings;
99      }
100 
101 
102     /**
103      * Get the initial substring
104      * 
105      * @return Returns the initialSubstrings.
106      */
107     public String getInitialSubstrings()
108     {
109         return initialSubstrings;
110     }
111 
112 
113     /**
114      * Set the initial substring
115      * 
116      * @param initialSubstrings The initialSubstrings to set.
117      */
118     public void setInitialSubstrings( String initialSubstrings )
119     {
120         this.initialSubstrings = initialSubstrings;
121     }
122 
123 
124     /**
125      * Get the attribute
126      * 
127      * @return Returns the type.
128      */
129     public String getType()
130     {
131         return type;
132     }
133 
134 
135     /**
136      * Set the attribute to match
137      * 
138      * @param type The type to set.
139      */
140     public void setType( String type )
141     {
142         this.type = type;
143     }
144 
145 
146     /**
147      * Return a string compliant with RFC 2254 representing a Substring filter
148      * 
149      * @return The substring filter string
150      */
151     public String toString()
152     {
153 
154         StringBuffer sb = new StringBuffer();
155 
156         if ( initialSubstrings != null )
157         {
158             sb.append( initialSubstrings );
159         }
160 
161         sb.append( '*' );
162 
163         if ( anySubstrings != null )
164         {
165             for ( String any : anySubstrings )
166             {
167                 sb.append( any ).append( '*' );
168             }
169         }
170 
171         if ( finalSubstrings != null )
172         {
173             sb.append( finalSubstrings );
174         }
175 
176         return sb.toString();
177     }
178 }