~hudson-ubuntu/ubuntu/natty/libspring-ldap-java/hudson-fix

« back to all changes in this revision

Viewing changes to dist/module-sources/spring-ldap-core/org/springframework/ldap/filter/HardcodedFilter.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-04-16 20:36:56 UTC
  • Revision ID: james.westby@ubuntu.com-20100416203656-257w9tnqwmpmcgv5
Tags: upstream-1.3.0.RELEASE
ImportĀ upstreamĀ versionĀ 1.3.0.RELEASE

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2005-2008 the original author or authors.
 
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 org.springframework.ldap.filter;
 
17
 
 
18
import org.springframework.util.StringUtils;
 
19
 
 
20
/**
 
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.
 
24
 * 
 
25
 * <pre>
 
26
 * Filter filter = new HardcodedFilter(&quot;(&amp;(objectClass=user)(!(objectClass=computer)))&quot;);
 
27
 * System.out.println(filter.toString());
 
28
 * </pre>
 
29
 * 
 
30
 * would result in:
 
31
 * <code>(&amp;(objectClass=user)(!(objectClass=computer)))</code>
 
32
 * <p>
 
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. &quot;&amp;&quot; needs to be encoded as &quot;&amp;amp;&quot;, e.g.
 
35
 * <pre>
 
36
 * &lt;bean class="MyClass"&gt;
 
37
 *   &lt;property name="filter" value="(&amp;amp;(objectClass=user)(!(objectClass=computer)))" /&gt;
 
38
 * &lt;/bean&gt;
 
39
 * </pre>
 
40
 * </p>
 
41
 * <p>
 
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
 
44
 * discouraged.
 
45
 * </p>
 
46
 * @author Justen Stepka
 
47
 * @author Mathieu Larchet
 
48
 */
 
49
public class HardcodedFilter extends AbstractFilter {
 
50
 
 
51
        private String filter;
 
52
 
 
53
        /**
 
54
         * The hardcoded string to be used for this filter.
 
55
         * @param filter the hardcoded filter string.
 
56
         */
 
57
        public HardcodedFilter(String filter) {
 
58
                this.filter = filter;
 
59
        }
 
60
 
 
61
        /*
 
62
         * (non-Javadoc)
 
63
         * @see org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer)
 
64
         */
 
65
        public StringBuffer encode(StringBuffer buff) {
 
66
                if (!StringUtils.hasLength(filter)) {
 
67
                        return buff;
 
68
                }
 
69
 
 
70
                buff.append(filter);
 
71
                return buff;
 
72
        }
 
73
}