directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r688867 - in /directory/studio/trunk: connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/ connection-ui/src/main/java/org/apache/directory/stu...
Date Mon, 25 Aug 2008 20:39:30 GMT
Author: seelmann
Date: Mon Aug 25 13:39:30 2008
New Revision: 688867

URL: http://svn.apache.org/viewvc?rev=688867&view=rev
Log:
First implementation of DIRSTUDIO-356: copy/paste of connections as URL

Modified:
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
    directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java?rev=688867&r1=688866&r2=688867&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionParameterPage.java
Mon Aug 25 13:39:30 2008
@@ -20,6 +20,7 @@
 package org.apache.directory.studio.connection.ui;
 
 
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.eclipse.jface.operation.IRunnableContext;
 import org.eclipse.swt.widgets.Composite;
@@ -36,9 +37,9 @@
 {
 
     /**
-     * Save the fields to the parameters.
+     * Save the fields to the connection parameters.
      * 
-     * @param parameter the parameter
+     * @param parameter the connection parameter
      */
     public void saveParameters( ConnectionParameter parameter );
 
@@ -189,8 +190,25 @@
      * The implementing class must return true if any
      * parameter was modified.
      * 
-     * @return true, if parameters were modifed
+     * @return true, if parameters were modified
      */
     public boolean areParametersModifed();
 
+
+    /**
+     * Merges the connection parameters into the LDAP URL.
+     *
+     * @param parameter the source connection parameter
+     * @param ldapUrl the target LDAP URL
+     */
+    public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapURL ldapUrl
);
+
+
+    /**
+     * Merges the LDAP URL into the connection parameters.
+     *
+     * @param ldapUrl the source LDAP URL
+     * @param parameter the target connection parameter
+     */
+    public void mergeLdapUrlToParameters( LdapURL ldapUrl, ConnectionParameter parameter
);
 }

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java?rev=688867&r1=688866&r2=688867&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
Mon Aug 25 13:39:30 2008
@@ -25,11 +25,18 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCoreConstants;
 import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPage;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager;
 import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.ISharedImages;
@@ -111,13 +118,14 @@
         List<Object> objects = new ArrayList<Object>();
         objects.addAll( Arrays.asList( connections ) );
         objects.addAll( Arrays.asList( connectionFolders ) );
+        String urls = getSelectedConnectionUrls();
 
-        // connection
+        // copy to clipboard
         if ( objects != null )
         {
             copyToClipboard( new Object[]
-                { objects.toArray() }, new Transfer[]
-                { ConnectionTransfer.getInstance() } );
+                { objects.toArray(), urls }, new Transfer[]
+                { ConnectionTransfer.getInstance(), TextTransfer.getInstance() } );
         }
 
         // update paste action
@@ -161,4 +169,33 @@
         return getSelectedConnections().length + getSelectedConnectionFolders().length >
0;
     }
 
+
+    /**
+     * Gets the selected connections as URLs, multiple URLs
+     * are separated by a line break. 
+     *
+     * @return the selected connections as URLs
+     */
+    private String getSelectedConnectionUrls()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        Connection[] connections = getSelectedConnections();
+        ConnectionParameterPage[] connectionParameterPages = ConnectionParameterPageManager
+            .getConnectionParameterPages();
+        for ( Connection connection : connections )
+        {
+            ConnectionParameter parameter = connection.getConnectionParameter();
+            LdapURL ldapUrl = new LdapURL();
+            ldapUrl.setDn( LdapDN.EMPTY_LDAPDN );
+            for ( ConnectionParameterPage connectionParameterPage : connectionParameterPages
)
+            {
+                connectionParameterPage.mergeParametersToLdapURL( parameter, ldapUrl );
+            }
+            sb.append( ldapUrl.toString() );
+            sb.append( ConnectionCoreConstants.LINE_SEPARATOR );
+        }
+        return sb.toString();
+    }
+
 }

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java?rev=688867&r1=688866&r2=688867&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
Mon Aug 25 13:39:30 2008
@@ -24,14 +24,22 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCoreConstants;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionFolder;
 import org.apache.directory.studio.connection.core.ConnectionFolderManager;
 import org.apache.directory.studio.connection.core.ConnectionManager;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPage;
+import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager;
 import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.ISharedImages;
@@ -101,7 +109,8 @@
      */
     public boolean isEnabled()
     {
-        return this.getFromClipboard( ConnectionTransfer.getInstance() ) != null;
+        return this.getFromClipboard( ConnectionTransfer.getInstance() ) != null
+            || !getConnectionsByLdapUrl().isEmpty();
     }
 
 
@@ -159,7 +168,8 @@
     {
         List<Connection> connections = new ArrayList<Connection>();
 
-        Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
+        // first check for Connection objects in the clipboard
+        Object content = getFromClipboard( ConnectionTransfer.getInstance() );
         if ( content != null && content instanceof Object[] )
         {
             Object[] objects = ( Object[] ) content;
@@ -172,6 +182,53 @@
             }
         }
 
+        // if there are no Connection objects in the clipboard
+        // then check for LDAP URLs
+        if ( connections.isEmpty() )
+        {
+            List<Connection> connectionByLdapUrl = getConnectionsByLdapUrl();
+            connections.addAll( connectionByLdapUrl );
+        }
+
+        return connections;
+    }
+
+
+    private List<Connection> getConnectionsByLdapUrl()
+    {
+        List<Connection> connections = new ArrayList<Connection>();
+
+        Object content = getFromClipboard( TextTransfer.getInstance() );
+        if ( content != null && content instanceof String )
+        {
+            ConnectionParameterPage[] connectionParameterPages = ConnectionParameterPageManager
+                .getConnectionParameterPages();
+
+            String[] lines = ( ( String ) content ).split( ConnectionCoreConstants.LINE_SEPARATOR
);
+            for ( String line : lines )
+            {
+                line = line.trim();
+                if ( StringUtils.isNotEmpty( line ) )
+                {
+                    try
+                    {
+                        LdapURL ldapUrl = new LdapURL( line );
+                        ConnectionParameter parameter = new ConnectionParameter();
+                        for ( ConnectionParameterPage connectionParameterPage : connectionParameterPages
)
+                        {
+                            connectionParameterPage.mergeLdapUrlToParameters( ldapUrl, parameter
);
+                        }
+                        Connection connection = new Connection( parameter );
+                        connections.add( connection );
+                    }
+                    catch ( LdapURLEncodingException e )
+                    {
+                        // this was a string that doesn't represent an LDAP URL, ignore
+                    }
+                }
+            }
+        }
+
         return connections;
     }
 

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java?rev=688867&r1=688866&r2=688867&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
Mon Aug 25 13:39:30 2008
@@ -22,6 +22,7 @@
 
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
@@ -45,7 +46,6 @@
 import org.eclipse.swt.widgets.Text;
 
 
-
 /**
  * The AuthenticationParameterPage is used the edit the authentication parameters of a
  * connection.
@@ -55,6 +55,22 @@
  */
 public class AuthenticationParameterPage extends AbstractConnectionParameterPage
 {
+    
+    private static final String X_AUTH_METHOD = "X-AUTH-METHOD";
+    
+    private static final String X_AUTH_METHOD_ANONYMOUS = "Anonymous";
+
+    private static final String X_AUTH_METHOD_SIMPLE = "Simple";
+    
+    private static final String X_AUTH_METHOD_DIGEST_MD5 = "DIGEST-MD5";
+    
+    private static final String X_AUTH_METHOD_CRAM_MD5 = "CRAM-MD5";
+    
+    private static final String X_BIND_USER = "X-BIND-USER";
+    
+    private static final String X_BIND_PASSWORD = "X-BIND-PASSWORD";
+
+    private static final String X_SASL_REALM = "X-SASL-REALM";
 
     /** The combo to select the authentication method */
     private Combo authenticationMethodCombo;
@@ -395,11 +411,107 @@
      */
     public boolean isReconnectionRequired()
     {
-        return connectionParameter == null 
-            || connectionParameter.getAuthMethod() != getAuthenticationMethod()
+        return connectionParameter == null || connectionParameter.getAuthMethod() != getAuthenticationMethod()
             || !StringUtils.equals( connectionParameter.getBindPrincipal(), getBindPrincipal()
)
             || !StringUtils.equals( connectionParameter.getBindPassword(), getBindPassword()
)
             || !StringUtils.equals( connectionParameter.getSaslRealm(), getSaslRealm() );
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+    public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapURL ldapUrl
)
+    {
+        switch ( parameter.getAuthMethod() )
+        {
+            case SASL_CRAM_MD5:
+                ldapUrl.getExtensions().put( X_AUTH_METHOD, X_AUTH_METHOD_CRAM_MD5 );
+                break;
+            case SASL_DIGEST_MD5:
+                ldapUrl.getExtensions().put( X_AUTH_METHOD, X_AUTH_METHOD_DIGEST_MD5 );
+                break;
+            case SIMPLE:
+                if ( StringUtils.isEmpty( parameter.getBindPrincipal() ) )
+                {
+                    // default if bind user is present
+                    ldapUrl.getExtensions().put( X_AUTH_METHOD, X_AUTH_METHOD_SIMPLE );
+                }
+                break;
+            case NONE:
+                if ( StringUtils.isNotEmpty( parameter.getBindPrincipal() ) )
+                {
+                    // default if bind user is absent
+                    ldapUrl.getExtensions().put( X_AUTH_METHOD, X_AUTH_METHOD_ANONYMOUS );
+                }
+                break;
+        }
+
+        if ( StringUtils.isNotEmpty( parameter.getBindPrincipal() ) )
+        {
+            ldapUrl.getExtensions().put( X_BIND_USER, parameter.getBindPrincipal() );
+        }
+
+        if ( StringUtils.isNotEmpty( parameter.getBindPassword() ) )
+        {
+            ldapUrl.getExtensions().put( X_BIND_PASSWORD, parameter.getBindPassword() );
+        }
+
+        if ( StringUtils.isNotEmpty( parameter.getSaslRealm() ) )
+        {
+            ldapUrl.getExtensions().put( X_SASL_REALM, parameter.getSaslRealm() );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void mergeLdapUrlToParameters( LdapURL ldapUrl, ConnectionParameter parameter
)
+    {
+        // bind user and password, none if empty or absent
+        String principal = ldapUrl.getExtensions().get( X_BIND_USER );
+        if ( principal == null )
+        {
+            principal = StringUtils.EMPTY;
+        }
+        parameter.setBindPrincipal( principal );
+
+        String password = ldapUrl.getExtensions().get( X_BIND_PASSWORD );
+        parameter.setBindPassword( password );
+
+        // auth method, simple if unknown or absent and X-BIND-USER is present, else anonymous

+        String authMethod = ldapUrl.getExtensions().get( X_AUTH_METHOD );
+        if ( StringUtils.isNotEmpty( authMethod ) && X_AUTH_METHOD_ANONYMOUS.equalsIgnoreCase(
authMethod ) )
+        {
+            parameter.setAuthMethod( ConnectionParameter.AuthenticationMethod.NONE );
+        }
+        else if ( StringUtils.isNotEmpty( authMethod ) && X_AUTH_METHOD_SIMPLE.equalsIgnoreCase(
authMethod ) )
+        {
+            parameter.setAuthMethod( ConnectionParameter.AuthenticationMethod.SIMPLE );
+        }
+        else if ( StringUtils.isNotEmpty( authMethod ) && X_AUTH_METHOD_DIGEST_MD5.equalsIgnoreCase(
authMethod ) )
+        {
+            parameter.setAuthMethod( ConnectionParameter.AuthenticationMethod.SASL_DIGEST_MD5
);
+        }
+        else if ( StringUtils.isNotEmpty( authMethod ) && X_AUTH_METHOD_CRAM_MD5.equalsIgnoreCase(
authMethod ) )
+        {
+            parameter.setAuthMethod( ConnectionParameter.AuthenticationMethod.SASL_CRAM_MD5
);
+        }
+        else if ( StringUtils.isNotEmpty( parameter.getBindPrincipal() ) )
+        {
+            parameter.setAuthMethod( ConnectionParameter.AuthenticationMethod.SIMPLE );
+        }
+        else
+        {
+            parameter.setAuthMethod( ConnectionParameter.AuthenticationMethod.NONE );
+        }
+
+        // SASL realm, none if empty or absent 
+        String saslRealm = ldapUrl.getExtensions().get( X_SASL_REALM );
+        if ( StringUtils.isNotEmpty( saslRealm ) )
+        {
+            parameter.setSaslRealm( saslRealm );
+        }
+    }
 }

Modified: directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java?rev=688867&r1=688866&r2=688867&view=diff
==============================================================================
--- directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java
(original)
+++ directory/studio/trunk/connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java
Mon Aug 25 13:39:30 2008
@@ -21,7 +21,11 @@
 package org.apache.directory.studio.connection.ui.widgets;
 
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 import org.apache.commons.lang.StringUtils;
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
@@ -58,6 +62,14 @@
 public class NetworkParameterPage extends AbstractConnectionParameterPage
 {
 
+    private static final String X_CONNECTION_NAME = "X-CONNECTION-NAME";
+
+    private static final String X_ENCRYPTION = "X-ENCRYPTION";
+
+    private static final String X_ENCRYPTION_LDAPS = "ldaps";
+
+    private static final String X_ENCRYPTION_START_TLS = "StartTLS";
+
     /** The connection name text widget */
     private Text nameText;
 
@@ -150,7 +162,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#createComposite(org.eclipse.swt.widgets.Composite)
+     * {@inheritDoc}
      */
     protected void createComposite( Composite parent )
     {
@@ -198,7 +210,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#validate()
+     * {@inheritDoc}
      */
     protected void validate()
     {
@@ -230,7 +242,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#loadParameters(org.apache.directory.studio.connection.core.ConnectionParameter)
+     * {@inheritDoc}
      */
     protected void loadParameters( ConnectionParameter parameter )
     {
@@ -246,7 +258,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#initListeners()
+     * {@inheritDoc}
      */
     protected void initListeners()
     {
@@ -314,7 +326,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveParameters(org.apache.directory.studio.connection.core.ConnectionParameter)
+     * {@inheritDoc}
      */
     public void saveParameters( ConnectionParameter parameter )
     {
@@ -326,7 +338,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveDialogSettings()
+     * {@inheritDoc}
      */
     public void saveDialogSettings()
     {
@@ -336,7 +348,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#setFocus()
+     * {@inheritDoc}
      */
     public void setFocus()
     {
@@ -345,7 +357,7 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#areParametersModifed()
+     * {@inheritDoc}
      */
     public boolean areParametersModifed()
     {
@@ -354,14 +366,74 @@
 
 
     /**
-     * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#isReconnectionRequired()
+     * {@inheritDoc}
      */
     public boolean isReconnectionRequired()
     {
-        return connectionParameter == null 
-            || !StringUtils.equals(  connectionParameter.getHost(), getHostName() ) 
+        return connectionParameter == null || !StringUtils.equals( connectionParameter.getHost(),
getHostName() )
             || connectionParameter.getPort() != getPort()
             || connectionParameter.getEncryptionMethod() != getEncyrptionMethod();
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+    public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapURL ldapUrl
)
+    {
+        ldapUrl.getExtensions().put( X_CONNECTION_NAME, parameter.getName() );
+
+        ldapUrl.setHost( parameter.getHost() );
+
+        ldapUrl.setPort( parameter.getPort() );
+
+        switch ( parameter.getEncryptionMethod() )
+        {
+            case NONE:
+                // default
+                break;
+            case LDAPS:
+                ldapUrl.getExtensions().put( X_ENCRYPTION, X_ENCRYPTION_LDAPS );
+                break;
+            case START_TLS:
+                ldapUrl.getExtensions().put( X_ENCRYPTION, X_ENCRYPTION_START_TLS );
+                break;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void mergeLdapUrlToParameters( LdapURL ldapUrl, ConnectionParameter parameter
)
+    {
+        // connection name, current date if absent
+        String name = ldapUrl.getExtensions().get( X_CONNECTION_NAME );
+        if ( StringUtils.isEmpty( name ) )
+        {
+            name = new SimpleDateFormat( "yyyy-MM-dd HH-mm-ss" ).format( new Date() ); //$NON-NLS-1$
+        }
+        parameter.setName( name );
+
+        // host
+        parameter.setHost( ldapUrl.getHost() );
+
+        // port
+        parameter.setPort( ldapUrl.getPort() );
+
+        // encryption method, none if unknown or absent 
+        String encryption = ldapUrl.getExtensions().get( X_ENCRYPTION );
+        if ( StringUtils.isNotEmpty( encryption ) && X_ENCRYPTION_LDAPS.equalsIgnoreCase(
encryption ) )
+        {
+            parameter.setEncryptionMethod( ConnectionParameter.EncryptionMethod.LDAPS );
+        }
+        else if ( StringUtils.isNotEmpty( encryption ) && X_ENCRYPTION_START_TLS.equalsIgnoreCase(
encryption ) )
+        {
+            parameter.setEncryptionMethod( ConnectionParameter.EncryptionMethod.START_TLS
);
+        }
+        else
+        {
+            parameter.setEncryptionMethod( ConnectionParameter.EncryptionMethod.NONE );
+        }
+    }
 }

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java?rev=688867&r1=688866&r2=688867&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java
Mon Aug 25 13:39:30 2008
@@ -25,11 +25,12 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage;
-import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.connection.ui.RunnableContextRunner;
+import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.ldapbrowser.common.widgets.search.AliasesDereferencingWidget;
 import org.apache.directory.studio.ldapbrowser.common.widgets.search.LimitWidget;
 import org.apache.directory.studio.ldapbrowser.common.widgets.search.ReferralsHandlingWidget;
@@ -61,6 +62,26 @@
 public class BrowserParameterPage extends AbstractConnectionParameterPage
 {
 
+    private static final String X_BASE_DN = "X-BASE-DN";
+
+    private static final String X_COUNT_LIMIT = "X-COUNT-LIMIT";
+
+    private static final String X_TIME_LIMIT = "X-TIME-LIMIT";
+
+    private static final String X_ALIAS_HANDLING = "X-ALIAS-HANDLING";
+
+    private static final String X_ALIAS_HANDLING_FINDING = "FINDING";
+
+    private static final String X_ALIAS_HANDLING_SEARCHING = "SEARCHING";
+
+    private static final String X_ALIAS_HANDLING_NEVER = "NEVER";
+
+    private static final String X_REFERRAL_HANDLING = "X-REFERRAL-HANDLING";
+
+    private static final String X_REFERRAL_HANDLING_IGNORE = "IGNORE";
+
+    private static final String X_REFERRAL_HANDLING_MANAGE = "MANAGE";
+
     /** The checkbox to fetch the base DN's from namingContexts whenever opening the connection
*/
     private Button autoFetchBaseDnsButton;
 
@@ -407,10 +428,160 @@
         Connection.AliasDereferencingMethod aliasesDereferencingMethod = Connection.AliasDereferencingMethod
             .getByOrdinal( aliasesDereferencingMethodOrdinal );
 
-        return fetchBaseDns != isAutoFetchBaseDns()
-            || !StringUtils.equals( baseDn, getBaseDN() )
+        return fetchBaseDns != isAutoFetchBaseDns() || !StringUtils.equals( baseDn, getBaseDN()
)
             || referralsHandlingMethod != getReferralsHandlingMethod()
             || aliasesDereferencingMethod != getAliasesDereferencingMethod();
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+    public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapURL ldapUrl
)
+    {
+        boolean fetchBaseDns = parameter
+            .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS
);
+        String baseDn = parameter.getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN
);
+        if ( !fetchBaseDns && StringUtils.isNotEmpty( baseDn ) )
+        {
+            ldapUrl.getExtensions().put( X_BASE_DN, baseDn );
+        }
+
+        int countLimit = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT
);
+        if ( countLimit != 0 )
+        {
+            ldapUrl.getExtensions().put( X_COUNT_LIMIT,
+                parameter.getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT
) );
+        }
+
+        int timeLimit = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT
);
+        if ( timeLimit != 0 )
+        {
+            ldapUrl.getExtensions().put( X_TIME_LIMIT,
+                parameter.getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT
) );
+        }
+
+        int aliasesDereferencingMethodOrdinal = parameter
+            .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD
);
+        Connection.AliasDereferencingMethod aliasesDereferencingMethod = Connection.AliasDereferencingMethod
+            .getByOrdinal( aliasesDereferencingMethodOrdinal );
+        switch ( aliasesDereferencingMethod )
+        {
+            case ALWAYS:
+                // default
+                break;
+            case FINDING:
+                ldapUrl.getExtensions().put( X_ALIAS_HANDLING, X_ALIAS_HANDLING_FINDING );
+                break;
+            case SEARCH:
+                ldapUrl.getExtensions().put( X_ALIAS_HANDLING, X_ALIAS_HANDLING_SEARCHING
);
+                break;
+            case NEVER:
+                ldapUrl.getExtensions().put( X_ALIAS_HANDLING, X_ALIAS_HANDLING_NEVER );
+                break;
+        }
+
+        int referralsHandlingMethodOrdinal = parameter
+            .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD
);
+        Connection.ReferralHandlingMethod referralsHandlingMethod = Connection.ReferralHandlingMethod
+            .getByOrdinal( referralsHandlingMethodOrdinal );
+        switch ( referralsHandlingMethod )
+        {
+            case FOLLOW:
+                // default
+                break;
+            case IGNORE:
+                ldapUrl.getExtensions().put( X_REFERRAL_HANDLING, X_REFERRAL_HANDLING_IGNORE
);
+                break;
+            case MANAGE:
+                ldapUrl.getExtensions().put( X_REFERRAL_HANDLING, X_REFERRAL_HANDLING_MANAGE
);
+                break;
+        }
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void mergeLdapUrlToParameters( LdapURL ldapUrl, ConnectionParameter parameter
)
+    {
+        // base DN, get from Root DSE if absent, may be empty 
+        String baseDn = ldapUrl.getExtensions().get( X_BASE_DN );
+        if ( baseDn == null )
+        {
+            parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS,
true );
+            parameter.setExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN,
null );
+        }
+        else
+        {
+            parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS,
false );
+            parameter.setExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN,
baseDn );
+        }
+
+        // count limit, 1000 if non-numeric or absent 
+        String countLimit = ldapUrl.getExtensions().get( X_COUNT_LIMIT );
+        try
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT,
new Integer(
+                countLimit ).intValue() );
+        }
+        catch ( NumberFormatException e )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT,
0 );
+        }
+
+        // time limit, 0 if non-numeric or absent 
+        String timeLimit = ldapUrl.getExtensions().get( X_TIME_LIMIT );
+        try
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT,
new Integer(
+                timeLimit ).intValue() );
+        }
+        catch ( NumberFormatException e )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT,
0 );
+        }
+
+        // alias handling, ALWAYS if unknown or absent
+        String alias = ldapUrl.getExtensions().get( X_ALIAS_HANDLING );
+        if ( StringUtils.isNotEmpty( alias ) && X_ALIAS_HANDLING_FINDING.equalsIgnoreCase(
alias ) )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD,
+                Connection.AliasDereferencingMethod.FINDING.getOrdinal() );
+        }
+        else if ( StringUtils.isNotEmpty( alias ) && X_ALIAS_HANDLING_SEARCHING.equalsIgnoreCase(
alias ) )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD,
+                Connection.AliasDereferencingMethod.SEARCH.getOrdinal() );
+        }
+        else if ( StringUtils.isNotEmpty( alias ) && X_ALIAS_HANDLING_NEVER.equalsIgnoreCase(
alias ) )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD,
+                Connection.AliasDereferencingMethod.NEVER.getOrdinal() );
+        }
+        else
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD,
+                Connection.AliasDereferencingMethod.ALWAYS.getOrdinal() );
+        }
+
+        // referral handling, FOLLOW if unknown or absent
+        String referral = ldapUrl.getExtensions().get( X_REFERRAL_HANDLING );
+        if ( StringUtils.isNotEmpty( referral ) && X_REFERRAL_HANDLING_IGNORE.equalsIgnoreCase(
referral ) )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD,
+                Connection.ReferralHandlingMethod.IGNORE.getOrdinal() );
+        }
+        else if ( StringUtils.isNotEmpty( referral ) && X_REFERRAL_HANDLING_MANAGE.equalsIgnoreCase(
referral ) )
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD,
+                Connection.ReferralHandlingMethod.MANAGE.getOrdinal() );
+        }
+        else
+        {
+            parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD,
+                Connection.ReferralHandlingMethod.FOLLOW.getOrdinal() );
+        }
+    }
 }



Mime
View raw message