directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r693477 - in /directory/studio/trunk: ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/
Date Tue, 09 Sep 2008 14:46:04 GMT
Author: pamarcelot
Date: Tue Sep  9 07:46:04 2008
New Revision: 693477

URL: http://svn.apache.org/viewvc?rev=693477&view=rev
Log:
Part of a fix for DIRSTUDIO-355 (DSML Import and Export fail with "Internal Error: null").
	o DSML Export is now working!
	o Added two types for DSML Export:
		- Export as a DSML Response (BatchResponse with SearchResultEntries in it)
		- Export as a DSML Request (BatchRequest with AddRequest in it)

Modified:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlToWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlWizard.java

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java?rev=693477&r1=693476&r2=693477&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportDsmlJob.java
Tue Sep  9 07:46:04 2008
@@ -21,52 +21,31 @@
 package org.apache.directory.studio.ldapbrowser.core.jobs;
 
 
+import java.io.BufferedWriter;
 import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.text.ParseException;
+import java.io.OutputStreamWriter;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.naming.InvalidNameException;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.InvalidAttributeIdentifierException;
+import javax.naming.directory.SearchResult;
+
 import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.AttributeValueAssertion;
-import org.apache.directory.shared.ldap.codec.LdapConstants;
-import org.apache.directory.shared.ldap.codec.search.AndFilter;
-import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter;
-import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter;
-import org.apache.directory.shared.ldap.codec.search.Filter;
-import org.apache.directory.shared.ldap.codec.search.NotFilter;
-import org.apache.directory.shared.ldap.codec.search.OrFilter;
-import org.apache.directory.shared.ldap.codec.search.PresentFilter;
-import org.apache.directory.shared.ldap.codec.search.SearchRequest;
-import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
-import org.apache.directory.shared.ldap.filter.AndNode;
-import org.apache.directory.shared.ldap.filter.ApproximateNode;
-import org.apache.directory.shared.ldap.filter.BranchNode;
-import org.apache.directory.shared.ldap.filter.EqualityNode;
-import org.apache.directory.shared.ldap.filter.ExprNode;
-import org.apache.directory.shared.ldap.filter.ExtensibleNode;
-import org.apache.directory.shared.ldap.filter.FilterParser;
-import org.apache.directory.shared.ldap.filter.GreaterEqNode;
-import org.apache.directory.shared.ldap.filter.LessEqNode;
-import org.apache.directory.shared.ldap.filter.NotNode;
-import org.apache.directory.shared.ldap.filter.OrNode;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
-import org.apache.directory.shared.ldap.filter.SimpleNode;
-import org.apache.directory.shared.ldap.filter.SubstringNode;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
-import org.apache.directory.studio.dsmlv2.engine.Dsmlv2Engine;
-import org.apache.directory.studio.dsmlv2.request.SearchRequestDsml;
+import org.apache.directory.studio.dsmlv2.reponse.BatchResponseDsml;
+import org.apache.directory.studio.dsmlv2.reponse.SearchResponseDsml;
+import org.apache.directory.studio.dsmlv2.reponse.SearchResultEntryDsml;
+import org.apache.directory.studio.dsmlv2.request.AddRequestDsml;
+import org.apache.directory.studio.dsmlv2.request.BatchRequestDsml;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
-import org.apache.directory.studio.ldapbrowser.core.model.StudioControl;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
 
 
 /**
@@ -86,6 +65,20 @@
     /** The Search Parameter of the export*/
     private SearchParameter searchParameter;
 
+    /** The type of the export */
+    private ExportDsmlJobType type = ExportDsmlJobType.RESPONSE;
+
+    /**
+     * This enum contains the two possible export types.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public enum ExportDsmlJobType
+    {
+        RESPONSE, REQUEST
+    };
+
 
     /**
      * Creates a new instance of ExportDsmlJob.
@@ -97,11 +90,13 @@
      * @param searchParameter
      *          the Search Parameter of the export
      */
-    public ExportDsmlJob( String exportDsmlFilename, IBrowserConnection connection, SearchParameter
searchParameter )
+    public ExportDsmlJob( String exportDsmlFilename, IBrowserConnection connection, SearchParameter
searchParameter,
+        ExportDsmlJobType type )
     {
         this.exportDsmlFilename = exportDsmlFilename;
         this.browserConnection = connection;
         this.searchParameter = searchParameter;
+        this.type = type;
 
         setName( BrowserCoreMessages.jobs__export_dsml_name );
     }
@@ -139,93 +134,33 @@
 
         try
         {
-            SearchRequest searchRequest = new SearchRequest();
-            searchRequest.setProtocolOP( searchRequest );
-
-            // DN
-            searchRequest.setBaseObject( searchParameter.getSearchBase( ) );
-
-            // Scope
-            SearchScope scope = searchParameter.getScope();
-            if ( scope == SearchScope.OBJECT )
-            {
-                searchRequest.setScope( org.apache.directory.shared.ldap.filter.SearchScope.OBJECT
);
-            }
-            else if ( scope == SearchScope.ONELEVEL )
-            {
-                searchRequest.setScope( org.apache.directory.shared.ldap.filter.SearchScope.ONELEVEL
);
-            }
-            else if ( scope == SearchScope.SUBTREE )
-            {
-                searchRequest.setScope( org.apache.directory.shared.ldap.filter.SearchScope.SUBTREE
);
-            }
+            // Searching for the requested entries
+            NamingEnumeration<SearchResult> ne = SearchRunnable.search( browserConnection,
searchParameter, monitor );
 
-            // DerefAliases
-            Connection.AliasDereferencingMethod derefAliases = searchParameter.getAliasesDereferencingMethod();
-            switch ( derefAliases )
+            // Getting the DSML string associated to the search
+            // and the type of answer the user is expecting
+            String dsmlExportString = null;
+            switch ( type )
             {
-                case ALWAYS:
-                    searchRequest.setDerefAliases( LdapConstants.DEREF_ALWAYS );
-                    break;
-                case FINDING:
-                    searchRequest.setDerefAliases( LdapConstants.DEREF_FINDING_BASE_OBJ );
-                    break;
-                case NEVER:
-                    searchRequest.setDerefAliases( LdapConstants.NEVER_DEREF_ALIASES );
+                case RESPONSE:
+                    dsmlExportString = processAsDsmlResponse( ne );
                     break;
-                case SEARCH:
-                    searchRequest.setDerefAliases( LdapConstants.DEREF_IN_SEARCHING );
+                case REQUEST:
+                    dsmlExportString = processAsDsmlRequest( ne );
                     break;
-                default:
-                    break;
-            }
-
-            // Time Limit
-            int timeLimit = searchParameter.getTimeLimit();
-            if ( timeLimit != 0 )
-            {
-                searchRequest.setTimeLimit( timeLimit );
-            }
-
-            // Size Limit
-            int countLimit = searchParameter.getCountLimit();
-            if ( countLimit != 0 )
-            {
-                searchRequest.setSizeLimit( countLimit );
-            }
-
-            // Filter
-            searchRequest.setFilter( convertToSharedLdapFilter( searchParameter.getFilter()
) );
-
-            // Attributes
-            String[] returningAttributes = searchParameter.getReturningAttributes();
-            for ( int i = 0; i < returningAttributes.length; i++ )
-            {
-                searchRequest.addAttribute( returningAttributes[i] );
             }
 
-            // Controls
-            List<org.apache.directory.shared.ldap.codec.Control> sharedLdapControls
= convertToSharedLdapControls( searchParameter
-                .getControls() );
-            for ( int i = 0; i < sharedLdapControls.size(); i++ )
+            // Writing the DSML string to the final destination file.
+            if ( dsmlExportString != null )
             {
-                searchRequest.addControl( sharedLdapControls.get( i ) );
+                FileOutputStream fos = new FileOutputStream( exportDsmlFilename );
+                OutputStreamWriter osw = new OutputStreamWriter( fos );
+                BufferedWriter bufferedWriter = new BufferedWriter( osw );
+                bufferedWriter.write( dsmlExportString );
+                bufferedWriter.close();
+                osw.close();
+                fos.close();
             }
-
-            // Executing the request
-            Document xmlRequest = DocumentHelper.createDocument();
-            Element rootElement = xmlRequest.addElement( "batchRequest" );
-            SearchRequestDsml searchRequestDsml = new SearchRequestDsml( searchRequest );
-            searchRequestDsml.toDsml( rootElement );
-            Dsmlv2Engine engine = new Dsmlv2Engine( browserConnection.getConnection().getHost(),
browserConnection
-                .getConnection().getPort(), browserConnection.getConnection().getBindPrincipal(),
browserConnection
-                .getConnection().getBindPassword() );
-            String response = engine.processDSML( xmlRequest.asXML() );
-
-            // Saving the response
-            FileOutputStream fout = new FileOutputStream( exportDsmlFilename );
-            new PrintStream( fout ).println( response );
-            fout.close();
         }
         catch ( Exception e )
         {
@@ -234,237 +169,99 @@
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
-     */
-    protected String getErrorMessage()
-    {
-        return BrowserCoreMessages.jobs__export_dsml_error;
-    }
-
-
-    /**
-     * Converts a String filter into a Shared LDAP Filter.
-     *
-     * @param filter
-     *      the filter String to convert
-     * @return
-     *      the corresponding Shared LDAP Filter
-     * @throws ParseException 
-     * @throws IOException 
-     * @throws DecoderException 
-     */
-    public static Filter convertToSharedLdapFilter( String filter ) throws IOException, ParseException,
-        DecoderException
-    {
-        ExprNode exprNode = FilterParser.parse( filter );
-        return convertToSharedLdapFilter( exprNode );
-    }
-
-
     /**
-     * Converts a ExprNode Filter Model into a Shared LDAP Model.
+     * Processes the {@link NamingEnumeration} as a DSML response.
      *
-     * @param exprNode
-     *      the filter
+     * @param ne
+     *      the naming enumeration
      * @return
-     *      the corresponding filter in the Shared LDAP Model
-     * @throws DecoderException 
+     *      the associated DSML
+     * @throws InvalidNameException 
+     * @throws InvalidAttributeIdentifierException 
      */
-    public static Filter convertToSharedLdapFilter( ExprNode exprNode ) throws DecoderException
+    private String processAsDsmlResponse( NamingEnumeration<SearchResult> ne )
+        throws InvalidAttributeIdentifierException, InvalidNameException
     {
-        Filter sharedLdapFilter = null;
-
-        if ( exprNode instanceof BranchNode )
-        {
-            BranchNode branchNode = ( BranchNode ) exprNode;
-
-            if ( branchNode instanceof AndNode )
-            {
-                AndFilter andFilter = new AndFilter();
-                sharedLdapFilter = andFilter;
-
-                List<Filter> andFilters = iterateOnFilters( branchNode.getChildren()
);
-                for ( int i = 0; i < andFilters.size(); i++ )
-                {
-                    andFilter.addFilter( andFilters.get( i ) );
-                }
-            }
-            else if ( branchNode instanceof OrNode )
-            {
-                OrFilter orFilter = new OrFilter();
-                sharedLdapFilter = orFilter;
-
-                List<Filter> orFilters = iterateOnFilters( branchNode.getChildren()
);
-                for ( int i = 0; i < orFilters.size(); i++ )
-                {
-                    orFilter.addFilter( orFilters.get( i ) );
-                }
-            }
-            else if ( branchNode instanceof NotNode )
-            {
-                NotFilter notFilter = new NotFilter();
-                sharedLdapFilter = notFilter;
-
-                List<Filter> notFilters = iterateOnFilters( branchNode.getChildren()
);
-                notFilter.setNotFilter( notFilters.get( 0 ) );
-            }
-        }
-        else if ( exprNode instanceof PresenceNode )
-        {
-            PresenceNode presenceNode = ( PresenceNode ) exprNode;
-
-            PresentFilter presentFilter = new PresentFilter();
-            sharedLdapFilter = presentFilter;
-
-            presentFilter.setAttributeDescription( presenceNode.getAttribute() );
-        }
-        else if ( exprNode instanceof SimpleNode )
-        {
-            SimpleNode simpleNode = ( SimpleNode ) exprNode;
-
-            if ( simpleNode instanceof ApproximateNode )
-            {
-                AttributeValueAssertionFilter approxMatchFilter = createAttributeValueAssertionFilter(
simpleNode,
-                    LdapConstants.APPROX_MATCH_FILTER );
-                sharedLdapFilter = approxMatchFilter;
-            }
-            else if ( simpleNode instanceof EqualityNode )
-            {
-                AttributeValueAssertionFilter equalityMatchFilter = createAttributeValueAssertionFilter(
simpleNode,
-                    LdapConstants.EQUALITY_MATCH_FILTER );
-                sharedLdapFilter = equalityMatchFilter;
-            }
-            else if ( simpleNode instanceof GreaterEqNode )
-            {
-                AttributeValueAssertionFilter greaterOrEqualFilter = createAttributeValueAssertionFilter(
simpleNode,
-                    LdapConstants.GREATER_OR_EQUAL_FILTER );
-                sharedLdapFilter = greaterOrEqualFilter;
-            }
-            else if ( simpleNode instanceof LessEqNode )
-            {
-                AttributeValueAssertionFilter lessOrEqualFilter = createAttributeValueAssertionFilter(
simpleNode,
-                    LdapConstants.LESS_OR_EQUAL_FILTER );
-                sharedLdapFilter = lessOrEqualFilter;
-            }
-        }
-        else if ( exprNode instanceof ExtensibleNode )
-        {
-            ExtensibleNode extensibleNode = ( ExtensibleNode ) exprNode;
+        BatchResponseDsml batchResponse = new BatchResponseDsml();
+        SearchResponseDsml sr = new SearchResponseDsml();
+        batchResponse.addResponse( sr );
 
-            ExtensibleMatchFilter extensibleMatchFilter = new ExtensibleMatchFilter();
-            sharedLdapFilter = extensibleMatchFilter;
-
-            extensibleMatchFilter.setDnAttributes( extensibleNode.hasDnAttributes() );
-            extensibleMatchFilter.setMatchingRule( extensibleNode.getMatchingRuleId() );
-            extensibleMatchFilter.setMatchValue( extensibleNode.getValue() );
-            extensibleMatchFilter.setType( extensibleNode.getAttribute() );
-        }
-        else if ( exprNode instanceof SubstringNode )
+        while ( ne.hasMoreElements() )
         {
-            SubstringNode substringNode = ( SubstringNode ) exprNode;
-
-            SubstringFilter substringFilter = new SubstringFilter();
-            sharedLdapFilter = substringFilter;
-
-            substringFilter.setType( substringNode.getAttribute() );
-            substringFilter.setInitialSubstrings( substringNode.getInitial() );
-            substringFilter.setFinalSubstrings( substringNode.getFinal() );
-            List<String> anys = substringNode.getAny();
-            for ( int i = 0; i < anys.size(); i++ )
-            {
-                substringFilter.addAnySubstrings( anys.get( i ) );
-            }
+            SearchResult searchResult = ( SearchResult ) ne.nextElement();
+            SearchResultEntryDsml sreDsml = convertToSearchResultEntryDsml( searchResult
);
+            sr.addResponse( sreDsml );
         }
 
-        return sharedLdapFilter;
+        return batchResponse.toDsml();
     }
 
 
     /**
-     * Iterates the conversion on the given List of notdes.
+     * Converts the given {@link SearchResult} to a {@link SearchResultEntryDsml}.
      *
-     * @param filters
-     *      the List of nodes to convert
+     * @param searchResult
+     *      the search result
      * @return
-     *      an array containing the conversion for each Ldap Filter into its Shared LDAP
Model
-     * @throws DecoderException 
+     *      the associated search result entry DSML
+     * @throws InvalidNameException 
+     * @throws InvalidAttributeIdentifierException 
      */
-    private static List<Filter> iterateOnFilters( List<ExprNode> filters ) throws
DecoderException
+    private SearchResultEntryDsml convertToSearchResultEntryDsml( SearchResult searchResult
)
+        throws InvalidAttributeIdentifierException, InvalidNameException
     {
-        List<Filter> filtersList = new ArrayList<Filter>();
+        SearchResultEntryDsml sre = new SearchResultEntryDsml();
+        Entry entry = AttributeUtils.toClientEntry( searchResult.getAttributes(), new LdapDN(
searchResult
+            .getNameInNamespace() ) );
+        sre.setEntry( entry );
 
-        for ( int c = 0; c < filters.size(); c++ )
-        {
-            filtersList.add( convertToSharedLdapFilter( filters.get( c ) ) );
-        }
-
-        return filtersList;
+        return sre;
     }
 
 
     /**
-     * Create and returns an Attribute Value Assertion Filter from the given SimpleNode ant
the given type.
+     * Processes the {@link NamingEnumeration} as a DSML request.
      *
-     * @param node
-     *      the filter to convert
-     * @param type
-     *      the type of the Attribute Value Assertion Filter
+     * @param ne
+     *      the naming enumeration
      * @return
-     *      the corresponding Attribute Value Assertion Filter
+     *      the associated DSML
+     * @throws InvalidNameException 
+     * @throws InvalidAttributeIdentifierException 
      */
-    private static AttributeValueAssertionFilter createAttributeValueAssertionFilter( SimpleNode
node, int type )
+    private String processAsDsmlRequest( NamingEnumeration<SearchResult> ne )
+        throws InvalidAttributeIdentifierException, InvalidNameException
     {
-        AttributeValueAssertionFilter avaFilter = new AttributeValueAssertionFilter( type
);
+        BatchRequestDsml batchRequest = new BatchRequestDsml();
 
-        AttributeValueAssertion assertion = new AttributeValueAssertion();
-        avaFilter.setAssertion( assertion );
-        assertion.setAttributeDesc( node.getAttribute() );
-        assertion.setAssertionValue( node.getValue() );
+        while ( ne.hasMoreElements() )
+        {
+            SearchResult searchResult = ( SearchResult ) ne.nextElement();
+            AddRequestDsml arDsml = convertToAddRequestDsml( searchResult );
+            batchRequest.addRequest( arDsml );
+        }
 
-        return avaFilter;
+        return batchRequest.toDsml();
     }
 
 
-    /**
-     * Converts the given array of Controls into their corresponding representation in the
Shared LDAP Model.
-     *
-     * @param controls
-     *      the array of Controls to convert
-     * @return
-     *      a List of Shared LDAP Control Objects corresponding to the given Controls
-     */
-    private List<org.apache.directory.shared.ldap.codec.Control> convertToSharedLdapControls(
List<StudioControl> controls )
+    private AddRequestDsml convertToAddRequestDsml( SearchResult searchResult )
+        throws InvalidAttributeIdentifierException, InvalidNameException
     {
-        List<org.apache.directory.shared.ldap.codec.Control> returnList = new ArrayList<org.apache.directory.shared.ldap.codec.Control>();
-
-        if ( controls != null )
-        {
-            for ( StudioControl control : controls )
-            {
-                returnList.add( convertToSharedLDAP( control ) );
-            }
-        }
+        AddRequestDsml ar = new AddRequestDsml();
+        Entry entry = AttributeUtils.toClientEntry( searchResult.getAttributes(), new LdapDN(
searchResult
+            .getNameInNamespace() ) );
+        ar.setEntry( entry );
 
-        return returnList;
+        return ar;
     }
 
 
-    /**
-     * Converts the given Control into its corresponding representation in the Shared LDAP
Model.
-     *
-     * @param control
-     *      the Control to convert
-     * @return
-     *      the corresponding Control in the Shared LDAP Model
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
      */
-    private static org.apache.directory.shared.ldap.codec.Control convertToSharedLDAP( StudioControl
control )
+    protected String getErrorMessage()
     {
-        org.apache.directory.shared.ldap.codec.Control sharedLdapControl = new org.apache.directory.shared.ldap.codec.Control();
-
-        sharedLdapControl.setControlType( control.getOid() );
-        sharedLdapControl.setControlValue( control.getControlValue() );
-
-        return sharedLdapControl;
+        return BrowserCoreMessages.jobs__export_dsml_error;
     }
 }

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlToWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlToWizardPage.java?rev=693477&r1=693476&r2=693477&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlToWizardPage.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlToWizardPage.java
Tue Sep  9 07:46:04 2008
@@ -24,7 +24,15 @@
 import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
 import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.ExportDsmlWizard.ExportDsmlWizardSaveAsType;
+import org.eclipse.swt.SWT;
+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.Group;
+import org.eclipse.swt.widgets.Label;
 
 
 /**
@@ -35,6 +43,9 @@
  */
 public class ExportDsmlToWizardPage extends ExportBaseToPage
 {
+    /** The associated wizard */
+    private ExportDsmlWizard wizard;
+
     /** The extensions used by DSML files*/
     private static final String[] EXTENSIONS = new String[]
         { "*.xml", "*.*" };
@@ -48,9 +59,10 @@
      * @param wizard
      *          the wizard the page is attached to
      */
-    public ExportDsmlToWizardPage( String pageName, ExportBaseWizard wizard )
+    public ExportDsmlToWizardPage( String pageName, ExportDsmlWizard wizard )
     {
         super( pageName, wizard );
+        this.wizard = wizard;
         super.setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor(
             BrowserUIConstants.IMG_EXPORT_DSML_WIZARD ) );
     }
@@ -63,6 +75,36 @@
     {
         final Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
         super.createControl( composite );
+
+        Composite saveAsOuterComposite = BaseWidgetUtils.createColumnContainer( composite,
1, 3 );
+        Group saveAsGroup = BaseWidgetUtils.createGroup( saveAsOuterComposite, "Save As",
1 );
+        Composite saveAsComposite = BaseWidgetUtils.createColumnContainer( saveAsGroup, 2,
1 );
+
+        Button saveAsDsmlResponseButton = BaseWidgetUtils.createRadiobutton( saveAsComposite,
"DSML Response", 2 );
+        saveAsDsmlResponseButton.setSelection( true );
+        wizard.setSaveAsType( ExportDsmlWizardSaveAsType.RESPONSE );
+        saveAsDsmlResponseButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                wizard.setSaveAsType( ExportDsmlWizardSaveAsType.RESPONSE );
+            }
+        } );
+        BaseWidgetUtils.createRadioIndent( saveAsComposite, 1 );
+        BaseWidgetUtils.createWrappedLabel( saveAsComposite,
+            "The search will be saved as a response to a DSML search request.", 1 );
+
+        Button saveAsDsmlRequestButton = BaseWidgetUtils.createRadiobutton( saveAsComposite,
"DSML Request", 2 );
+        saveAsDsmlRequestButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                wizard.setSaveAsType( ExportDsmlWizardSaveAsType.REQUEST );
+            }
+        } );
+        BaseWidgetUtils.createRadioIndent( saveAsComposite, 1 );
+        BaseWidgetUtils.createWrappedLabel( saveAsComposite,
+            "The search will be saved as a DSML request containing an add request for each
entry.", 1 );
     }
 
 

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlWizard.java?rev=693477&r1=693476&r2=693477&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlWizard.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportDsmlWizard.java
Tue Sep  9 07:46:04 2008
@@ -22,6 +22,7 @@
 
 
 import org.apache.directory.studio.ldapbrowser.core.jobs.ExportDsmlJob;
+import org.apache.directory.studio.ldapbrowser.core.jobs.ExportDsmlJob.ExportDsmlJobType;
 import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.PlatformUI;
@@ -35,7 +36,7 @@
  */
 public class ExportDsmlWizard extends ExportBaseWizard
 {
-    
+
     /** The title. */
     public static final String WIZARD_TITLE = "DSML Export";
 
@@ -45,6 +46,19 @@
     /** The to page, used to select the target file. */
     private ExportDsmlToWizardPage toPage;
 
+    private ExportDsmlWizardSaveAsType saveAsType = ExportDsmlWizardSaveAsType.RESPONSE;
+
+    /**
+     * This enum contains the two possible export types.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public enum ExportDsmlWizardSaveAsType
+    {
+        RESPONSE, REQUEST
+    };
+
 
     /**
      * Creates a new instance of ExportDsmlWizard.
@@ -100,9 +114,42 @@
         fromPage.saveDialogSettings();
         toPage.saveDialogSettings();
 
-        ExportDsmlJob edj = new ExportDsmlJob( exportFilename, search.getBrowserConnection(),
search.getSearchParameter() );
-        edj.execute();
+        switch ( saveAsType )
+        {
+            case RESPONSE:
+                new ExportDsmlJob( exportFilename, search.getBrowserConnection(), search.getSearchParameter(),
+                    ExportDsmlJobType.RESPONSE ).execute();
+                break;
+            case REQUEST:
+                new ExportDsmlJob( exportFilename, search.getBrowserConnection(), search.getSearchParameter(),
+                    ExportDsmlJobType.REQUEST ).execute();
+                break;
+        }
 
         return true;
     }
+
+
+    /**
+     * Gets the "Save as" type.
+     *
+     * @return
+     *      the "Save as" type
+     */
+    public ExportDsmlWizardSaveAsType getSaveAsType()
+    {
+        return saveAsType;
+    }
+
+
+    /**
+     * Sets the "Save as" type.
+     *
+     * @param saveAsType
+     *      the "Save as" type
+     */
+    public void setSaveAsType( ExportDsmlWizardSaveAsType saveAsType )
+    {
+        this.saveAsType = saveAsType;
+    }
 }



Mime
View raw message