directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r679829 - /directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
Date Fri, 25 Jul 2008 15:06:42 GMT
Author: pamarcelot
Date: Fri Jul 25 08:06:41 2008
New Revision: 679829

URL: http://svn.apache.org/viewvc?rev=679829&view=rev
Log:
Reverted a file that sould not have been committed in the last commit.

Modified:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.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=679829&r1=679828&r2=679829&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 Jul 25 08:06:41 2008
@@ -21,18 +21,13 @@
 package org.apache.directory.studio.ldapbrowser.core.jobs;
 
 
-import java.io.BufferedWriter;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.PrintStream;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.naming.InvalidNameException;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.SearchResult;
-
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.ldap.codec.AttributeValueAssertion;
@@ -44,8 +39,7 @@
 import org.apache.directory.shared.ldap.codec.search.NotFilter;
 import org.apache.directory.shared.ldap.codec.search.OrFilter;
 import org.apache.directory.shared.ldap.codec.search.PresentFilter;
-import org.apache.directory.shared.ldap.codec.search.SearchResultDone;
-import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.apache.directory.shared.ldap.codec.search.SearchRequest;
 import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
 import org.apache.directory.shared.ldap.filter.AndNode;
 import org.apache.directory.shared.ldap.filter.ApproximateNode;
@@ -61,18 +55,19 @@
 import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
 import org.apache.directory.shared.ldap.filter.SubstringNode;
-import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.message.ScopeEnum;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
-import org.apache.directory.studio.dsmlv2.reponse.BatchResponseDsml;
-import org.apache.directory.studio.dsmlv2.reponse.SearchResultDoneDsml;
-import org.apache.directory.studio.dsmlv2.reponse.SearchResultEntryDsml;
+import org.apache.directory.studio.dsmlv2.engine.Dsmlv2Engine;
+import org.apache.directory.studio.dsmlv2.request.SearchRequestDsml;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.Control;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
 
 
 /**
@@ -145,27 +140,93 @@
 
         try
         {
-            BatchResponseDsml batchResponse = new BatchResponseDsml();
+            SearchRequest searchRequest = new SearchRequest();
+            searchRequest.setProtocolOP( searchRequest );
+
+            // DN
+            searchRequest.setBaseObject( searchParameter.getSearchBase( ) );
+
+            // Scope
+            SearchScope scope = searchParameter.getScope();
+            if ( scope == SearchScope.OBJECT )
+            {
+                searchRequest.setScope( ScopeEnum.BASE_OBJECT );
+            }
+            else if ( scope == SearchScope.ONELEVEL )
+            {
+                searchRequest.setScope( ScopeEnum.SINGLE_LEVEL );
+            }
+            else if ( scope == SearchScope.SUBTREE )
+            {
+                searchRequest.setScope( ScopeEnum.WHOLE_SUBTREE );
+            }
+
+            // DerefAliases
+            Connection.AliasDereferencingMethod derefAliases = searchParameter.getAliasesDereferencingMethod();
+            switch ( derefAliases )
+            {
+                case ALWAYS:
+                    searchRequest.setDerefAliases( LdapConstants.DEREF_ALWAYS );
+                    break;
+                case FINDING:
+                    searchRequest.setDerefAliases( LdapConstants.DEREF_FINDING_BASE_OBJ );
+                    break;
+                case NEVER:
+                    searchRequest.setDerefAliases( LdapConstants.NEVER_DEREF_ALIASES );
+                    break;
+                case SEARCH:
+                    searchRequest.setDerefAliases( LdapConstants.DEREF_IN_SEARCHING );
+                    break;
+                default:
+                    break;
+            }
 
-            NamingEnumeration<SearchResult> result = SearchRunnable
-                .search( browserConnection, searchParameter, monitor );
+            // Time Limit
+            int timeLimit = searchParameter.getTimeLimit();
+            if ( timeLimit != 0 )
+            {
+                searchRequest.setTimeLimit( timeLimit );
+            }
 
-            while ( result.hasMoreElements() )
+            // Size Limit
+            int countLimit = searchParameter.getCountLimit();
+            if ( countLimit != 0 )
             {
-                SearchResult searchResult = ( SearchResult ) result.nextElement();
-                SearchResultEntryDsml sreDsml = convertToDsmlSearchResult( searchResult );
-                batchResponse.addResponse( sreDsml );
+                searchRequest.setSizeLimit( countLimit );
             }
 
-            batchResponse.addResponse( new SearchResultDoneDsml( new SearchResultDone() )
);
+            // Filter
+            searchRequest.setFilter( convertToSharedLdapFilter( searchParameter.getFilter()
) );
 
-            FileOutputStream fos = new FileOutputStream( exportDsmlFilename );
-            OutputStreamWriter osw = new OutputStreamWriter( fos );
-            BufferedWriter bufferedWriter = new BufferedWriter( osw );
-            bufferedWriter.write( batchResponse.toDsml() );
-            bufferedWriter.close();
-            osw.close();
-            fos.close();
+            // Attributes
+            String[] returningAttributes = searchParameter.getReturningAttributes();
+            for ( int i = 0; i < returningAttributes.length; i++ )
+            {
+                searchRequest.addAttribute( returningAttributes[i] );
+            }
+
+            // Controls
+            List<org.apache.directory.shared.ldap.codec.Control> sharedLdapControls
= convertToSharedLdapControls( searchParameter
+                .getControls() );
+            for ( int i = 0; i < sharedLdapControls.size(); i++ )
+            {
+                searchRequest.addControl( sharedLdapControls.get( i ) );
+            }
+
+            // Executing the request
+            Document xmlRequest = DocumentHelper.createDocument();
+            Element rootElement = xmlRequest.addElement( "batchRequest" );
+            SearchRequestDsml searchRequestDsml = new SearchRequestDsml( searchRequest );
+            searchRequestDsml.toDsml( rootElement );
+            Dsmlv2Engine engine = new Dsmlv2Engine( browserConnection.getConnection().getHost(),
browserConnection
+                .getConnection().getPort(), browserConnection.getConnection().getBindPrincipal(),
browserConnection
+                .getConnection().getBindPassword() );
+            String response = engine.processDSML( xmlRequest.asXML() );
+
+            // Saving the response
+            FileOutputStream fout = new FileOutputStream( exportDsmlFilename );
+            new PrintStream( fout ).println( response );
+            fout.close();
         }
         catch ( Exception e )
         {
@@ -183,26 +244,6 @@
     }
 
 
-    private SearchResultEntryDsml convertToDsmlSearchResult( SearchResult searchResult )
-    {
-        try
-        {
-            SearchResultEntry sre = new SearchResultEntry();
-            sre.setObjectName( new LdapDN( searchResult.getNameInNamespace() ) );
-            sre.setPartialAttributeList( searchResult.getAttributes() );
-
-            return new SearchResultEntryDsml( sre );
-        }
-        catch ( InvalidNameException e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-
-        return null;
-    }
-
-
     /**
      * Converts a String filter into a Shared LDAP Filter.
      *



Mime
View raw message