directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1222102 - in /directory/studio/trunk/plugins/connection.ui: resources/icons/ src/main/java/org/apache/directory/studio/connection/ui/ src/main/java/org/apache/directory/studio/connection/ui/widgets/ src/main/java/org/apache/directory/studi...
Date Thu, 22 Dec 2011 08:43:13 GMT
Author: pamarcelot
Date: Thu Dec 22 08:43:12 2011
New Revision: 1222102

URL: http://svn.apache.org/viewvc?rev=1222102&view=rev
Log:
Fix for DIRSTUDIO-694 (Add ability to export certificates in the 'Certificate Validation'
preference page)

Added:
    directory/studio/trunk/plugins/connection.ui/resources/icons/certificate_export_wizard.gif
  (with props)
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java
Modified:
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_de.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_fr.properties

Added: directory/studio/trunk/plugins/connection.ui/resources/icons/certificate_export_wizard.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/resources/icons/certificate_export_wizard.gif?rev=1222102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/plugins/connection.ui/resources/icons/certificate_export_wizard.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
Thu Dec 22 08:43:12 2011
@@ -93,6 +93,9 @@ public final class ConnectionUIConstants
     /** The collapse all image */
     public static final String IMG_COLLAPSEALL = "resources/icons/collapseall.gif"; //$NON-NLS-1$
 
+    /** The export certificate wizard image */
+    public static final String IMG_CERTIFICATE_EXPORT_WIZARD = "resources/icons/certificate_export_wizard.gif";
//$NON-NLS-1$
+
     public static final String TYPENAME = ConnectionUIPlugin.getDefault().getPluginProperties()
         .getString( "ConnectionTransfert_Typename" ); //$NON-NLS-1$
 

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
Thu Dec 22 08:43:12 2011
@@ -34,6 +34,7 @@ import org.apache.directory.studio.conne
 import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
 import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
 import org.apache.directory.studio.connection.ui.dialogs.CertificateInfoDialog;
+import org.apache.directory.studio.connection.ui.wizards.ExportCertificateWizard;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -45,6 +46,7 @@ import org.eclipse.jface.viewers.Selecti
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -71,6 +73,7 @@ public class CertificateListComposite ex
     private Button viewButton;
     private Button addButton;
     private Button removeButton;
+    private Button exportButton;
 
 
     /**
@@ -111,8 +114,9 @@ public class CertificateListComposite ex
         {
             public void selectionChanged( SelectionChangedEvent event )
             {
-                viewButton.setEnabled( !event.getSelection().isEmpty() );
+                viewButton.setEnabled( ( ( IStructuredSelection ) event.getSelection() ).size()
== 1 );
                 removeButton.setEnabled( !event.getSelection().isEmpty() );
+                exportButton.setEnabled( ( ( IStructuredSelection ) event.getSelection()
).size() == 1 );
             }
         } );
         tableViewer.addDoubleClickListener( new IDoubleClickListener()
@@ -207,6 +211,21 @@ public class CertificateListComposite ex
                 tableViewer.refresh();
             }
         } );
+
+        exportButton = BaseWidgetUtils.createButton( buttonContainer, Messages
+            .getString( "CertificateListComposite.ExportButton" ), 1 ); //$NON-NLS-1$
+        exportButton.setEnabled( false );
+        exportButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                X509Certificate certificate = ( X509Certificate ) ( ( IStructuredSelection
) tableViewer.getSelection() )
+                    .getFirstElement();
+
+                WizardDialog dialog = new WizardDialog( getShell(), new ExportCertificateWizard(
certificate ) );
+                dialog.open();
+            }
+        } );
     }
 
 

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
Thu Dec 22 08:43:12 2011
@@ -107,6 +107,7 @@ CertificateListComposite.UntitledCertifi
 CertificateListComposite.LoadCertificate        = Load Certificate
 CertificateListComposite.ErrorDialogTitle       = Error
 CertificateListComposite.ErrorDialogMessage     = An error occurred while adding the certificate:
{0}
+CertificateListComposite.ExportButton 			= Export...
 
 NetworkParameterPage.CheckNetworkParameter        = Check Network Parameter
 NetworkParameterPage.ConnectionEstablished        = The connection was established successfully.

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
Thu Dec 22 08:43:12 2011
@@ -106,6 +106,7 @@ CertificateListComposite.UntitledCertifi
 CertificateInfoComposite.LoadCertificate        = Zertifikat laden
 CertificateInfoComposite.ErrorDialogTitle       = Fehler
 CertificateInfoComposite.ErrorDialogMessage     = TODO:An error occurred while adding the
certificate: {0}
+CertificateListComposite.ExportButton 			= Exportieren...
 
 NetworkParameterPage.CheckNetworkParameter        = Netzwerkparameter \u00FCberpr\u00FCfen
 NetworkParameterPage.ConnectionEstablished        = Die Verbindung wurde erfolgreich aufgebaut.

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
Thu Dec 22 08:43:12 2011
@@ -105,6 +105,7 @@ CertificateListComposite.UntitledCertifi
 CertificateListComposite.LoadCertificate        = Charger un certificat
 CertificateListComposite.ErrorDialogTitle       = Erreur
 CertificateListComposite.ErrorDialogMessage     = Une erreur est survenue lors de l'ajout
du certificat : {0}
+CertificateListComposite.ExportButton 			= Exporter...
 
 NetworkParameterPage.CheckNetworkParameter        = V\u00E9rifier les param\u00E8tres r\u00E9seau
 NetworkParameterPage.ConnectionEstablished        = La connexion a \u00E9t\u00E9 \u00E9tablie
avec succ\u00E8s

Added: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java?rev=1222102&view=auto
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java
(added)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java
Thu Dec 22 08:43:12 2011
@@ -0,0 +1,214 @@
+/*
+ *  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.studio.connection.ui.wizards;
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.X509Certificate;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.studio.connection.ui.wizards.ExportCertificateWizardPage.CertificateExportFormat;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * The ExportCertificateWizard is used to export a certificate.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExportCertificateWizard extends Wizard
+{
+    /** The certificate */
+    private X509Certificate certificate;
+
+    /** The wizard page */
+    private ExportCertificateWizardPage page;
+
+
+    /**
+     * Creates a new instance of ExportCertificateWizard.
+     * 
+     * @param certificate the certificate
+     */
+    public ExportCertificateWizard( X509Certificate certificate )
+    {
+        this.certificate = certificate;
+        setWindowTitle( Messages.getString( "ExportCertificateWizard.ExportCertificate" )
); //$NON-NLS-1$
+        setNeedsProgressMonitor( false );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+        // Nothing to do
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addPages()
+    {
+        page = new ExportCertificateWizardPage();
+        addPage( page );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean performFinish()
+    {
+        // Getting the export format
+        CertificateExportFormat format = page.getCertificateExportFormat();
+
+        try
+        {
+            switch ( format )
+            {
+                case DER:
+                    return exportAsDerFormat();
+                case PEM:
+                    return exportAsPemFormat();
+            }
+        }
+        catch ( Exception e )
+        {
+            MessageDialog.openError( getShell(),
+                Messages.getString( "ExportCertificateWizard.ErrorDialogTitle" ), //$NON-NLS-1$
+                NLS.bind( Messages.getString( "ExportCertificateWizard.ErrorDialogMessage"
),
+                    e.getMessage() ) );
+            return false;
+        }
+
+        return false;
+    }
+
+
+    /**
+     * Exports the certificate as DER format.
+     *
+     * @return <code>true</code> if the export is successful
+     * @throws CertificateEncodingException
+     * @throws IOException
+     */
+    private boolean exportAsDerFormat() throws CertificateEncodingException, IOException
+    {
+        // Getting the export file
+        File exportFile = page.getExportFile();
+
+        // Exporting the certificate
+        FileUtils.writeByteArrayToFile( exportFile, certificate.getEncoded() );
+
+        return true;
+    }
+
+
+    /**
+     * Exports the certificate as PEM format.
+     *
+     * @return <code>true</code> if the export is successful
+     * @throws CertificateEncodingException
+     * @throws IOException
+     */
+    private boolean exportAsPemFormat() throws CertificateEncodingException, IOException
+    {
+        // Getting the export file
+        File exportFile = page.getExportFile();
+
+        // Exporting the certificate
+        FileOutputStream fos = new FileOutputStream( exportFile );
+        OutputStreamWriter osw = new OutputStreamWriter( fos, Charset.forName( "UTF-8" )
); //$NON-NLS-1$
+        osw.write( "-----BEGIN CERTIFICATE-----\n" ); //$NON-NLS-1$
+        osw.write( stripLineToNChars( new String( Base64.encodeBase64( certificate.getEncoded()
),
+            Charset.forName( "UTF-8" ) ), 64 ) ); //$NON-NLS-1$
+        osw.write( "\n-----END CERTIFICATE-----\n" ); //$NON-NLS-1$
+        osw.flush();
+        fos.close();
+
+        return true;
+    }
+
+
+    /**
+     * Strips the String every n specified characters
+     * 
+     * @param str the string to strip
+     * @param nbChars the number of characters
+     * @return the stripped String
+     */
+    public static String stripLineToNChars( String str, int nbChars )
+    {
+        int strLength = str.length();
+
+        if ( strLength <= nbChars )
+        {
+            return str;
+        }
+
+        // We will first compute the new size of the result
+        // It's at least nbChars chars plus one for \n
+        int charsPerLine = nbChars;
+
+        int remaining = ( strLength - nbChars ) % charsPerLine;
+
+        int nbLines = 1 + ( ( strLength - nbChars ) / charsPerLine ) + ( remaining == 0 ?
0 : 1 );
+
+        int nbCharsTotal = strLength + nbLines + nbLines - 2;
+
+        char[] buffer = new char[nbCharsTotal];
+        char[] orig = str.toCharArray();
+
+        int posSrc = 0;
+        int posDst = 0;
+
+        System.arraycopy( orig, posSrc, buffer, posDst, nbChars );
+        posSrc += nbChars;
+        posDst += nbChars;
+
+        for ( int i = 0; i < nbLines - 2; i++ )
+        {
+            buffer[posDst++] = '\n';
+
+            System.arraycopy( orig, posSrc, buffer, posDst, charsPerLine );
+            posSrc += charsPerLine;
+            posDst += charsPerLine;
+        }
+
+        buffer[posDst++] = '\n';
+        System.arraycopy( orig, posSrc, buffer, posDst, remaining == 0 ? charsPerLine : remaining
);
+
+        return new String( buffer );
+    }
+}

Added: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java?rev=1222102&view=auto
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java
(added)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java
Thu Dec 22 08:43:12 2011
@@ -0,0 +1,274 @@
+/*
+ *  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.studio.connection.ui.wizards;
+
+
+import java.io.File;
+
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
+import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements the Export Certificate wizard page.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExportCertificateWizardPage extends WizardPage
+{
+    // UI widgets
+    private Text fileText;
+    private Button browseButton;
+    private Button overwriteFileButton;
+    private ComboViewer formatComboViewer;
+
+
+    /**
+     * Creates a new instance of NewConnectionWizard.
+     * 
+     * @param page the page
+     * @param wizard the wizard
+     */
+    public ExportCertificateWizardPage()
+    {
+        super( "ExportCertificateWizardPage" );
+        setTitle( Messages.getString( "ExportCertificateWizardPage.ExportCertificate" ) );
//$NON-NLS-1$
+        setDescription( Messages.getString( "ExportCertificateWizardPage.PleaseSelectFileAndFormat"
) ); //$NON-NLS-1$ 
+        setImageDescriptor( ConnectionUIPlugin.getDefault().getImageDescriptor(
+            ConnectionUIConstants.IMG_CERTIFICATE_EXPORT_WIZARD ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createControl( Composite parent )
+    {
+        // Creating the composite
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+        composite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Creating the file's group widget
+        Group fileGroup = BaseWidgetUtils.createGroup( composite,
+            Messages.getString( "ExportCertificateWizardPage.File" ), 1 ); //$NON-NLS-1$
+        fileGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        Composite fileComposite = BaseWidgetUtils.createColumnContainer( fileGroup, 2, 1
);
+        fileComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Creating the file's text widget
+        fileText = BaseWidgetUtils.createText( fileComposite, "", 1 );
+        fileText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+        fileText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                validate();
+            }
+        } );
+
+        // Creating the file's 'Browse' button widget
+        browseButton = BaseWidgetUtils.createButton( fileComposite,
+            Messages.getString( "ExportCertificateWizardPage.Browse" ), 1 ); //$NON-NLS-1$
+        browseButton.addSelectionListener( new SelectionAdapter()
+        {
+            /**
+             * {@inheritDoc}
+             */
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportFile();
+                validate();
+            }
+        } );
+
+        // Creating the file's 'Overwrite' button widget
+        overwriteFileButton = BaseWidgetUtils.createCheckbox( fileComposite,
+            Messages.getString( "ExportCertificateWizardPage.OverwriteExistingFile" ), 2
); //$NON-NLS-1$
+        overwriteFileButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                validate();
+            }
+        } );
+
+        // Creating the format's group widget
+        Group formatGroup = BaseWidgetUtils.createGroup( composite,
+            Messages.getString( "ExportCertificateWizardPage.Format" ), 1 ); //$NON-NLS-1$
+        formatGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Creating the format's combo viewer widget
+        formatComboViewer = new ComboViewer( formatGroup );
+        formatComboViewer.setContentProvider( new ArrayContentProvider() );
+        formatComboViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof CertificateExportFormat )
+                {
+                    CertificateExportFormat format = ( CertificateExportFormat ) element;
+
+                    switch ( format )
+                    {
+                        case DER:
+                            return "X509 Certificat DER";
+                        case PEM:
+                            return "X509 Certificat PEM";
+                    }
+                }
+
+                return super.getText( element );
+            }
+        } );
+        formatComboViewer.setInput( new CertificateExportFormat[]
+            { CertificateExportFormat.DER, CertificateExportFormat.PEM } );
+        formatComboViewer.setSelection( new StructuredSelection( CertificateExportFormat.DER
) );
+        formatComboViewer.getControl().setLayoutData( new GridData( SWT.FILL, SWT.NONE, true,
false ) );
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Validates the page.
+     */
+    private void validate()
+    {
+        File file = new File( fileText.getText() );
+        if ( file.isDirectory() )
+        {
+            displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileNotAFile"
) ); //$NON-NLS-1$
+            return;
+        }
+        else if ( file.exists() && !overwriteFileButton.getSelection() )
+        {
+            displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileAlreadyExists"
) ); //$NON-NLS-1$
+            return;
+        }
+        else if ( file.exists() && !file.canWrite() )
+        {
+            displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileNotWritable"
) ); //$NON-NLS-1$
+            return;
+        }
+        else if ( file.getParentFile() == null )
+        {
+            displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileDirectoryNotWritable"
) ); //$NON-NLS-1$
+            return;
+        }
+
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message the message to display
+     */
+    protected void displayErrorMessage( String message )
+    {
+        setMessage( null, DialogPage.NONE );
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * This method is called when the 'browse' button is selected.
+     */
+    private void chooseExportFile()
+    {
+        FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.SAVE );
+        dialog.setText( Messages.getString( "ExportCertificateWizardPage.ChooseFile" ) );
//$NON-NLS-1$
+        if ( !"".equals( fileText.getText() ) ) //$NON-NLS-1$
+        {
+            dialog.setFilterPath( fileText.getText() );
+        }
+
+        String selectedFile = dialog.open();
+        if ( selectedFile != null )
+        {
+            fileText.setText( selectedFile );
+        }
+    }
+
+
+    /**
+     * Returns the export file.
+     *
+     * @return the export file
+     */
+    public File getExportFile()
+    {
+        return new File( fileText.getText() );
+    }
+
+
+    /**
+     * Gets the certificate export format.
+     *
+     * @return the certificate export format
+     */
+    public CertificateExportFormat getCertificateExportFormat()
+    {
+        StructuredSelection selection = ( StructuredSelection ) formatComboViewer.getSelection();
+        if ( !selection.isEmpty() )
+        {
+            return ( CertificateExportFormat ) selection.getFirstElement();
+        }
+
+        // Default format
+        return CertificateExportFormat.DER;
+    }
+
+    /**
+     * This enum represents the various certificate export formats.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     */
+    enum CertificateExportFormat
+    {
+        DER, PEM
+    }
+}
\ No newline at end of file

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages.properties?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages.properties
Thu Dec 22 08:43:12 2011
@@ -16,3 +16,19 @@
 # under the License.
 
 NewConnectionWizard.NewLdapConnection=New LDAP Connection
+
+ExportCertificateWizard.ErrorDialogTitle=Error
+ExportCertificateWizard.ErrorDialogMessage=An error occurred while exporting the certificate:
{0}
+ExportCertificateWizard.ExportCertificate=Export Certificate
+
+ExportCertificateWizardPage.Browse=Bro&wse...
+ExportCertificateWizardPage.ChooseFile=Choose a file
+ExportCertificateWizardPage.ErrorFileAlreadyExists=Selected file already exists. Select option
'Overwrite existing file' if you want to overwrite the file.
+ExportCertificateWizardPage.ErrorFileDirectoryNotWritable=Selected file directory is not
writeable.
+ExportCertificateWizardPage.ErrorFileNotAFile=Selected file is not a file.
+ExportCertificateWizardPage.ErrorFileNotWritable=Selected file is not writeable.
+ExportCertificateWizardPage.ExportCertificate=Export Certificate
+ExportCertificateWizardPage.File=File
+ExportCertificateWizardPage.Format=Format
+ExportCertificateWizardPage.OverwriteExistingFile=O&verwrite existing file
+ExportCertificateWizardPage.PleaseSelectFileAndFormat=Please select the file and format you
want to export the certificate to.
\ No newline at end of file

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_de.properties?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_de.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_de.properties
Thu Dec 22 08:43:12 2011
@@ -16,3 +16,19 @@
 # under the License.
 
 NewConnectionWizard.NewLdapConnection=Neue LDAP Verbindung
+
+ExportCertificateWizard.ErrorDialogTitle=Fehler
+ExportCertificateWizard.ErrorDialogMessage=TODO:An error occurred while exporting the certificate:
{0}
+ExportCertificateWizard.ExportCertificate=Zertifikat exportieren
+
+ExportCertificateWizardPage.Browse=Bro&wsen...
+ExportCertificateWizardPage.ChooseFile=Datei ausw\u00E4hlen
+ExportCertificateWizardPage.ErrorFileAlreadyExists=Die Datei existiert bereits. W\u00E4hle
Option 'Bestehende Datei \u00FCberschreiben', wenn die Datei \u00FCberschrieben werden soll.
+ExportCertificateWizardPage.ErrorFileDirectoryNotWritable=Verzeichnis der ausgew\u00E4hlten
Datei ist nicht beschreibbar.
+ExportCertificateWizardPage.ErrorFileNotAFile=Ausgew\u00E4hlte Datei ist keine Datei.
+ExportCertificateWizardPage.ErrorFileNotWritable=Ausgew\u00E4hlte Datei ist nicht beschreibbar.
+ExportCertificateWizardPage.ExportCertificate=TODO:Export Certificate
+ExportCertificateWizardPage.File=Datei
+ExportCertificateWizardPage.Format=Format
+ExportCertificateWizardPage.OverwriteExistingFile=Bestehende Datei &\u00FCberschreiben
+ExportCertificateWizardPage.PleaseSelectFileAndFormat=TODO:Please select the file and format
you want to export the certificate to.

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_fr.properties?rev=1222102&r1=1222101&r2=1222102&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_fr.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/messages_fr.properties
Thu Dec 22 08:43:12 2011
@@ -16,3 +16,19 @@
 # under the License.
 
 NewConnectionWizard.NewLdapConnection=Nouvelle connexion LDAP
+
+ExportCertificateWizard.ErrorDialogTitle=Erreur
+ExportCertificateWizard.ErrorDialogMessage=Une erreur est survenue lors de l'export du certificat
: {0}
+ExportCertificateWizard.ExportCertificate=Exporter le certificat
+
+ExportCertificateWizardPage.Browse=Parco&urir...
+ExportCertificateWizardPage.ChooseFile=Choisir un fichier
+ExportCertificateWizardPage.ErrorFileAlreadyExists=Le fichier s\u00E9lectionn\u00E9 existe
d\u00E9j\u00E0. Choisissez l'option 'Ecraser le fichier existant' si vous voulez remplacer
ce fichier.
+ExportCertificateWizardPage.ErrorFileDirectoryNotWritable=Le r\u00E9pertoire s\u00E9lectionn\u00E9
n'est pas accessible en \u00E9criture.
+ExportCertificateWizardPage.ErrorFileNotAFile=L'\u00E9l\u00E9ment s\u00E9lectionn\u00E9 n'est
pas un fichier.
+ExportCertificateWizardPage.ErrorFileNotWritable=Le fichier s\u00E9lectionn\u00E9 n'est pas
accessible en \u00E9criture.
+ExportCertificateWizardPage.ExportCertificate=Exporter le certificat
+ExportCertificateWizardPage.File=Fichier
+ExportCertificateWizardPage.Format=Format
+ExportCertificateWizardPage.OverwriteExistingFile=Ecraser le fichier existant
+ExportCertificateWizardPage.PleaseSelectFileAndFormat=Veuillez s\u00E9lectionner le fichier
et le format dans lequel vous souhaitez exporter le certificat.



Mime
View raw message