directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r694733 - in /directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs: ExportDsmlJob.java ImportDsmlJob.java
Date Fri, 12 Sep 2008 16:45:49 GMT
Author: pamarcelot
Date: Fri Sep 12 09:45:48 2008
New Revision: 694733

URL: http://svn.apache.org/viewvc?rev=694733&view=rev
Log:
Added support for the Search Request.

Modified:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlJob.java

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java?rev=694733&r1=694732&r2=694733&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
Fri Sep 12 09:45:48 2008
@@ -192,6 +192,24 @@
         // Creating the batch reponse
         BatchResponseDsml batchResponse = new BatchResponseDsml();
 
+        processAsDsmlResponse( ne, batchResponse );
+
+        // Returning the associated DSML
+        return batchResponse.toDsml();
+    }
+
+
+    /**
+     * Processes the {@link NamingEnumeration} as a DSML response.
+     *
+     * @param ne
+     *      the naming enumeration
+     * @throws InvalidNameException 
+     * @throws InvalidAttributeIdentifierException 
+     */
+    public static void processAsDsmlResponse( NamingEnumeration<SearchResult> ne, BatchResponseDsml
batchResponse )
+        throws InvalidAttributeIdentifierException, InvalidNameException
+    {
         // Creating and adding the search response
         SearchResponseDsml sr = new SearchResponseDsml();
         batchResponse.addResponse( sr );
@@ -210,9 +228,6 @@
         ldapResult.setResultCode( ResultCodeEnum.SUCCESS );
         srd.setLdapResult( ldapResult );
         sr.addResponse( new SearchResultDoneDsml( srd ) );
-
-        // Returning the associated DSML
-        return batchResponse.toDsml();
     }
 
 
@@ -226,7 +241,7 @@
      * @throws InvalidNameException 
      * @throws InvalidAttributeIdentifierException 
      */
-    private SearchResultEntryDsml convertToSearchResultEntryDsml( SearchResult searchResult
)
+    private static SearchResultEntryDsml convertToSearchResultEntryDsml( SearchResult searchResult
)
         throws InvalidAttributeIdentifierException, InvalidNameException
     {
         SearchResultEntryDsml sre = new SearchResultEntryDsml();

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlJob.java?rev=694733&r1=694732&r2=694733&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlJob.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlJob.java
Fri Sep 12 09:45:48 2008
@@ -29,10 +29,14 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.naming.InvalidNameException;
 import javax.naming.directory.DirContext;
+import javax.naming.directory.InvalidAttributeIdentifierException;
 import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
 
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapResult;
 import org.apache.directory.shared.ldap.codec.add.AddRequest;
 import org.apache.directory.shared.ldap.codec.bind.BindRequest;
@@ -43,12 +47,15 @@
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
 import org.apache.directory.shared.ldap.codec.search.SearchRequest;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
 import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
+import org.apache.directory.studio.connection.core.io.jndi.StudioNamingEnumeration;
 import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
 import org.apache.directory.studio.dsmlv2.reponse.AddResponseDsml;
@@ -226,8 +233,11 @@
      *      the request
      * @param batchResponseDsml
      *      the DSML batch response (can be <code>null</code>)
+     * @throws InvalidNameException 
+     * @throws InvalidAttributeIdentifierException 
      */
     private void processRequest( Object request, BatchResponseDsml batchResponseDsml, StudioProgressMonitor
monitor )
+        throws InvalidAttributeIdentifierException, InvalidNameException
     {
         if ( request instanceof BindRequest )
         {
@@ -484,12 +494,103 @@
      *      the request
      * @param batchResponseDsml
      *      the DSML batch response (can be <code>null</code>)
+     * @throws InvalidNameException 
+     * @throws InvalidAttributeIdentifierException 
      */
     private void processSearchRequest( SearchRequest request, BatchResponseDsml batchResponseDsml,
-        StudioProgressMonitor monitor )
+        StudioProgressMonitor monitor ) throws InvalidAttributeIdentifierException, InvalidNameException
+    {
+        // Creating the response
+        if ( batchResponseDsml != null )
+        {
+            // [Optimization] We're only searching if we need to produce a response
+            StudioNamingEnumeration ne = browserConnection.getConnection().getJNDIConnectionWrapper().search(
+                request.getBaseObject().toString(), request.getFilter().toString(), getSearchControls(
request ),
+                getAliasDereferencingMethod( request ), ReferralHandlingMethod.IGNORE, null,
monitor, null );
+
+            ExportDsmlJob.processAsDsmlResponse( ne, batchResponseDsml );
+        }
+    }
+
+
+    /**
+     * Returns the {@link SearchControls} object associated with the request.
+     *
+     * @param request
+     *      the search request
+     * @return
+     *      the associated {@link SearchControls} object
+     */
+    private SearchControls getSearchControls( SearchRequest request )
     {
-        // TODO Auto-generated method stub
+        SearchControls controls = new SearchControls();
 
+        // Scope
+        switch ( request.getScope() )
+        {
+            case OBJECT:
+                controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+                break;
+            case ONELEVEL:
+                controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+                break;
+            case SUBTREE:
+                controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+                break;
+            default:
+                controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        }
+
+        // Returning attributes
+        List<String> returningAttributes = new ArrayList<String>();
+        for ( EntryAttribute entryAttribute : request.getAttributes() )
+        {
+            returningAttributes.add( entryAttribute.getId() );
+        }
+        // If the returning attributes are empty, we need to return the user attributes
+        // [Cf. RFC 2251 - "There are two special values which may be used: an empty 
+        //  list with no attributes, and the attribute description string '*'.  Both of 
+        // these signify that all user attributes are to be returned."]
+        if ( returningAttributes.size() == 0 )
+        {
+            returningAttributes.add( "*" );
+        }
+
+        controls.setReturningAttributes( returningAttributes.toArray( new String[0] ) );
+
+        // Size Limit
+        controls.setCountLimit( request.getSizeLimit() );
+
+        // Time Limit
+        controls.setTimeLimit( request.getTimeLimit() );
+
+        return controls;
+    }
+
+
+    /**
+     * Returns the {@link AliasDereferencingMethod} object associated with the request.
+     *
+     * @param request
+     *      the search request
+     * @return
+     *      the associated {@link AliasDereferencingMethod} object
+     */
+    private AliasDereferencingMethod getAliasDereferencingMethod( SearchRequest request )
+    {
+        switch ( request.getDerefAliases() )
+        {
+            case LdapConstants.NEVER_DEREF_ALIASES:
+                return AliasDereferencingMethod.NEVER;
+            case LdapConstants.DEREF_ALWAYS:
+                return AliasDereferencingMethod.ALWAYS;
+            case LdapConstants.DEREF_FINDING_BASE_OBJ:
+                return AliasDereferencingMethod.FINDING;
+            case LdapConstants.DEREF_IN_SEARCHING:
+                return AliasDereferencingMethod.SEARCH;
+            default:
+                return AliasDereferencingMethod.NEVER;
+        }
     }
 
 



Mime
View raw message