directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r586706 - in /directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core: internal/model/ jobs/ model/
Date Sat, 20 Oct 2007 13:00:58 GMT
Author: seelmann
Date: Sat Oct 20 06:00:57 2007
New Revision: 586706

URL: http://svn.apache.org/viewvc?rev=586706&view=rev
Log:
DIRSTUDIO-123: Moved import ldif code from BrowserConnection to ImportLdifJob.

Removed:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/ConnectionModifyHandler.java
Modified:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java?rev=586706&r1=586705&r2=586706&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
Sat Oct 20 06:00:57 2007
@@ -22,7 +22,6 @@
 
 
 import java.io.Serializable;
-import java.io.Writer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -86,7 +85,7 @@
 
     transient JNDIConnectionProvider connectionProvider;
     
-    transient ConnectionModifyHandler modifyHandler;
+    transient ModificationLogger modificationLogger;
 
     transient ConnectionSearchHandler searchHandler;
 
@@ -130,7 +129,7 @@
         this.entryToChildrenInfoMap = new HashMap<IEntry, ChildrenInfo>();
 
         this.connectionProvider = new JNDIConnectionProvider( connection );
-        this.modifyHandler = new ConnectionModifyHandler( this );
+        this.modificationLogger = new ModificationLogger( this );
         this.searchHandler = new ConnectionSearchHandler( this );
         
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner()
);
@@ -293,7 +292,6 @@
         entryToChildrenInfoMap.clear();
         entryToChildrenFilterMap.clear();
 
-        modifyHandler.connectionClosed();
         searchHandler.connectionClosed();
 
         rootDSE = null;
@@ -738,7 +736,7 @@
 
     public ModificationLogger getModificationLogger()
     {
-        return modifyHandler.getModificationLogger();
+        return modificationLogger;
     }
 
 
@@ -843,13 +841,6 @@
         {
             this.entryToChildrenInfoMap.put( entry, si );
         }
-    }
-
-
-    public void importLdif( LdifEnumeration enumeration, Writer logWriter, boolean continueOnError,
-        StudioProgressMonitor monitor )
-    {
-        modifyHandler.importLdif( enumeration, logWriter, continueOnError, monitor );
     }
 
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java?rev=586706&r1=586705&r2=586706&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/DummyConnection.java
Sat Oct 20 06:00:57 2007
@@ -21,19 +21,15 @@
 package org.apache.directory.studio.ldapbrowser.core.internal.model;
 
 
-import java.io.Writer;
-
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.ldapbrowser.core.BookmarkManager;
 import org.apache.directory.studio.ldapbrowser.core.SearchManager;
 import org.apache.directory.studio.ldapbrowser.core.model.DN;
-import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.IValue;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
 import org.apache.directory.studio.ldapbrowser.core.model.URL;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
@@ -129,13 +125,6 @@
     public int getTimeLimit()
     {
         return 0;
-    }
-
-
-    public void importLdif( LdifEnumeration enumeration, Writer logWriter, boolean continueOnError,
-        StudioProgressMonitor monitor )
-    {
-
     }
 
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java?rev=586706&r1=586705&r2=586706&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java
Sat Oct 20 06:00:57 2007
@@ -36,19 +36,35 @@
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.parser.LdifParser;
 
 
+/**
+ * Job to execute an LDIF.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class ExecuteLdifJob extends AbstractEclipseJob
 {
 
-    private IBrowserConnection connection;
+    /** The browser connection. */
+    private IBrowserConnection browserConnection;
 
+    /** The LDIF to execute. */
     private String ldif;
 
+    /** The continue on error flag. */
     private boolean continueOnError;
 
 
-    public ExecuteLdifJob( IBrowserConnection connection, String ldif, boolean continueOnError
)
+    /**
+     * Creates a new instance of ExecuteLdifJob.
+     * 
+     * @param browserConnection the browser connection
+     * @param ldif the LDIF to execute
+     * @param continueOnError the continue on error flag
+     */
+    public ExecuteLdifJob( IBrowserConnection browserConnection, String ldif, boolean continueOnError
)
     {
-        this.connection = connection;
+        this.browserConnection = browserConnection;
         this.ldif = ldif;
         this.continueOnError = continueOnError;
 
@@ -56,24 +72,32 @@
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
     protected Connection[] getConnections()
     {
         return new Connection[]
-            { connection.getConnection() };
+            { browserConnection.getConnection() };
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
     protected Object[] getLockedObjects()
     {
-        List l = new ArrayList();
-        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( ldif ) );
+        List<Object> l = new ArrayList<Object>();
+        l.add( browserConnection.getUrl() + "_" + DigestUtils.shaHex( ldif ) );
         return l.toArray();
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
     protected void executeAsyncJob( StudioProgressMonitor monitor )
     {
-
         monitor.beginTask( BrowserCoreMessages.jobs__execute_ldif_task, 2 );
         monitor.reportProgress( " " ); //$NON-NLS-1$
         monitor.worked( 1 );
@@ -101,7 +125,7 @@
                 }
             };
 
-            connection.importLdif( enumeration, logWriter, continueOnError, monitor );
+            ImportLdifJob.importLdif( browserConnection, enumeration, logWriter, continueOnError,
monitor );
 
             logWriter.close();
             ldifReader.close();
@@ -113,6 +137,9 @@
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
     protected String getErrorMessage()
     {
         return BrowserCoreMessages.jobs__execute_ldif_error;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java?rev=586706&r1=586705&r2=586706&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
Sat Oct 20 06:00:57 2007
@@ -29,36 +29,84 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
+
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.events.BulkModificationEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.internal.model.ConnectionException;
+import org.apache.directory.studio.ldapbrowser.core.internal.model.JNDIControl;
+import org.apache.directory.studio.ldapbrowser.core.model.DN;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
+import org.apache.directory.studio.ldapbrowser.core.model.NameException;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifCommentLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifModSpecTypeLine;
 import org.apache.directory.studio.ldapbrowser.core.model.ldif.parser.LdifParser;
 
 
+/**
+ * Job used to import an LDIF file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class ImportLdifJob extends AbstractNotificationJob
 {
 
-    private IBrowserConnection connection;
+    /** The browser connection. */
+    private IBrowserConnection browserConnection;
 
+    /** The LDIF file. */
     private File ldifFile;
 
+    /** The log file. */
     private File logFile;
 
+    /** The continue on error flag. */
     private boolean continueOnError;
 
 
-    public ImportLdifJob( IBrowserConnection connection, File ldifFile, File logFile, boolean
continueOnError )
+    /**
+     * Creates a new instance of ImportLdifJob.
+     * 
+     * @param browserConnection the browser connection
+     * @param ldifFile the LDIF file
+     * @param logFile the log file
+     * @param continueOnError the continue on error flag
+     */
+    public ImportLdifJob( IBrowserConnection browserConnection, File ldifFile, File logFile,
boolean continueOnError )
     {
-        this.connection = connection;
+        this.browserConnection = browserConnection;
         this.ldifFile = ldifFile;
         this.logFile = logFile;
         this.continueOnError = continueOnError;
@@ -67,30 +115,45 @@
     }
 
 
+    /**
+     * Creates a new instance of ImportLdifJob.
+     * 
+     * @param connection the connection
+     * @param ldifFile the LDIF file
+     * @param continueOnError the continue on error
+     */
     public ImportLdifJob( IBrowserConnection connection, File ldifFile, boolean continueOnError
)
     {
         this( connection, ldifFile, null, continueOnError );
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+     */
     protected Connection[] getConnections()
     {
         return new Connection[]
-            { connection.getConnection() };
+            { browserConnection.getConnection() };
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+     */
     protected Object[] getLockedObjects()
     {
-        List l = new ArrayList();
-        l.add( connection.getUrl() + "_" + DigestUtils.shaHex( ldifFile.toString() ) );
+        List<Object> l = new ArrayList<Object>();
+        l.add( browserConnection.getUrl() + "_" + DigestUtils.shaHex( ldifFile.toString()
) );
         return l.toArray();
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+     */
     protected void executeNotificationJob( StudioProgressMonitor monitor ) throws ModelModificationException
     {
-
         monitor.beginTask( BrowserCoreMessages.jobs__import_ldif_task, 2 );
         monitor.reportProgress( " " ); //$NON-NLS-1$
         monitor.worked( 1 );
@@ -126,7 +189,7 @@
                 };
             }
 
-            connection.importLdif( enumeration, logWriter, continueOnError, monitor );
+            importLdif( browserConnection, enumeration, logWriter, continueOnError, monitor
);
 
             logWriter.close();
             ldifReader.close();
@@ -138,15 +201,367 @@
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+     */
     protected String getErrorMessage()
     {
         return BrowserCoreMessages.jobs__import_ldif_error;
     }
 
 
+    /**
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+     */
     protected void runNotification()
     {
-        EventRegistry.fireEntryUpdated( new BulkModificationEvent( connection ), this );
+        EventRegistry.fireEntryUpdated( new BulkModificationEvent( browserConnection ), this
);
+    }
+
+
+    /**
+     * Imports the LDIF enumeration
+     * 
+     * @param browserConnection the browser connection
+     * @param enumeration the LDIF enumeration
+     * @param logWriter the log writer
+     * @param continueOnError the continue on error flag
+     * @param monitor the progress monitor
+     */
+    static void importLdif( IBrowserConnection browserConnection, LdifEnumeration enumeration,
Writer logWriter,
+        boolean continueOnError, StudioProgressMonitor monitor )
+    {
+        int importedCount = 0;
+        int errorCount = 0;
+        try
+        {
+            while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
+            {
+                LdifContainer container = enumeration.next( monitor );
+
+                if ( container instanceof LdifRecord )
+                {
+                    LdifRecord record = ( LdifRecord ) container;
+                    try
+                    {
+                        importLdifRecord( browserConnection, record, monitor );
+                        logModification( browserConnection, logWriter, record, monitor );
+                        importedCount++;
+
+                        // update cache and adjust attribute/children initialization flags
+                        DN dn = new DN( record.getDnLine().getValueAsString() );
+                        IEntry entry = browserConnection.getEntryFromCache( dn );
+                        DN parentDn = dn.getParentDn();
+                        IEntry parentEntry = parentDn != null ? browserConnection.getEntryFromCache(
parentDn ) : null;
+
+                        if ( record instanceof LdifChangeDeleteRecord )
+                        {
+                            if ( entry != null )
+                            {
+                                entry.setAttributesInitialized( false );
+                                browserConnection.uncacheEntryRecursive( entry );
+                            }
+                            if ( parentEntry != null )
+                            {
+                                parentEntry.setChildrenInitialized( false );
+                            }
+                        }
+                        else if ( record instanceof LdifChangeModDnRecord )
+                        {
+                            if ( entry != null )
+                            {
+                                entry.setAttributesInitialized( false );
+                                browserConnection.uncacheEntryRecursive( entry );
+                            }
+                            if ( parentEntry != null )
+                            {
+                                parentEntry.setChildrenInitialized( false );
+                            }
+                            LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord )
record;
+                            if ( modDnRecord.getNewsuperiorLine() != null )
+                            {
+                                DN newSuperiorDn = new DN( modDnRecord.getNewsuperiorLine().getValueAsString()
);
+                                IEntry newSuperiorEntry = browserConnection.getEntryFromCache(
newSuperiorDn );
+                                if ( newSuperiorEntry != null )
+                                {
+                                    newSuperiorEntry.setChildrenInitialized( false );
+                                }
+                            }
+                        }
+                        else if ( record instanceof LdifChangeAddRecord || record instanceof
LdifContentRecord )
+                        {
+                            if ( parentEntry != null )
+                            {
+                                parentEntry.setChildrenInitialized( false );
+                            }
+                        }
+                        else
+                        {
+                            if ( entry != null )
+                            {
+                                entry.setAttributesInitialized( false );
+                            }
+                        }
+                    }
+                    catch ( Exception e )
+                    {
+                        logModificationError( browserConnection, logWriter, record, e, monitor
);
+                        errorCount++;
+
+                        if ( !continueOnError )
+                        {
+                            monitor.reportError( e );
+                            return;
+                        }
+                    }
+
+                    monitor.reportProgress( BrowserCoreMessages.bind(
+                        BrowserCoreMessages.ldif__imported_n_entries_m_errors, new String[]
+                            { "" + importedCount, "" + errorCount } ) ); //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                else
+                {
+                    logWriter.write( container.toRawString() );
+                }
+            }
+
+            if ( errorCount > 0 )
+            {
+                monitor.reportError( BrowserCoreMessages.bind( BrowserCoreMessages.ldif__n_errors_see_logfile,
+                    new String[]
+                        { "" + errorCount } ) ); //$NON-NLS-1$
+            }
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( e );
+        }
+    }
+
+
+    /**
+     * Imports the LDIF record.
+     * 
+     * @param browserConnection the browser connection
+     * @param record the LDIF record
+     * @param monitor the progress monitor
+     * 
+     * @throws ConnectionException the connection exception
+     */
+    static void importLdifRecord( IBrowserConnection browserConnection, LdifRecord record,
StudioProgressMonitor monitor )
+        throws ConnectionException
+    {
+        if ( !record.isValid() )
+        {
+            throw new ConnectionException( BrowserCoreMessages.model__invalid_record );
+        }
+
+        String dn = record.getDnLine().getValueAsString();
+
+        if ( record instanceof LdifContentRecord )
+        {
+            LdifContentRecord attrValRecord = ( LdifContentRecord ) record;
+            LdifAttrValLine[] attrVals = attrValRecord.getAttrVals();
+            Attributes jndiAttributes = new BasicAttributes();
+            for ( int ii = 0; ii < attrVals.length; ii++ )
+            {
+                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
+                Object realValue = attrVals[ii].getValueAsObject();
+
+                if ( jndiAttributes.get( attributeName ) != null )
+                {
+                    jndiAttributes.get( attributeName ).add( realValue );
+                }
+                else
+                {
+                    jndiAttributes.put( attributeName, realValue );
+                }
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn,
jndiAttributes,
+                getControls( attrValRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeAddRecord )
+        {
+            LdifChangeAddRecord changeAddRecord = ( LdifChangeAddRecord ) record;
+            LdifAttrValLine[] attrVals = changeAddRecord.getAttrVals();
+            Attributes jndiAttributes = new BasicAttributes();
+            for ( int ii = 0; ii < attrVals.length; ii++ )
+            {
+                String attributeName = attrVals[ii].getUnfoldedAttributeDescription();
+                Object realValue = attrVals[ii].getValueAsObject();
+
+                if ( jndiAttributes.get( attributeName ) != null )
+                {
+                    jndiAttributes.get( attributeName ).add( realValue );
+                }
+                else
+                {
+                    jndiAttributes.put( attributeName, realValue );
+                }
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( dn,
jndiAttributes,
+                getControls( changeAddRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeDeleteRecord )
+        {
+            LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
+            browserConnection.getConnection().getJNDIConnectionWrapper().deleteEntry( dn,
+                getControls( changeDeleteRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeModifyRecord )
+        {
+            LdifChangeModifyRecord modifyRecord = ( LdifChangeModifyRecord ) record;
+            LdifModSpec[] modSpecs = modifyRecord.getModSpecs();
+            ModificationItem[] mis = new ModificationItem[modSpecs.length];
+            for ( int ii = 0; ii < modSpecs.length; ii++ )
+            {
+                LdifModSpecTypeLine modSpecType = modSpecs[ii].getModSpecType();
+                LdifAttrValLine[] attrVals = modSpecs[ii].getAttrVals();
+
+                Attribute attribute = new BasicAttribute( modSpecType.getUnfoldedAttributeDescription()
);
+                for ( int x = 0; x < attrVals.length; x++ )
+                {
+                    attribute.add( attrVals[x].getValueAsObject() );
+                }
+
+                if ( modSpecType.isAdd() )
+                {
+                    mis[ii] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
+                }
+                else if ( modSpecType.isDelete() )
+                {
+                    mis[ii] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attribute
);
+                }
+                else if ( modSpecType.isReplace() )
+                {
+                    mis[ii] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute
);
+                }
+            }
+
+            browserConnection.getConnection().getJNDIConnectionWrapper().modifyAttributes(
dn, mis,
+                getControls( modifyRecord ), monitor );
+        }
+        else if ( record instanceof LdifChangeModDnRecord )
+        {
+            LdifChangeModDnRecord modDnRecord = ( LdifChangeModDnRecord ) record;
+            if ( modDnRecord.getNewrdnLine() != null && modDnRecord.getDeloldrdnLine()
!= null )
+            {
+                String newRdn = modDnRecord.getNewrdnLine().getValueAsString();
+                boolean deleteOldRdn = modDnRecord.getDeloldrdnLine().isDeleteOldRdn();
+
+                try
+                {
+                    DN newDn;
+                    if ( modDnRecord.getNewsuperiorLine() != null )
+                        newDn = new DN( newRdn, modDnRecord.getNewsuperiorLine().getValueAsString()
);
+                    else
+                    {
+                        DN dnObject = new DN( dn );
+                        newDn = new DN( newRdn.toString(), dnObject.getParentDn().toString()
);
+                    }
+
+                    browserConnection.getConnection().getJNDIConnectionWrapper().rename(
dn, newDn.toString(),
+                        deleteOldRdn, getControls( modDnRecord ), monitor );
+                }
+                catch ( NameException ne )
+                {
+                    throw new ConnectionException( ne );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Gets the controls.
+     * 
+     * @param record the LDIF record
+     * 
+     * @return the controls
+     */
+    private static Control[] getControls( LdifRecord record )
+    {
+        Control[] controls = null;
+        if ( record instanceof LdifChangeRecord )
+        {
+            LdifChangeRecord changeRecord = ( LdifChangeRecord ) record;
+            LdifControlLine[] controlLines = changeRecord.getControls();
+            controls = new Control[controlLines.length];
+            for ( int i = 0; i < controlLines.length; i++ )
+            {
+                LdifControlLine line = controlLines[i];
+                // TODO: encoded control value
+                controls[i] = new JNDIControl( line.getUnfoldedOid(), line.isCritical(),
null );
+            }
+        }
+        return controls;
     }
 
+
+    /**
+     * Log a modification error to the given writer.
+     * 
+     * @param browserConnection the browser connection
+     * @param logWriter the log writer
+     * @param record the record
+     * @param exception the exception
+     * @param monitor the progress monitor
+     */
+    private static void logModificationError( IBrowserConnection browserConnection, Writer
logWriter,
+        LdifRecord record, Exception exception, StudioProgressMonitor monitor )
+    {
+        try
+        {
+            DateFormat df = new SimpleDateFormat( BrowserCoreConstants.DATEFORMAT );
+
+            String errorComment = "#!ERROR " + exception.getMessage(); //$NON-NLS-1$
+            errorComment = errorComment.replaceAll( "\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+            errorComment = errorComment.replaceAll( "\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$
+            LdifCommentLine errorCommentLine = LdifCommentLine.create( errorComment );
+
+            logWriter.write( LdifCommentLine.create( "#!RESULT ERROR" ).toFormattedString()
); //$NON-NLS-1$
+            logWriter
+                .write( LdifCommentLine
+                    .create(
+                        "#!CONNECTION ldap://" + browserConnection.getConnection().getHost()
+ ":" + browserConnection.getConnection().getPort() ).toFormattedString() ); //$NON-NLS-1$
//$NON-NLS-2$
+            logWriter.write( LdifCommentLine.create( "#!DATE " + df.format( new Date() )
).toFormattedString() ); //$NON-NLS-1$
+            logWriter.write( errorCommentLine.toFormattedString() );
+            logWriter.write( record.toFormattedString() );
+        }
+        catch ( IOException ioe )
+        {
+            monitor.reportError( BrowserCoreMessages.model__error_logging_modification, ioe
);
+        }
+    }
+
+
+    /**
+     * Log a modification to the given writer.
+     * 
+     * @param browserConnection the browser connection
+     * @param logWriter the log writer
+     * @param record the record
+     * @param monitor the progress monitor
+     */
+    private static void logModification( IBrowserConnection browserConnection, Writer logWriter,
LdifRecord record,
+        StudioProgressMonitor monitor )
+    {
+        try
+        {
+            DateFormat df = new SimpleDateFormat( BrowserCoreConstants.DATEFORMAT );
+            logWriter.write( LdifCommentLine.create( "#!RESULT OK" ).toFormattedString()
); //$NON-NLS-1$
+            logWriter
+                .write( LdifCommentLine
+                    .create(
+                        "#!CONNECTION ldap://" + browserConnection.getConnection().getHost()
+ ":" + browserConnection.getConnection().getPort() ).toFormattedString() ); //$NON-NLS-1$
//$NON-NLS-2$
+            logWriter.write( LdifCommentLine.create( "#!DATE " + df.format( new Date() )
).toFormattedString() ); //$NON-NLS-1$
+            logWriter.write( record.toFormattedString() );
+        }
+        catch ( IOException ioe )
+        {
+            monitor.reportError( BrowserCoreMessages.model__error_logging_modification, ioe
);
+        }
+    }
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java?rev=586706&r1=586705&r2=586706&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
Sat Oct 20 06:00:57 2007
@@ -22,13 +22,10 @@
 
 
 import java.io.Serializable;
-import java.io.Writer;
 
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionPropertyPageProvider;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
-import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
-import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
 import org.apache.directory.studio.ldapbrowser.core.BookmarkManager;
 import org.apache.directory.studio.ldapbrowser.core.SearchManager;
 import org.apache.directory.studio.ldapbrowser.core.internal.model.ConnectionException;
@@ -152,10 +149,6 @@
 
 
     public abstract void search( ISearch searchRequest, StudioProgressMonitor monitor );
-
-
-    public abstract void importLdif( LdifEnumeration enumeration, Writer logWriter, boolean
continueOnError,
-        StudioProgressMonitor monitor );
 
 
     public abstract LdifEnumeration exportLdif( SearchParameter searchParameter, StudioProgressMonitor
pm )



Mime
View raw message