2
* Copyright 2005-2008 the original author or authors.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
package org.springframework.ldap.filter;
18
import org.springframework.util.StringUtils;
21
* Allows hardcoded parts to be included in a search filter. Particularly useful
22
* if some filters are specified in configuration files and these should be
23
* combined with other ones.
26
* Filter filter = new HardcodedFilter("(&(objectClass=user)(!(objectClass=computer)))");
27
* System.out.println(filter.toString());
31
* <code>(&(objectClass=user)(!(objectClass=computer)))</code>
33
* <b>Note 1</b>: If the definition is in XML you will need to properly encode any special characters so that they are valid in an XML file,
34
* e.g. "&" needs to be encoded as "&amp;", e.g.
36
* <bean class="MyClass">
37
* <property name="filter" value="(&amp;(objectClass=user)(!(objectClass=computer)))" />
42
* <b>Note 2</b>: There will be no validation to ensure that the supplied filter is
43
* valid. Using this implementation to build filters from user input is strongly
46
* @author Justen Stepka
47
* @author Mathieu Larchet
49
public class HardcodedFilter extends AbstractFilter {
51
private String filter;
54
* The hardcoded string to be used for this filter.
55
* @param filter the hardcoded filter string.
57
public HardcodedFilter(String filter) {
63
* @see org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer)
65
public StringBuffer encode(StringBuffer buff) {
66
if (!StringUtils.hasLength(filter)) {