You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by lu...@apache.org on 2015/01/29 15:27:39 UTC
svn commit: r1655679 - in /directory/shared/trunk/ldap/client/api/src:
main/java/org/apache/directory/ldap/client/api/search/
test/java/org/apache/directory/ldap/client/api/search/
Author: lucastheisen
Date: Thu Jan 29 14:27:38 2015
New Revision: 1655679
URL: http://svn.apache.org/r1655679
Log:
DIRAPI-165: added extensible filter
Added:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilter.java (with props)
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterBuilder.java (with props)
directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterTest.java (with props)
Modified:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java
directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java?rev=1655679&r1=1655678&r2=1655679&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java Thu Jan 29 14:27:38 2015
@@ -65,7 +65,7 @@ import org.apache.directory.api.ldap.mod
/**
- * Creates an equam Filter : ( <attribute> = <value> )
+ * Creates an equal Filter : ( <attribute> = <value> )
*
* @param attribute The AttributeType
* @param value The Value
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java?rev=1655679&r1=1655678&r2=1655679&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java Thu Jan 29 14:27:38 2015
@@ -22,7 +22,7 @@ package org.apache.directory.ldap.client
/**
* A builder for constructing well formed search filters according to
- * <a href="https://tools.ietf.org/html/rfc1960.html">RFC 1960</a>. This
+ * <a href="https://tools.ietf.org/html/rfc4515.html">RFC 4515</a>. This
* builder is most convenient when you use static imports. For example:
* <pre>
* import static org.apache.directory.ldap.client.api.search.FilterBuilder.and;
@@ -47,14 +47,14 @@ package org.apache.directory.ldap.client
public class FilterBuilder
{
/** The built filter */
- private Filter filter;
+ /* No qualifier */ Filter filter;
/**
* A private constructor that creates a new instance of a FilterBuilder
* containing a given filter.
*/
- private FilterBuilder( Filter filter )
+ /* No qualifier*/ FilterBuilder( Filter filter )
{
this.filter = filter;
}
@@ -187,6 +187,58 @@ public class FilterBuilder
/**
+ * Creates an extensible match filter by calling
+ * {@link #extensible(String, String) extensible(null, value)}.
+ *
+ * @param value The value to test for
+ * @return A new MatchingRuleAssertionFilterBuilder
+ */
+ public static MatchingRuleAssertionFilterBuilder extensible( String value )
+ {
+ return new MatchingRuleAssertionFilterBuilder( null, value );
+ }
+
+
+ /**
+ * Creates an extensible match filter. This filter can be used to specify
+ * that dn attributes should be included in the match, which matcher to
+ * use, or that all attributes that support a specific matcher will be
+ * checked. For example:
+ *
+ * <pre>
+ * extensible( "sn", "Barney Rubble" )
+ * .useDnAttributes()
+ * .setMatchingRule( "2.4.6.8.10" )
+ * .toString();
+ * </pre>
+ * would result in the string:
+ * <pre>
+ * (sn:dn:2.4.6.8.10:=Barney Rubble)
+ * </pre>
+ *
+ * Not that the specialized filter builder that is returned <b>IS</b> a
+ * FilterBuilder so it can be chained with other filters. For example:
+ *
+ * <pre>
+ * and(
+ * extensible( "sn", "Rubble" )
+ * .useDnAttributes()
+ * .setMatchingRule( "2.4.6.8.10" ),
+ * equal( "givenName", "Barney" ) )
+ * .toString();
+ * </pre>
+ *
+ * @param attribute The attribute to test
+ * @param value The value to test for
+ * @return A new MatchingRuleAssertionFilterBuilder
+ */
+ public static MatchingRuleAssertionFilterBuilder extensible( String attribute, String value )
+ {
+ return new MatchingRuleAssertionFilterBuilder( attribute, value );
+ }
+
+
+ /**
* Returns a new FilterBuilder for testing lexicographical greater than.
* For example:
*
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java?rev=1655679&r1=1655678&r2=1655679&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java Thu Jan 29 14:27:38 2015
@@ -45,7 +45,8 @@ package org.apache.directory.ldap.client
EQUAL("="),
PRESENT("=*"),
GREATER_THAN_OR_EQUAL(">="),
- LESS_THAN_OR_EQUAL("<=");
+ LESS_THAN_OR_EQUAL("<="),
+ EXTENSIBLE_EQUAL(":=");
/** The String representing the operator in a FIlter */
private String operator;
Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilter.java?rev=1655679&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilter.java (added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilter.java Thu Jan 29 14:27:38 2015
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.ldap.client.api.search;
+
+
+import org.apache.directory.api.ldap.model.filter.FilterEncoder;
+
+
+/**
+ * A class to represent the extensible matching filter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+/* No qualifier*/class MatchingRuleAssertionFilter extends AbstractFilter
+{
+ /** The associated attribute */
+ private String attribute;
+
+ /** The rule to use */
+ private String matchingRule;
+
+ /** The Filter operator */
+ private FilterOperator operator;
+
+ /** Whether or not to include dn attributes in the matching */
+ private boolean useDnAttributes = false;
+
+ /** The filter value */
+ private String value;
+
+
+ /**
+ * Creates a new instance of MatchingRuleAssertionFilter.
+ *
+ * @param attribute The attribute to test
+ * @param value The value to test for
+ * @param operator The FilterOperator
+ */
+ MatchingRuleAssertionFilter( String attribute, String value,
+ FilterOperator operator )
+ {
+ this.attribute = attribute;
+ this.value = value;
+ this.operator = operator;
+ }
+
+
+ /**
+ * Creates a new instance of MatchingRuleAssertionFilter without an attribute.
+ *
+ * @param value The value to test for
+ * @return A new MatchingRuleAssertionFilter
+ */
+ public static MatchingRuleAssertionFilter extensible( String value )
+ {
+ return new MatchingRuleAssertionFilter( null, value,
+ FilterOperator.EXTENSIBLE_EQUAL );
+ }
+
+
+ /**
+ * Creates an extensible filter
+ *
+ * @param attribute The attribute to test
+ * @param value The value to test for
+ * @return A new MatchingRuleAssertionFilter
+ */
+ public static MatchingRuleAssertionFilter extensible( String attribute, String value )
+ {
+ return new MatchingRuleAssertionFilter( attribute, value,
+ FilterOperator.EXTENSIBLE_EQUAL );
+ }
+
+
+ /**
+ * Sets the matching rule to use. Can be either a name or an OID string.
+ *
+ * @param matchingRule The matching rule to use
+ * @return This filter
+ */
+ public MatchingRuleAssertionFilter setMatchingRule( String matchingRule )
+ {
+ this.matchingRule = matchingRule;
+ return this;
+ }
+
+
+ /**
+ * If set, the dn attributes will be included in the matching.
+ *
+ * @return This filter
+ */
+ public MatchingRuleAssertionFilter useDnAttributes()
+ {
+ this.useDnAttributes = true;
+ return this;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public StringBuilder build( StringBuilder builder )
+ {
+ builder.append( "(" );
+ if ( attribute != null )
+ {
+ builder.append( attribute );
+ }
+ if ( useDnAttributes )
+ {
+ builder.append( ":dn" );
+ }
+ if ( matchingRule != null && !matchingRule.isEmpty() )
+ {
+ builder.append( ":" ).append( matchingRule );
+ }
+ return builder.append( operator.operator() )
+ .append( FilterEncoder.encodeFilterValue( value ) ).append( ")" );
+ }
+}
\ No newline at end of file
Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilter.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterBuilder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterBuilder.java?rev=1655679&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterBuilder.java (added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterBuilder.java Thu Jan 29 14:27:38 2015
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.ldap.client.api.search;
+
+
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MatchingRuleAssertionFilterBuilder extends FilterBuilder
+{
+ /**
+ * Creates a new instance of MatchingRuleAssertionFilterBuilder.
+ *
+ * @param attribute The attribute to test
+ * @param value The value to test for
+ */
+ /* No qualifier*/ MatchingRuleAssertionFilterBuilder( String attribute, String value )
+ {
+ super( MatchingRuleAssertionFilter.extensible( attribute, value ) );
+ }
+
+
+ /**
+ * Sets the matching rule to use. Can be either a name or an OID string.
+ *
+ * @param matchingRule The matching rule to use
+ * @return This filter
+ */
+ public MatchingRuleAssertionFilterBuilder setMatchingRule( String matchingRule )
+ {
+ ((MatchingRuleAssertionFilter)filter).setMatchingRule( matchingRule );
+ return this;
+ }
+
+
+ /**
+ * If set, the dn attributes will be included in the matching.
+ *
+ * @return This filter
+ */
+ public MatchingRuleAssertionFilterBuilder useDnAttributes()
+ {
+ ((MatchingRuleAssertionFilter)filter).useDnAttributes();
+ return this;
+ }
+}
\ No newline at end of file
Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterBuilder.java
------------------------------------------------------------------------------
svn:executable = *
Modified: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java?rev=1655679&r1=1655678&r2=1655679&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java (original)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java Thu Jan 29 14:27:38 2015
@@ -25,6 +25,7 @@ import static org.apache.directory.ldap.
import static org.apache.directory.ldap.client.api.search.FilterBuilder.endsWith;
import static org.apache.directory.ldap.client.api.search.FilterBuilder.equal;
import static org.apache.directory.ldap.client.api.search.FilterBuilder.extended;
+import static org.apache.directory.ldap.client.api.search.FilterBuilder.extensible;
import static org.apache.directory.ldap.client.api.search.FilterBuilder.not;
import static org.apache.directory.ldap.client.api.search.FilterBuilder.or;
import static org.apache.directory.ldap.client.api.search.FilterBuilder.startsWith;
@@ -144,6 +145,16 @@ public class FilterBuilderTest
{
assertEquals( "(objectClass=*)", extended( everything() ).toString() );
}
+
+
+ @Test
+ public void testExtensible()
+ {
+ assertEquals( "(cn:caseExactMatch:=Fred Flintstone)",
+ extensible( "cn", "Fred Flintstone" )
+ .setMatchingRule( "caseExactMatch" ).toString() );
+ }
+
public static class EverythingFilter implements Filter
{
Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterTest.java?rev=1655679&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterTest.java (added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterTest.java Thu Jan 29 14:27:38 2015
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldap.client.api.search;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.apache.directory.ldap.client.api.search.FilterBuilder.extensible;
+
+import org.junit.Test;
+
+
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MatchingRuleAssertionFilterTest
+{
+ @Test
+ public void testExtensible()
+ {
+ assertEquals( "(cn:caseExactMatch:=Fred Flintstone)",
+ extensible( "cn", "Fred Flintstone" )
+ .setMatchingRule( "caseExactMatch" ).toString() );
+ assertEquals( "(cn:=Betty Rubble)",
+ extensible( "cn", "Betty Rubble" ).toString() );
+ assertEquals( "(sn:dn:2.4.6.8.10:=Barney Rubble)",
+ extensible( "sn", "Barney Rubble" )
+ .useDnAttributes()
+ .setMatchingRule( "2.4.6.8.10" ).toString() );
+ assertEquals( "(o:dn:=Ace Industry)",
+ extensible( "o", "Ace Industry" )
+ .useDnAttributes().toString() );
+ assertEquals( "(:1.2.3:=Wilma Flintstone)",
+ extensible( "Wilma Flintstone" )
+ .setMatchingRule( "1.2.3" ).toString() );
+ assertEquals( "(:dn:2.4.6.8.10:=Dino)",
+ extensible( "Dino" )
+ .useDnAttributes()
+ .setMatchingRule( "2.4.6.8.10" ).toString() );
+ }
+}
Propchange: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/MatchingRuleAssertionFilterTest.java
------------------------------------------------------------------------------
svn:executable = *