directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488345 [8/12] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-core/ ldapstudio-browser-core/META-INF/ ldapstudio-browser-core/about_files/ ldapstudio-browser-core/lib/ ldapstudio-browser-core/src/ ldapstudio-browser-core/...
Date Mon, 18 Dec 2006 17:15:08 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteAttributesValueJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteAttributesValueJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteAttributesValueJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteAttributesValueJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,155 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.AttributeDeletedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.ValueDeletedEvent;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+
+
+public class DeleteAttributesValueJob extends AbstractModificationJob
+{
+
+    private IEntry entry;
+
+    private IAttribute[] attributes;
+
+    private IValue[] values;
+
+    private EntryModificationEvent event;
+
+
+    public DeleteAttributesValueJob( IAttribute attributes[], IValue[] values )
+    {
+        this.attributes = attributes;
+        this.values = values;
+        for ( int i = 0; attributes != null && i < attributes.length; i++ )
+        {
+            if ( this.entry == null )
+            {
+                this.entry = attributes[i].getEntry();
+            }
+        }
+        for ( int i = 0; values != null && i < values.length; i++ )
+        {
+            if ( this.entry == null )
+            {
+                this.entry = values[i].getAttribute().getEntry();
+            }
+        }
+
+        setName( attributes.length + values.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_name_1
+            : BrowserCoreMessages.jobs__delete_attributes_name_n );
+    }
+
+
+    public DeleteAttributesValueJob( AttributeHierachie ah )
+    {
+        this( ah.getAttributes(), new IValue[0] );
+    }
+
+
+    public DeleteAttributesValueJob( IValue value )
+    {
+        this( new IAttribute[0], new IValue[]
+            { value } );
+    }
+
+
+    protected void executeAsyncModificationJob( ExtendedProgressMonitor monitor ) throws ModelModificationException
+    {
+
+        monitor.beginTask( attributes.length + values.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_task_1
+            : BrowserCoreMessages.jobs__delete_attributes_task_n, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        for ( int i = 0; attributes != null && i < attributes.length; i++ )
+        {
+            attributes[i].getEntry().deleteAttribute( attributes[i], this );
+        }
+        for ( int i = 0; values != null && i < values.length; i++ )
+        {
+            values[i].getAttribute().deleteValue( values[i], this );
+        }
+
+        entry.getConnection().delete( attributes, monitor );
+        entry.getConnection().delete( values, monitor );
+
+        if ( values.length > 0 )
+        {
+            this.event = new ValueDeletedEvent( entry.getConnection(), entry, values[0].getAttribute(), values[0], this );
+        }
+        else if ( attributes.length > 0 )
+        {
+            this.event = new AttributeDeletedEvent( entry.getConnection(), entry, attributes[0], this );
+        }
+    }
+
+
+    protected IEntry getModifiedEntry()
+    {
+        return entry;
+    }
+
+
+    protected String[] getAffectedAttributeNames()
+    {
+        Set affectedAttributeNameSet = new HashSet();
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+            affectedAttributeNameSet.add( attributes[i].getDescription() );
+        }
+        for ( int i = 0; i < values.length; i++ )
+        {
+            affectedAttributeNameSet.add( values[i].getAttribute().getDescription() );
+        }
+        return ( String[] ) affectedAttributeNameSet.toArray( new String[affectedAttributeNameSet.size()] );
+    }
+
+
+    protected void runNotification()
+    {
+        if ( this.event != null )
+        {
+            EventRegistry.fireEntryUpdated( this.event, this );
+        }
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return attributes.length + values.length == 1 ? BrowserCoreMessages.jobs__delete_attributes_error_1
+            : BrowserCoreMessages.jobs__delete_attributes_error_n;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteEntriesJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteEntriesJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/DeleteEntriesJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,234 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.ChildrenInitializedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Search;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+
+
+public class DeleteEntriesJob extends AbstractAsyncBulkJob
+{
+
+    private IEntry[] entriesToDelete;
+
+    private Set entriesToUpdateSet = new HashSet();
+
+    private Set searchesToUpdateSet = new HashSet();
+
+
+    public DeleteEntriesJob( final IEntry[] entriesToDelete )
+    {
+        this.entriesToDelete = entriesToDelete;
+        setName( entriesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_entries_name_1
+            : BrowserCoreMessages.jobs__delete_entries_name_n );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        IConnection[] connections = new IConnection[entriesToDelete.length];
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            connections[i] = entriesToDelete[i].getConnection();
+        }
+        return connections;
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.addAll( Arrays.asList( entriesToDelete ) );
+        return l.toArray();
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( entriesToDelete.length == 1 ? BrowserCoreMessages.bind(
+            BrowserCoreMessages.jobs__delete_entries_task_1, new String[]
+                { entriesToDelete[0].getDn().toString() } ) : BrowserCoreMessages.bind(
+            BrowserCoreMessages.jobs__delete_entries_task_n, new String[]
+                { Integer.toString( entriesToDelete.length ) } ), 2 + entriesToDelete.length );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        int num = 0;
+        for ( int i = 0; !monitor.isCanceled() && i < entriesToDelete.length; i++ )
+        {
+
+            IEntry entryToDelete = entriesToDelete[i];
+            IConnection connection = entryToDelete.getConnection();
+
+            // delete from directory
+            // TODO: use TreeDelete Control, if available
+            num = deleteEntryRecursive( entryToDelete, false, num, monitor );
+
+            // delete from parent
+            entryToDelete.getParententry().deleteChild( entryToDelete, connection );
+            entriesToUpdateSet.add( entryToDelete.getParententry() );
+
+            // delete from searches
+            ISearch[] searches = connection.getSearchManager().getSearches();
+            for ( int j = 0; j < searches.length; j++ )
+            {
+                ISearch search = searches[j];
+                if ( search.getSearchResults() != null )
+                {
+                    ISearchResult[] searchResults = search.getSearchResults();
+                    for ( int k = 0; k < searchResults.length; k++ )
+                    {
+                        ISearchResult result = searchResults[k];
+                        if ( entryToDelete.equals( result.getEntry() ) )
+                        {
+                            ISearchResult[] newsrs = new ISearchResult[searchResults.length - 1];
+                            System.arraycopy( searchResults, 0, newsrs, 0, k );
+                            System.arraycopy( searchResults, k + 1, newsrs, k, searchResults.length - k - 1 );
+                            search.setSearchResults( newsrs );
+                            searchResults = newsrs;
+                            k--;
+                            searchesToUpdateSet.add( search );
+                        }
+                    }
+                }
+            }
+
+            monitor.worked( 1 );
+        }
+    }
+
+
+    private int deleteEntryRecursive( IEntry entry, boolean refInitialized, int numberOfDeletedEntries,
+        ExtendedProgressMonitor monitor )
+    {
+        try
+        {
+
+            int numberInBatch;
+            do
+            {
+                numberInBatch = 0;
+
+                SearchParameter subParam = new SearchParameter();
+                subParam.setSearchBase( entry.getDn() );
+                subParam.setFilter( ISearch.FILTER_TRUE );
+                subParam.setScope( ISearch.SCOPE_ONELEVEL );
+                subParam.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
+                subParam.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
+                subParam.setReturningAttributes( new String[]
+                    { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
+                subParam.setCountLimit( 100 );
+                ISearch search = new Search( entry.getConnection(), subParam );
+                entry.getConnection().search( search, monitor );
+
+                ISearchResult[] srs = search.getSearchResults();
+                for ( int i = 0; !monitor.isCanceled() && srs != null && i < srs.length; i++ )
+                {
+                    IEntry childEntry = srs[i].getEntry();
+                    numberOfDeletedEntries = this.deleteEntryRecursive( childEntry, true, numberOfDeletedEntries,
+                        monitor );
+                    numberInBatch++;
+                }
+            }
+            while ( numberInBatch > 0 && !monitor.isCanceled() && !monitor.errorsReported() );
+
+            if ( !monitor.isCanceled() && !monitor.errorsReported() )
+            {
+
+                // check for referrals
+                if ( !refInitialized )
+                {
+                    SearchParameter param = new SearchParameter();
+                    param.setSearchBase( entry.getDn() );
+                    param.setFilter( ISearch.FILTER_TRUE );
+                    param.setScope( ISearch.SCOPE_OBJECT );
+                    param.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
+                    param.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
+                    param.setReturningAttributes( new String[]
+                        { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
+                    ISearch search = new Search( entry.getConnection(), param );
+                    entry.getConnection().search( search, monitor );
+
+                    ISearchResult[] srs = search.getSearchResults();
+                    if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
+                    {
+                        entry = srs[0].getEntry();
+                    }
+                }
+
+                entry.getConnection().delete( entry, monitor );
+
+                numberOfDeletedEntries++;
+                monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__deleted_n_entries,
+                    new String[]
+                        { "" + numberOfDeletedEntries } ) ); //$NON-NLS-1$
+            }
+
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+
+        return numberOfDeletedEntries;
+    }
+
+
+    protected void runNotification()
+    {
+        for ( Iterator it = entriesToUpdateSet.iterator(); it.hasNext(); )
+        {
+            IEntry parent = ( IEntry ) it.next();
+            EventRegistry.fireEntryUpdated( new ChildrenInitializedEvent( parent, parent.getConnection() ), this );
+        }
+        for ( Iterator it = searchesToUpdateSet.iterator(); it.hasNext(); )
+        {
+            ISearch search = ( ISearch ) it.next();
+            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( search, SearchUpdateEvent.SEARCH_PERFORMED ), this );
+        }
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return entriesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_entries_error_1
+            : BrowserCoreMessages.jobs__delete_entries_error_n;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExecuteLdifJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExecuteLdifJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExecuteLdifJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExecuteLdifJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,119 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
+
+
+public class ExecuteLdifJob extends AbstractEclipseJob
+{
+
+    private IConnection connection;
+
+    private String ldif;
+
+    private boolean continueOnError;
+
+
+    public ExecuteLdifJob( IConnection connection, String ldif, boolean continueOnError )
+    {
+        this.connection = connection;
+        this.ldif = ldif;
+        this.continueOnError = continueOnError;
+
+        setName( BrowserCoreMessages.jobs__execute_ldif_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { connection };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( ldif ) );
+        return l.toArray();
+    }
+
+
+    protected void executeAsyncJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__execute_ldif_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        try
+        {
+            Reader ldifReader = new StringReader( this.ldif );
+            LdifParser parser = new LdifParser();
+            LdifEnumeration enumeration = parser.parse( ldifReader );
+
+            Writer logWriter = new Writer()
+            {
+                public void close()
+                {
+                }
+
+
+                public void flush()
+                {
+                }
+
+
+                public void write( char[] cbuf, int off, int len )
+                {
+                }
+            };
+
+            connection.importLdif( enumeration, logWriter, continueOnError, monitor );
+
+            logWriter.close();
+            ldifReader.close();
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__execute_ldif_error;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,316 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ConnectionException;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralException;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+import org.eclipse.core.runtime.Preferences;
+
+
+public class ExportCsvJob extends AbstractEclipseJob
+{
+
+    private String exportLdifFilename;
+
+    private IConnection connection;
+
+    private SearchParameter searchParameter;
+
+    private boolean exportDn;
+
+
+    public ExportCsvJob( String exportLdifFilename, IConnection connection, SearchParameter searchParameter,
+        boolean exportDn )
+    {
+        this.exportLdifFilename = exportLdifFilename;
+        this.connection = connection;
+        this.searchParameter = searchParameter;
+        this.exportDn = exportDn;
+
+        setName( BrowserCoreMessages.jobs__export_csv_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { connection };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
+        return l.toArray();
+    }
+
+
+    protected void executeAsyncJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__export_csv_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
+
+        String attributeDelimiter = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER );
+        String valueDelimiter = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER );
+        String quoteCharacter = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER );
+        String lineSeparator = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR );
+        String encoding = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING );
+        int binaryEncoding = coreStore.getInt( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING );
+        String[] exportAttributes = this.searchParameter.getReturningAttributes();
+
+        try
+        {
+            // open file
+            FileOutputStream fos = new FileOutputStream( exportLdifFilename );
+            OutputStreamWriter osw = new OutputStreamWriter( fos, encoding );
+            BufferedWriter bufferedWriter = new BufferedWriter( osw );
+
+            // header
+            if ( this.exportDn )
+            {
+                bufferedWriter.write( "dn" ); //$NON-NLS-1$
+                if ( exportAttributes == null || exportAttributes.length > 0 )
+                    bufferedWriter.write( attributeDelimiter );
+            }
+            for ( int i = 0; i < exportAttributes.length; i++ )
+            {
+                bufferedWriter.write( exportAttributes[i] );
+                if ( i + 1 < exportAttributes.length )
+                    bufferedWriter.write( attributeDelimiter );
+            }
+            bufferedWriter.write( BrowserCoreConstants.LINE_SEPARATOR );
+
+            // export
+            int count = 0;
+            export( connection, searchParameter, bufferedWriter, count, monitor, exportAttributes, attributeDelimiter,
+                valueDelimiter, quoteCharacter, lineSeparator, binaryEncoding, exportDn );
+
+            // close file
+            bufferedWriter.close();
+            osw.close();
+            fos.close();
+
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    private static void export( IConnection connection, SearchParameter searchParameter, BufferedWriter bufferedWriter,
+        int count, ExtendedProgressMonitor monitor, String[] attributes, String attributeDelimiter,
+        String valueDelimiter, String quoteCharacter, String lineSeparator, int binaryEncoding, boolean exportDn )
+        throws IOException, ConnectionException
+    {
+        try
+        {
+
+            LdifEnumeration enumeration = connection.exportLdif( searchParameter, monitor );
+            while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
+            {
+                LdifContainer container = enumeration.next( monitor );
+
+                if ( container instanceof LdifContentRecord )
+                {
+
+                    LdifContentRecord record = ( LdifContentRecord ) container;
+                    bufferedWriter.write( recordToCsv( record, attributes, attributeDelimiter, valueDelimiter,
+                        quoteCharacter, lineSeparator, binaryEncoding, exportDn ) );
+
+                    count++;
+                    monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
+                        new String[]
+                            { Integer.toString( count ) } ) );
+                }
+            }
+        }
+        catch ( ConnectionException ce )
+        {
+
+            if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
+            {
+                // nothing
+            }
+            else if ( ce instanceof ReferralException )
+            {
+
+                if ( searchParameter.getReferralsHandlingMethod() == IConnection.HANDLE_REFERRALS_FOLLOW )
+                {
+
+                    ReferralException re = ( ReferralException ) ce;
+                    ISearch[] referralSearches = re.getReferralSearches();
+                    for ( int i = 0; i < referralSearches.length; i++ )
+                    {
+                        ISearch referralSearch = referralSearches[i];
+
+                        // open connection
+                        if ( !referralSearch.getConnection().isOpened() )
+                        {
+                            referralSearch.getConnection().open( monitor );
+                        }
+
+                        // export recursive
+                        export( referralSearch.getConnection(), referralSearch.getSearchParameter(), bufferedWriter,
+                            count, monitor, attributes, attributeDelimiter, valueDelimiter, quoteCharacter,
+                            lineSeparator, binaryEncoding, exportDn );
+                    }
+                }
+            }
+            else
+            {
+                monitor.reportError( ce );
+            }
+        }
+
+    }
+
+
+    private static String recordToCsv( LdifContentRecord record, String[] attributes, String attributeDelimiter,
+        String valueDelimiter, String quoteCharacter, String lineSeparator, int binaryEncoding, boolean exportDn )
+    {
+
+        // group multi-valued attributes
+        Map attributeMap = getAttributeMap( record, valueDelimiter, binaryEncoding );
+
+        // print attributes
+        StringBuffer sb = new StringBuffer();
+        if ( exportDn )
+        {
+            sb.append( quoteCharacter );
+            sb.append( record.getDnLine().getValueAsString() );
+            sb.append( quoteCharacter );
+
+            if ( attributes == null || attributes.length > 0 )
+                sb.append( attributeDelimiter );
+        }
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+
+            String attributeName = attributes[i];
+            if ( attributeMap.containsKey( attributeName ) )
+            {
+                String value = ( String ) attributeMap.get( attributeName );
+
+                // escape
+                value = value.replaceAll( quoteCharacter, quoteCharacter + quoteCharacter );
+
+                // always quote
+                sb.append( quoteCharacter );
+                sb.append( value );
+                sb.append( quoteCharacter );
+            }
+
+            // delimiter
+            if ( i + 1 < attributes.length )
+            {
+                sb.append( attributeDelimiter );
+            }
+
+        }
+        sb.append( lineSeparator );
+
+        return sb.toString();
+    }
+
+
+    static Map getAttributeMap( LdifContentRecord record, String valueDelimiter, int binaryEncoding )
+    {
+        Map attributeMap = new HashMap();
+        LdifAttrValLine[] lines = record.getAttrVals();
+        for ( int i = 0; i < lines.length; i++ )
+        {
+            String attributeName = lines[i].getUnfoldedAttributeDescription();
+
+            if ( LdifUtils.mustEncode( lines[i].getValueAsBinary() ) )
+            {
+
+                String value = BrowserCoreConstants.BINARY;
+                if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_BASE64 )
+                {
+                    value = LdifUtils.base64encode( lines[i].getValueAsBinary() );
+                }
+                else if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_HEX )
+                {
+                    value = LdifUtils.hexEncode( lines[i].getValueAsBinary() );
+                }
+
+                if ( attributeMap.containsKey( attributeName ) )
+                {
+                    String oldValue = ( String ) attributeMap.get( attributeName );
+                    attributeMap.put( attributeName, oldValue + valueDelimiter + value );
+                }
+                else
+                {
+                    attributeMap.put( attributeName, value );
+                }
+            }
+            else
+            {
+                String value = lines[i].getValueAsString();
+                if ( attributeMap.containsKey( attributeName ) )
+                {
+                    String oldValue = ( String ) attributeMap.get( attributeName );
+                    attributeMap.put( attributeName, oldValue + valueDelimiter + value );
+                }
+                else
+                {
+                    attributeMap.put( attributeName, value );
+                }
+            }
+        }
+        return attributeMap;
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__export_cvs_error;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportLdifJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportLdifJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportLdifJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,198 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.internal.model.AttributeComparator;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ConnectionException;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralException;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine;
+
+
+public class ExportLdifJob extends AbstractEclipseJob
+{
+
+    private String exportLdifFilename;
+
+    private IConnection connection;
+
+    private SearchParameter searchParameter;
+
+
+    public ExportLdifJob( String exportLdifFilename, IConnection connection, SearchParameter searchParameter )
+    {
+        this.exportLdifFilename = exportLdifFilename;
+        this.connection = connection;
+        this.searchParameter = searchParameter;
+
+        setName( BrowserCoreMessages.jobs__export_ldif_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { connection };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
+        return l.toArray();
+    }
+
+
+    protected void executeAsyncJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__export_ldif_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        try
+        {
+            // open file
+            FileWriter fileWriter = new FileWriter( exportLdifFilename );
+            BufferedWriter bufferedWriter = new BufferedWriter( fileWriter );
+
+            // export
+            int count = 0;
+            export( connection, searchParameter, bufferedWriter, count, monitor );
+
+            // close file
+            bufferedWriter.close();
+            fileWriter.close();
+
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+
+    }
+
+
+    private static void export( IConnection connection, SearchParameter searchParameter, BufferedWriter bufferedWriter,
+        int count, ExtendedProgressMonitor monitor ) throws IOException, ConnectionException
+    {
+        try
+        {
+
+            AttributeComparator comparator = new AttributeComparator( connection );
+            LdifEnumeration enumeration = connection.exportLdif( searchParameter, monitor );
+            while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
+            {
+                LdifContainer container = enumeration.next( monitor );
+
+                if ( container instanceof LdifContentRecord )
+                {
+                    LdifContentRecord record = ( LdifContentRecord ) container;
+                    LdifDnLine dnLine = record.getDnLine();
+                    LdifAttrValLine[] attrValLines = record.getAttrVals();
+                    LdifSepLine sepLine = record.getSepLine();
+
+                    // sort and format
+                    Arrays.sort( attrValLines, comparator );
+                    LdifContentRecord newRecord = new LdifContentRecord( dnLine );
+                    for ( int i = 0; i < attrValLines.length; i++ )
+                    {
+                        newRecord.addAttrVal( attrValLines[i] );
+                    }
+                    newRecord.finish( sepLine );
+                    String s = newRecord.toFormattedString();
+
+                    // String s = record.toFormattedString();
+                    bufferedWriter.write( s );
+
+                    count++;
+                    monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
+                        new String[]
+                            { Integer.toString( count ) } ) );
+
+                }
+
+            }
+        }
+        catch ( ConnectionException ce )
+        {
+
+            if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
+            {
+                // nothing
+            }
+            else if ( ce instanceof ReferralException )
+            {
+
+                if ( searchParameter.getReferralsHandlingMethod() == IConnection.HANDLE_REFERRALS_FOLLOW )
+                {
+
+                    ReferralException re = ( ReferralException ) ce;
+                    ISearch[] referralSearches = re.getReferralSearches();
+                    for ( int i = 0; i < referralSearches.length; i++ )
+                    {
+                        ISearch referralSearch = referralSearches[i];
+
+                        // open connection
+                        if ( !referralSearch.getConnection().isOpened() )
+                        {
+                            referralSearch.getConnection().open( monitor );
+                        }
+
+                        // export recursive
+                        export( referralSearch.getConnection(), referralSearch.getSearchParameter(), bufferedWriter,
+                            count, monitor );
+                    }
+                }
+            }
+            else
+            {
+                monitor.reportError( ce );
+            }
+        }
+
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__export_ldif_error;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,299 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ConnectionException;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralException;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.SearchParameter;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.eclipse.core.runtime.Preferences;
+
+
+public class ExportXlsJob extends AbstractEclipseJob
+{
+
+    public static final int MAX_COUNT_LIMIT = 65000;
+
+    private String exportLdifFilename;
+
+    private IConnection connection;
+
+    private SearchParameter searchParameter;
+
+    private boolean exportDn;
+
+
+    public ExportXlsJob( String exportLdifFilename, IConnection connection, SearchParameter searchParameter,
+        boolean exportDn )
+    {
+        this.exportLdifFilename = exportLdifFilename;
+        this.connection = connection;
+        this.searchParameter = searchParameter;
+        this.exportDn = exportDn;
+
+        setName( BrowserCoreMessages.jobs__export_xls_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { connection };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
+        return l.toArray();
+    }
+
+
+    protected void executeAsyncJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__export_xls_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
+        String valueDelimiter = coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER );
+        int binaryEncoding = coreStore.getInt( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING );
+
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet( "Export" ); //$NON-NLS-1$
+
+        // header
+        HSSFRow headerRow = sheet.createRow( 0 );
+        LinkedHashMap attributeNameMap = new LinkedHashMap();
+        if ( this.exportDn )
+        {
+            short cellNum = ( short ) 0;
+            attributeNameMap.put( "dn", new Short( cellNum ) ); //$NON-NLS-1$
+            headerRow.createCell( cellNum ).setCellValue( "dn" ); //$NON-NLS-1$
+        }
+
+        // String[] exportAttributes =
+        // this.searchParameter.getReturningAttributes();
+        // exportAttributes = null;
+        // for (int i = 0; exportAttributes != null && i <
+        // exportAttributes.length; i++) {
+        // short cellNum = (short)attributeNameMap.size();
+        // attributeNameMap.put(exportAttributes[i], new Short(cellNum));
+        // headerRow.createCell(cellNum).setCellValue(exportAttributes[i]);
+        // }
+
+        // max export
+        if ( searchParameter.getCountLimit() < 1 || searchParameter.getCountLimit() > MAX_COUNT_LIMIT )
+        {
+            searchParameter.setCountLimit( MAX_COUNT_LIMIT );
+        }
+
+        // export
+        try
+        {
+
+            int count = 0;
+            export( connection, searchParameter, sheet, headerRow, count, monitor, attributeNameMap, valueDelimiter,
+                binaryEncoding, this.exportDn );
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+
+        // column width
+        for ( int i = 0; i <= sheet.getLastRowNum(); i++ )
+        {
+            HSSFRow row = sheet.getRow( i );
+            for ( short j = 0; row != null && j <= row.getLastCellNum(); j++ )
+            {
+                HSSFCell cell = row.getCell( j );
+                if ( cell != null && cell.getCellType() == HSSFCell.CELL_TYPE_STRING )
+                {
+                    String value = cell.getStringCellValue();
+
+                    if ( ( short ) ( value.length() * 256 * 1.1 ) > sheet.getColumnWidth( j ) )
+                    {
+                        sheet.setColumnWidth( j, ( short ) ( value.length() * 256 * 1.1 ) );
+                    }
+                }
+            }
+        }
+
+        try
+        {
+            FileOutputStream fileOut = new FileOutputStream( exportLdifFilename );
+            wb.write( fileOut );
+            fileOut.close();
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    private static void export( IConnection connection, SearchParameter searchParameter, HSSFSheet sheet,
+        HSSFRow headerRow, int count, ExtendedProgressMonitor monitor, LinkedHashMap attributeNameMap,
+        String valueDelimiter, int binaryEncoding, boolean exportDn ) throws IOException, ConnectionException
+    {
+        try
+        {
+
+            LdifEnumeration enumeration = connection.exportLdif( searchParameter, monitor );
+            while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
+            {
+                LdifContainer container = enumeration.next( monitor );
+
+                if ( container instanceof LdifContentRecord )
+                {
+                    LdifContentRecord record = ( LdifContentRecord ) container;
+                    recordToHSSFRow( record, sheet, headerRow, attributeNameMap, valueDelimiter, binaryEncoding,
+                        exportDn );
+
+                    count++;
+                    monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
+                        new String[]
+                            { Integer.toString( count ) } ) );
+                }
+            }
+
+        }
+        catch ( ConnectionException ce )
+        {
+
+            if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
+            {
+                // nothing
+            }
+            else if ( ce instanceof ReferralException )
+            {
+
+                if ( searchParameter.getReferralsHandlingMethod() == IConnection.HANDLE_REFERRALS_FOLLOW )
+                {
+
+                    ReferralException re = ( ReferralException ) ce;
+                    ISearch[] referralSearches = re.getReferralSearches();
+                    for ( int i = 0; i < referralSearches.length; i++ )
+                    {
+                        ISearch referralSearch = referralSearches[i];
+
+                        // open connection
+                        if ( !referralSearch.getConnection().isOpened() )
+                        {
+                            referralSearch.getConnection().open( monitor );
+                        }
+
+                        // export recursive
+                        export( referralSearch.getConnection(), referralSearch.getSearchParameter(), sheet, headerRow,
+                            count, monitor, attributeNameMap, valueDelimiter, binaryEncoding, exportDn );
+                    }
+                }
+            }
+            else
+            {
+                monitor.reportError( ce );
+            }
+        }
+
+    }
+
+
+    private static void recordToHSSFRow( LdifContentRecord record, HSSFSheet sheet, HSSFRow headerRow,
+        Map headerRowAttributeNameMap, String valueDelimiter, int binaryEncoding, boolean exportDn )
+    {
+
+        // group multi-valued attributes
+        Map attributeMap = ExportCsvJob.getAttributeMap( record, valueDelimiter, binaryEncoding );
+
+        // output attributes
+        HSSFRow row = sheet.createRow( sheet.getLastRowNum() + 1 );
+        if ( exportDn )
+        {
+            HSSFCell cell = row.createCell( ( short ) 0 );
+            cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
+            cell.setCellValue( record.getDnLine().getValueAsString() );
+        }
+        for ( Iterator it = attributeMap.keySet().iterator(); it.hasNext(); )
+        {
+            String attributeName = ( String ) it.next();
+            String value = ( String ) attributeMap.get( attributeName );
+
+            if ( !headerRowAttributeNameMap.containsKey( attributeName ) )
+            {
+                short cellNum = ( short ) headerRowAttributeNameMap.size();
+                headerRowAttributeNameMap.put( attributeName, new Short( cellNum ) );
+                HSSFCell cell = headerRow.createCell( cellNum );
+                cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
+                cell.setCellValue( attributeName );
+            }
+
+            if ( headerRowAttributeNameMap.containsKey( attributeName ) )
+            {
+                short cellNum = ( ( Short ) headerRowAttributeNameMap.get( attributeName ) ).shortValue();
+                HSSFCell cell = row.createCell( cellNum );
+                cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
+                cell.setCellValue( value );
+            }
+        }
+
+        // for (int i = 0; i < attributes.length; i++) {
+        //			
+        // String attributeName = attributes[i];
+        // if (attributeMap.containsKey(attributeName)) {
+        // String value = (String)attributeMap.get(attributeName);
+        // short cellNum = (short)(i + (exportDn?1:0));
+        // row.createCell(cellNum).setCellValue(value);
+        // }
+        // }
+
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__export_xls_error;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExtendedProgressMonitor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExtendedProgressMonitor.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExtendedProgressMonitor.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ExtendedProgressMonitor.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,275 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.ProgressMonitorWrapper;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+
+public class ExtendedProgressMonitor extends ProgressMonitorWrapper
+{
+
+    private boolean done;
+
+    private List errorStatusList;
+
+    private List cancelListenerList;
+
+    private Job checkCanceledJob;
+
+
+    public ExtendedProgressMonitor( IProgressMonitor monitor )
+    {
+        super( monitor );
+        this.done = false;
+
+        this.checkCanceledJob = new Job( BrowserCoreMessages.jobs__progressmonitor_check_cancellation )
+        {
+            protected IStatus run( IProgressMonitor monitor )
+            {
+                while ( !done )
+                {
+                    if ( isCanceled() )
+                    {
+                        fireCancelRequested();
+                        break;
+                    }
+                    else
+                    {
+                        try
+                        {
+                            Thread.sleep( 1000 );
+                        }
+                        catch ( InterruptedException e )
+                        {
+                        }
+                    }
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        this.checkCanceledJob.setSystem( true );
+        this.checkCanceledJob.schedule();
+    }
+
+
+    public void setCanceled( boolean b )
+    {
+        super.setCanceled( b );
+        if ( b )
+        {
+            this.fireCancelRequested();
+        }
+    }
+
+
+    public void done()
+    {
+        synchronized ( this )
+        {
+            this.done = true;
+            super.done();
+        }
+    }
+
+
+    public void addCancelListener( CancelListener listener )
+    {
+        if ( cancelListenerList == null )
+            cancelListenerList = new ArrayList();
+        if ( !cancelListenerList.contains( listener ) )
+            cancelListenerList.add( listener );
+    }
+
+
+    public void removeCancelListener( CancelListener listener )
+    {
+        if ( cancelListenerList != null && cancelListenerList.contains( listener ) )
+            cancelListenerList.remove( listener );
+    }
+
+
+    private void fireCancelRequested()
+    {
+        CancelEvent event = new CancelEvent( this );
+        if ( cancelListenerList != null )
+        {
+            for ( int i = 0; i < cancelListenerList.size(); i++ )
+            {
+                CancelListener listener = ( CancelListener ) cancelListenerList.get( i );
+                listener.cancelRequested( event );
+            }
+        }
+    }
+
+    Job reportProgressJob = null;
+
+    String reportProgressMessage = null;
+
+
+    public void reportProgress( String message )
+    {
+        synchronized ( this )
+        {
+            if ( !done )
+            {
+                if ( reportProgressJob == null )
+                {
+                    reportProgressJob = new Job( BrowserCoreMessages.jobs__progressmonitor_report_progress )
+                    {
+                        protected IStatus run( IProgressMonitor monitor )
+                        {
+                            synchronized ( ExtendedProgressMonitor.this )
+                            {
+                                if ( !done )
+                                {
+                                    subTask( reportProgressMessage );
+                                }
+                                return Status.OK_STATUS;
+                            }
+                        }
+                    };
+                    reportProgressJob.setSystem( true );
+                }
+
+                reportProgressMessage = message;
+                reportProgressJob.schedule( 1000 );
+            }
+        }
+    }
+
+
+    public void reportError( String message )
+    {
+        this.reportError( message, null );
+    }
+
+
+    public void reportError( Throwable throwable )
+    {
+        this.reportError( throwable.getMessage() != null ? throwable.getMessage() : throwable.toString(), throwable );
+    }
+
+
+    public void reportError( String message, Throwable exception )
+    {
+
+        if ( this.errorStatusList == null )
+            this.errorStatusList = new ArrayList( 3 );
+
+        do
+        {
+            if ( message == null )
+                message = ""; //$NON-NLS-1$
+
+            Status errorStatus = new Status( IStatus.ERROR, BrowserCorePlugin.PLUGIN_ID, IStatus.ERROR, message,
+                exception );
+            this.errorStatusList.add( errorStatus );
+
+            if ( exception != null )
+            {
+                exception = exception.getCause();
+            }
+            if ( exception != null )
+            {
+                message = exception.getMessage();
+            }
+        }
+        while ( exception != null );
+
+    }
+
+
+    public boolean errorsReported()
+    {
+        return this.errorStatusList != null;
+    }
+
+
+    public IStatus getErrorStatus( String message )
+    {
+
+        if ( this.errorStatusList != null && !this.errorStatusList.isEmpty() )
+        {
+
+            Throwable exception = null;
+            for ( Iterator it = this.errorStatusList.iterator(); it.hasNext(); )
+            {
+                Status status = ( Status ) it.next();
+                if ( status.getException() != null )
+                {
+                    exception = status.getException();
+                    break;
+                }
+            }
+
+            MultiStatus multiStatus = new MultiStatus( BrowserCorePlugin.PLUGIN_ID, IStatus.ERROR, message, exception );
+
+            for ( Iterator it = this.errorStatusList.iterator(); it.hasNext(); )
+            {
+                Status status = ( Status ) it.next();
+                multiStatus.add( new Status( status.getSeverity(), status.getPlugin(), status.getCode(), status
+                    .getMessage(), null ) );
+            }
+
+            return multiStatus;
+
+        }
+        else
+        {
+            return Status.OK_STATUS;
+        }
+    }
+
+    public static class CancelEvent
+    {
+        private IProgressMonitor monitor;
+
+
+        public CancelEvent( IProgressMonitor monitor )
+        {
+            this.monitor = monitor;
+        }
+
+
+        public IProgressMonitor getMonitor()
+        {
+            return monitor;
+        }
+    }
+
+    public interface CancelListener
+    {
+        public void cancelRequested( CancelEvent event );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/FetchBaseDNsJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/FetchBaseDNsJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/FetchBaseDNsJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/FetchBaseDNsJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,104 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+
+
+public class FetchBaseDNsJob extends AbstractAsyncBulkJob
+{
+
+    private IConnection connection;
+
+    private String[] baseDNs;
+
+
+    public FetchBaseDNsJob( IConnection connection )
+    {
+        this.connection = connection;
+        setName( BrowserCoreMessages.jobs__fetch_basedns_name );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[0];
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection );
+        return l.toArray();
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__fetch_basedns_task, 5 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        connection.fetchRootDSE( monitor );
+
+        IEntry[] baseDNEntries = connection.getBaseDNEntries();
+        baseDNs = new String[baseDNEntries.length];
+        for ( int i = 0; i < baseDNs.length; i++ )
+        {
+            baseDNs[i] = baseDNEntries[i].getDn().toString();
+        }
+        monitor.worked( 1 );
+
+        connection.close();
+
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__fetch_basedns_error;
+    }
+
+
+    public String[] getBaseDNs()
+    {
+        if ( baseDNs == null )
+        {
+            baseDNs = new String[0];
+        }
+        return baseDNs;
+    }
+
+
+    protected void runNotification()
+    {
+
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ImportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ImportLdifJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ImportLdifJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/ImportLdifJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,141 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
+
+
+public class ImportLdifJob extends AbstractEclipseJob
+{
+
+    private IConnection connection;
+
+    private File ldifFile;
+
+    private File logFile;
+
+    private boolean continueOnError;
+
+
+    public ImportLdifJob( IConnection connection, File ldifFile, File logFile, boolean continueOnError )
+    {
+        this.connection = connection;
+        this.ldifFile = ldifFile;
+        this.logFile = logFile;
+        this.continueOnError = continueOnError;
+
+        setName( BrowserCoreMessages.jobs__import_ldif_name );
+    }
+
+
+    public ImportLdifJob( IConnection connection, File ldifFile, boolean continueOnError )
+    {
+        this( connection, ldifFile, null, continueOnError );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        return new IConnection[]
+            { connection };
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( ldifFile.toString() ) );
+        return l.toArray();
+    }
+
+
+    protected void executeAsyncJob( ExtendedProgressMonitor monitor )
+    {
+
+        monitor.beginTask( BrowserCoreMessages.jobs__import_ldif_task, 2 );
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+        monitor.worked( 1 );
+
+        try
+        {
+            Reader ldifReader = new BufferedReader( new FileReader( this.ldifFile ) );
+            LdifParser parser = new LdifParser();
+            LdifEnumeration enumeration = parser.parse( ldifReader );
+
+            Writer logWriter;
+            if ( this.logFile != null )
+            {
+                logWriter = new BufferedWriter( new FileWriter( this.logFile ) );
+            }
+            else
+            {
+                logWriter = new Writer()
+                {
+                    public void close() throws IOException
+                    {
+                    }
+
+
+                    public void flush() throws IOException
+                    {
+                    }
+
+
+                    public void write( char[] cbuf, int off, int len ) throws IOException
+                    {
+                    }
+                };
+            }
+
+            connection.importLdif( enumeration, logWriter, continueOnError, monitor );
+
+            logWriter.close();
+            ldifReader.close();
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return BrowserCoreMessages.jobs__import_ldif_error;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeAttributesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeAttributesJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeAttributesJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeAttributesJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,166 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.events.AttributesInitializedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.RootDSE;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Search;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
+
+
+public class InitializeAttributesJob extends AbstractAsyncBulkJob
+{
+
+    private IEntry[] entries;
+
+    private boolean initOperationalAttributes;
+
+
+    public InitializeAttributesJob( IEntry[] entries, boolean initOperationalAttributes )
+    {
+        this.entries = entries;
+        this.initOperationalAttributes = initOperationalAttributes;
+        setName( BrowserCoreMessages.jobs__init_entries_title_attonly );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        IConnection[] connections = new IConnection[entries.length];
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            connections[i] = entries[i].getConnection();
+        }
+        return connections;
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.addAll( Arrays.asList( entries ) );
+        return l.toArray();
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1
+            : BrowserCoreMessages.jobs__init_entries_error_n;
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+        monitor.beginTask( " ", entries.length + 2 ); //$NON-NLS-1$
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+
+        for ( int pi = 0; pi < entries.length && !monitor.isCanceled(); pi++ )
+        {
+            monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_task, new String[]
+                { this.entries[pi].getDn().toString() } ) );
+            monitor.worked( 1 );
+            if ( entries[pi].getConnection() != null && entries[pi].getConnection().isOpened()
+                && entries[pi].isDirectoryEntry() )
+            {
+                initializeAttributes( entries[pi], initOperationalAttributes, monitor );
+            }
+        }
+    }
+
+
+    protected void runNotification()
+    {
+        for ( int pi = 0; pi < entries.length; pi++ )
+        {
+            IEntry parent = entries[pi];
+            if ( parent.getConnection() != null && entries[pi].getConnection().isOpened() && parent.isDirectoryEntry() )
+            {
+                EventRegistry.fireEntryUpdated( new AttributesInitializedEvent( parent, parent.getConnection() ), this );
+            }
+        }
+    }
+
+
+    public static void initializeAttributes( IEntry entry, boolean initOperationalAttributes,
+        ExtendedProgressMonitor monitor )
+    {
+
+        // get user attributes or both user and operational attributes
+        String[] returningAttributes = null;
+        LinkedHashSet raSet = new LinkedHashSet();
+        raSet.add( ISearch.ALL_USER_ATTRIBUTES );
+        if ( initOperationalAttributes )
+        {
+            AttributeTypeDescription[] opAtds = SchemaUtils.getOperationalAttributeDescriptions( entry.getConnection()
+                .getSchema() );
+            String[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( opAtds );
+            raSet.addAll( Arrays.asList( attributeTypeDescriptionNames ) );
+            raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
+        }
+        if ( entry instanceof RootDSE )
+        {
+            raSet.add( ISearch.ALL_USER_ATTRIBUTES );
+            raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
+        }
+        if ( entry.isReferral() )
+        {
+            raSet.add( IAttribute.REFERRAL_ATTRIBUTE );
+        }
+        returningAttributes = ( String[] ) raSet.toArray( new String[raSet.size()] );
+
+        initializeAttributes( entry, returningAttributes, monitor );
+    }
+
+
+    public static void initializeAttributes( IEntry entry, String[] attributes, ExtendedProgressMonitor monitor )
+    {
+
+        monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_att,
+            new String[]
+                { entry.getDn().toString() } ) );
+
+        // entry.setAttributesInitialized(false, entry.getConnection());
+
+        // search
+        ISearch search = new Search( null, entry.getConnection(), entry.getDn(), ISearch.FILTER_TRUE, attributes,
+            ISearch.SCOPE_OBJECT, 0, 0, IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE,
+            false, false, null );
+        entry.getConnection().search( search, monitor );
+
+        // set initialized state
+        entry.setAttributesInitialized( true, entry.getConnection() );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeChildrenJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeChildrenJob.java?view=auto&rev=488345
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeChildrenJob.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/jobs/InitializeChildrenJob.java Mon Dec 18 09:15:00 2006
@@ -0,0 +1,253 @@
+/*
+ *  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.ldapstudio.browser.core.jobs;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.events.ChildrenInitializedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.AliasBaseEntry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralBaseEntry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Search;
+import org.apache.directory.ldapstudio.browser.core.model.Control;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IRootDSE;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+
+
+public class InitializeChildrenJob extends AbstractAsyncBulkJob
+{
+
+    private IEntry[] entries;
+
+
+    public InitializeChildrenJob( IEntry[] entries )
+    {
+        this.entries = entries;
+        setName( BrowserCoreMessages.jobs__init_entries_title_subonly );
+    }
+
+
+    protected IConnection[] getConnections()
+    {
+        IConnection[] connections = new IConnection[entries.length];
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            connections[i] = entries[i].getConnection();
+        }
+        return connections;
+    }
+
+
+    protected Object[] getLockedObjects()
+    {
+        List l = new ArrayList();
+        l.addAll( Arrays.asList( entries ) );
+        return l.toArray();
+    }
+
+
+    protected String getErrorMessage()
+    {
+        return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1
+            : BrowserCoreMessages.jobs__init_entries_error_n;
+    }
+
+
+    protected void executeBulkJob( ExtendedProgressMonitor monitor )
+    {
+        monitor.beginTask( " ", entries.length + 2 ); //$NON-NLS-1$
+        monitor.reportProgress( " " ); //$NON-NLS-1$
+
+        for ( int pi = 0; pi < entries.length && !monitor.isCanceled(); pi++ )
+        {
+
+            monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_task, new String[]
+                { this.entries[pi].getDn().toString() } ) );
+            monitor.worked( 1 );
+
+            if ( entries[pi].getConnection() != null && entries[pi].getConnection().isOpened()
+                && entries[pi].isDirectoryEntry() )
+            {
+                initializeChildren( entries[pi], monitor );
+            }
+        }
+    }
+
+
+    protected void runNotification()
+    {
+        for ( int pi = 0; pi < entries.length; pi++ )
+        {
+            IEntry parent = entries[pi];
+            if ( parent.getConnection() != null && entries[pi].getConnection().isOpened() && parent.isDirectoryEntry() )
+            {
+                EventRegistry.fireEntryUpdated( new ChildrenInitializedEvent( parent, parent.getConnection() ), this );
+            }
+        }
+    }
+
+
+    public static void initializeChildren( IEntry parent, ExtendedProgressMonitor monitor )
+    {
+
+        monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_sub,
+            new String[]
+                { parent.getDn().toString() } ) );
+
+        // root DSE has no children
+        if ( parent instanceof IRootDSE )
+        {
+            parent.setChildrenInitialized( true, parent.getConnection() );
+            return;
+        }
+
+        // clear old children
+        IEntry[] oldChildren = parent.getChildren();
+        for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
+        {
+            if ( oldChildren[i] != null )
+            {
+                parent.deleteChild( oldChildren[i], parent.getConnection() );
+            }
+        }
+        parent.setChildrenInitialized( false, parent.getConnection() );
+
+        // determine alias and referral handling
+        int scope = ISearch.SCOPE_ONELEVEL;
+        int derefAliasMethod = parent.getConnection().getAliasesDereferencingMethod();
+        int handleReferralsMethod = parent.getConnection().getReferralsHandlingMethod();
+        if ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+            BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) )
+        {
+            scope = ( parent.isAlias() || parent.isReferral() ) ? ISearch.SCOPE_OBJECT : ISearch.SCOPE_ONELEVEL;
+            derefAliasMethod = parent.isAlias() ? IConnection.DEREFERENCE_ALIASES_FINDING
+                : IConnection.DEREFERENCE_ALIASES_NEVER;
+            handleReferralsMethod = parent.isReferral() ? IConnection.HANDLE_REFERRALS_FOLLOW
+                : IConnection.HANDLE_REFERRALS_IGNORE;
+        }
+
+        // get children,
+        ISearch search = new Search( null, parent.getConnection(), parent.getDn(), parent.getChildrenFilter(),
+            ISearch.NO_ATTRIBUTES, scope, parent.getConnection().getCountLimit(),
+            parent.getConnection().getTimeLimit(), derefAliasMethod, handleReferralsMethod, BrowserCorePlugin
+                .getDefault().getPluginPreferences().getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ),
+            BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ), null );
+        parent.getConnection().search( search, monitor );
+        ISearchResult[] srs = search.getSearchResults();
+        monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_subcount,
+            new String[]
+                { srs == null ? Integer.toString( 0 ) : Integer.toString( srs.length ), parent.getDn().toString() } ) );
+
+        // fill children in search result
+        if ( srs != null && srs.length > 0 )
+        {
+
+            /*
+             * clearing old children before filling new subenties is
+             * necessary to handle aliases and referrals.
+             */
+            IEntry[] connChildren = parent.getChildren();
+            for ( int i = 0; connChildren != null && i < connChildren.length; i++ )
+            {
+                if ( connChildren[i] != null )
+                {
+                    parent.deleteChild( connChildren[i], parent.getConnection() );
+                }
+            }
+            parent.setChildrenInitialized( false, parent.getConnection() );
+
+            for ( int i = 0; srs != null && i < srs.length; i++ )
+            {
+                if ( parent.isReferral() )
+                {
+                    ReferralBaseEntry referralBaseEntry = new ReferralBaseEntry( srs[i].getEntry().getConnection(),
+                        srs[i].getEntry().getDn() );
+                    parent.addChild( referralBaseEntry, parent.getConnection() );
+                    // System.out.println("Ref: " +
+                    // referralBaseEntry.getUrl());
+                }
+                else if ( parent.isAlias() )
+                {
+                    AliasBaseEntry aliasBaseEntry = new AliasBaseEntry( srs[i].getEntry().getConnection(), srs[i]
+                        .getEntry().getDn() );
+                    parent.addChild( aliasBaseEntry, parent.getConnection() );
+                    // System.out.println("Ali: " +
+                    // aliasBaseEntry.getUrl());
+                }
+                else
+                {
+                    parent.addChild( srs[i].getEntry(), parent.getConnection() );
+                }
+            }
+        }
+        else
+        {
+            parent.setHasChildrenHint( false, parent.getConnection() );
+        }
+
+        // get subentries
+        ISearch subSearch = new Search( null, parent.getConnection(), parent.getDn(), parent.getChildrenFilter(),
+            ISearch.NO_ATTRIBUTES, scope, parent.getConnection().getCountLimit(),
+            parent.getConnection().getTimeLimit(), derefAliasMethod, handleReferralsMethod, BrowserCorePlugin
+                .getDefault().getPluginPreferences().getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ),
+            BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ), new Control[]
+                { Control.SUBENTRIES_CONTROL } );
+        if ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+            BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) )
+        {
+            parent.getConnection().search( subSearch, monitor );
+            ISearchResult[] subSrs = subSearch.getSearchResults();
+            monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_subcount,
+                new String[]
+                    { subSrs == null ? Integer.toString( 0 ) : Integer.toString( subSrs.length ),
+                        parent.getDn().toString() } ) );
+            // fill children in search result
+            if ( subSrs != null && subSrs.length > 0 )
+            {
+
+                for ( int i = 0; subSrs != null && i < subSrs.length; i++ )
+                {
+                    parent.addChild( subSrs[i].getEntry(), parent.getConnection() );
+                }
+            }
+        }
+
+        // check exceeded limits / canceled
+        parent.setHasMoreChildren( search.isCountLimitExceeded() || subSearch.isCountLimitExceeded()
+            || monitor.isCanceled(), parent.getConnection() );
+
+        // set initialized state
+        parent.setChildrenInitialized( true, parent.getConnection() );
+
+    }
+
+}



Mime
View raw message