You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2023/12/05 22:55:58 UTC

(directory-ldap-api) 01/02: o Added a method SearchRequest.setFilter(SchemaManager, String) o Fixed the DSML generation of binary values

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git

commit 8a4dc293a4387bcec86f6788678a48b92fa8c28c
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Tue Dec 5 23:46:34 2023 +0100

    o Added a method SearchRequest.setFilter(SchemaManager, String)
    o Fixed the DSML generation of binary values
---
 .../api/dsmlv2/request/SearchRequestDsml.java        | 19 ++++++++++++++++---
 .../api/ldap/model/message/SearchRequest.java        | 12 ++++++++++++
 .../api/ldap/model/message/SearchRequestImpl.java    | 20 ++++++++++++++++++++
 3 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java b/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
index f2006659c..d64420a4c 100644
--- a/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
+++ b/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/SearchRequestDsml.java
@@ -55,6 +55,7 @@ import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.api.ldap.model.message.SearchResultDone;
 import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.api.util.Strings;
 import org.dom4j.Element;
 import org.dom4j.Namespace;
@@ -568,7 +569,7 @@ public class SearchRequestDsml
                     element.getDocument().getRootElement().add( xsiNamespace );
 
                     Element valueElement = newElement.addElement( DsmlLiterals.VALUE ).addText(
-                        ParserUtils.base64Encode( value ) );
+                        ParserUtils.base64Encode( value.getBytes() ) );
                     valueElement
                         .addAttribute( new QName( DsmlLiterals.TYPE, xsiNamespace ), ParserUtils.XSD_COLON + ParserUtils.BASE64BINARY );
                 }
@@ -592,7 +593,7 @@ public class SearchRequestDsml
             
             if ( value != null )
             {
-                if ( ParserUtils.needsBase64Encoding( value ) )
+                if ( !value.isHumanReadable() )
                 {
                     Namespace xsdNamespace = new Namespace( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI );
                     Namespace xsiNamespace = new Namespace( ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI );
@@ -600,7 +601,7 @@ public class SearchRequestDsml
                     element.getDocument().getRootElement().add( xsiNamespace );
 
                     Element valueElement = newElement.addElement( DsmlLiterals.VALUE ).addText(
-                        ParserUtils.base64Encode( value.getString() ) );
+                        ParserUtils.base64Encode( value.getBytes() ) );
                     valueElement.addAttribute( new QName( DsmlLiterals.TYPE, xsiNamespace ), ParserUtils.XSD_COLON + ParserUtils.BASE64BINARY );
                 }
                 else
@@ -800,6 +801,18 @@ public class SearchRequestDsml
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public SearchRequest setFilter( SchemaManager schemaManager, String filter ) throws LdapException
+    {
+        getDecorated().setFilter( schemaManager, filter );
+
+        return this;
+    }
+
+
     /**
      * {@inheritDoc}
      */
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
index ed6f3716e..a95070334 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequest.java
@@ -25,6 +25,7 @@ import java.util.List;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.filter.ExprNode;
 import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
 
 
 /**
@@ -207,6 +208,17 @@ public interface SearchRequest extends ManyReplyRequest, AbandonableRequest
     SearchRequest setFilter( String filter ) throws LdapException;
 
 
+    /**
+     * Sets the search filter associated with this search request.
+     * 
+     * @param schemaManager the SchemaManager instance
+     * @param filter the expression node for the root of the filter expression tree.
+     * @return The SearchRequest instance
+     * @throws LdapException If the filter can't be added
+     */
+    SearchRequest setFilter( SchemaManager schemaManager, String filter ) throws LdapException;
+
+
     /**
      * Gets a list of the attributes to be returned from each entry which
      * matches the search filter. There are two special values which may be
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java
index d8462f228..4bcd31668 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchRequestImpl.java
@@ -33,6 +33,7 @@ import org.apache.directory.api.ldap.model.filter.BranchNormalizedVisitor;
 import org.apache.directory.api.ldap.model.filter.ExprNode;
 import org.apache.directory.api.ldap.model.filter.FilterParser;
 import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
 
 
 /**
@@ -188,6 +189,25 @@ public class SearchRequestImpl extends AbstractAbandonableRequest implements Sea
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public SearchRequest setFilter( SchemaManager schemaManager, String filter ) throws LdapException
+    {
+        try
+        {
+            filterNode = FilterParser.parse( schemaManager, filter );
+        }
+        catch ( ParseException pe )
+        {
+            throw new LdapInvalidSearchFilterException( I18n.err( I18n.ERR_13508_INVALID_FILTER, filter, pe.getMessage() ) );
+        }
+
+        return this;
+    }
+
+
     /**
      * {@inheritDoc}
      */