directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r599648 - in /directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration: editor/ model/
Date Fri, 30 Nov 2007 00:05:04 GMT
Author: felixk
Date: Thu Nov 29 16:05:00 2007
New Revision: 599648

URL: http://svn.apache.org/viewvc?rev=599648&view=rev
Log:
Some updates from trunk

Modified:
    directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/GeneralPage.java
    directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
    directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
    directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java
    directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java
    directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java

Modified: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/GeneralPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/GeneralPage.java?rev=599648&r1=599647&r2=599648&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/GeneralPage.java
(original)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/GeneralPage.java
Thu Nov 29 16:05:00 2007
@@ -21,7 +21,6 @@
 
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.directory.studio.apacheds.configuration.dialogs.BinaryAttributeDialog;
@@ -846,7 +845,6 @@
     /**
      * Saves the necessary elements to the input model.
      */
-    @SuppressWarnings("unchecked")
     public void save()
     {
         ServerConfiguration configuration = ( ( ServerConfigurationEditor ) getEditor() ).getServerConfiguration();
@@ -873,8 +871,12 @@
         configuration.setSynchronizationPeriod( Long.parseLong( synchPeriodText.getText()
) );
         configuration.setMaxThreads( Integer.parseInt( maxThreadsText.getText() ) );
 
-        configuration.setSupportedMechanisms( new ArrayList<String>( ( List<String>
) Arrays
-            .asList( (String[])supportedMechanismsTableViewer.getCheckedElements() ) ) );
+        List<String> supportedMechanismsList = new ArrayList<String>();
+        for ( Object supportedMechanism : supportedMechanismsTableViewer.getCheckedElements()
)
+        {
+            supportedMechanismsList.add( ( String ) supportedMechanism );
+        }
+        configuration.setSupportedMechanisms( supportedMechanismsList );
 
         configuration.setAllowAnonymousAccess( allowAnonymousAccessCheckbox.getSelection()
);
         configuration.setEnableAccessControl( enableAccesControlCheckbox.getSelection() );

Modified: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java?rev=599648&r1=599647&r2=599648&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
(original)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
Thu Nov 29 16:05:00 2007
@@ -20,17 +20,16 @@
 package org.apache.directory.studio.apacheds.configuration.editor;
 
 
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.FileWriter;
 
 import org.apache.directory.studio.apacheds.configuration.Activator;
 import org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration;
 import org.apache.directory.studio.apacheds.configuration.model.ServerConfigurationParser;
-import org.apache.directory.studio.apacheds.configuration.model.ServerConfigurationParserException;
 import org.apache.directory.studio.apacheds.configuration.model.ServerConfigurationWriter;
-import org.apache.directory.studio.apacheds.configuration.model.ServerConfigurationWriterException;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.swt.SWT;
@@ -38,7 +37,6 @@
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IPathEditorInput;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.SaveAsDialog;
@@ -78,94 +76,75 @@
         super.init( site, input );
         setPartName( input.getName() );
 
-        if ( input instanceof FileEditorInput )
+        String inputClassName = input.getClass().getName();
+        try
         {
-            FileEditorInput fei = ( FileEditorInput ) input;
-
-            try
+            if ( input instanceof FileEditorInput )
+            // The 'FileEditorInput' class is used when the file is opened
+            // from a project in the workspace.
             {
+                FileEditorInput fei = ( FileEditorInput ) input;
+
                 ServerConfigurationParser parser = new ServerConfigurationParser();
                 serverConfiguration = parser.parse( fei.getFile().getContents() );
-                serverConfiguration.setPath( fei.getFile().getFullPath().toOSString() );
-            }
-            catch ( ServerConfigurationParserException e )
-            {
-                MessageBox messageBox = new MessageBox(
-                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
| SWT.ICON_ERROR );
-                messageBox.setText( "Error!" );
-                messageBox.setMessage( "An error occurred when reading the file." + "\n"
+ e.getMessage() );
-                messageBox.open();
-                return;
             }
-            catch ( CoreException e )
-            {
-                MessageBox messageBox = new MessageBox(
-                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
| SWT.ICON_ERROR );
-                messageBox.setText( "Error!" );
-                messageBox.setMessage( "An error occurred when reading the file." + "\n"
+ e.getMessage() );
-                messageBox.open();
-                return;
-            }
-        }
-        else if ( input instanceof IPathEditorInput )
-        {
-            IPathEditorInput ipei = ( IPathEditorInput ) input;
-            try
+            else if ( inputClassName.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput"
)
+                || inputClassName.equals( "org.eclipse.ui.ide.FileStoreEditorInput" ) )
+            // The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
+            // is used when opening a file from the menu File > Open... in Eclipse 3.2.x
+            // The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
+            // opening a file from the menu File > Open... in Eclipse 3.3.x
             {
+                // We use the tooltip to get the full path of the file
                 ServerConfigurationParser parser = new ServerConfigurationParser();
-                serverConfiguration = parser.parse( new FileInputStream( new File( ipei.getPath().toOSString()
) ) );
-                serverConfiguration.setPath( ipei.getPath().toOSString() );
-            }
-            catch ( ServerConfigurationParserException e )
-            {
-                MessageBox messageBox = new MessageBox(
-                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
| SWT.ICON_ERROR );
-                messageBox.setText( "Error!" );
-                messageBox.setMessage( "An error occurred when reading the file." + "\n"
+ e.getMessage() );
-                messageBox.open();
-                return;
+                serverConfiguration = parser.parse( new FileInputStream( new File( input.getToolTipText()
) ) );
             }
-            catch ( FileNotFoundException e )
+            else if ( input instanceof ServerConfigurationEditorInput )
             {
-                MessageBox messageBox = new MessageBox(
-                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
| SWT.ICON_ERROR );
-                messageBox.setText( "Error!" );
-                messageBox.setMessage( "An error occurred when reading the file." + "\n"
+ e.getMessage() );
-                messageBox.open();
-                return;
-            }
+                // The 'ServerConfigurationEditorInput' class is used when a
+                // new Server Configuration File is created.
+                serverConfiguration = ( ( ServerConfigurationEditorInput ) input ).getServerConfiguration();
+                dirty = true;
+            }
+
+            // TODO What to do in the other cases ?
+
+            //        else
+            //        {
+            //            try
+            //            {
+            //                ServerConfigurationParser parser = new ServerConfigurationParser();
+            //                serverConfiguration = parser.parse( new FileInputStream( new
File( input.getToolTipText() ) ) );
+            //                serverConfiguration.setPath( input.getToolTipText() );
+            //            }
+            //            catch ( ServerConfigurationParserException e )
+            //            {
+            //                MessageBox messageBox = new MessageBox(
+            //                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.OK | SWT.ICON_ERROR );
+            //                messageBox.setText( "Error!" );
+            //                messageBox.setMessage( "An error occurred when reading the
file." + "\n" + e.getMessage() );
+            //                messageBox.open();
+            //                return;
+            //            }
+            //            catch ( FileNotFoundException e )
+            //            {
+            //                MessageBox messageBox = new MessageBox(
+            //                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.OK | SWT.ICON_ERROR );
+            //                messageBox.setText( "Error!" );
+            //                messageBox.setMessage( "An error occurred when reading the
file." + "\n" + e.getMessage() );
+            //                messageBox.open();
+            //                return;
+            //            }
+            //        }
         }
-        else if ( input instanceof ServerConfigurationEditorInput )
+        catch ( Exception e )
         {
-            serverConfiguration = ( ( ServerConfigurationEditorInput ) input ).getServerConfiguration();
-            dirty = true;
-        }
-        else
-        {
-            try
-            {
-                ServerConfigurationParser parser = new ServerConfigurationParser();
-                serverConfiguration = parser.parse( new FileInputStream( new File( input.getToolTipText()
) ) );
-                serverConfiguration.setPath( input.getToolTipText() );
-            }
-            catch ( ServerConfigurationParserException e )
-            {
-                MessageBox messageBox = new MessageBox(
-                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
| SWT.ICON_ERROR );
-                messageBox.setText( "Error!" );
-                messageBox.setMessage( "An error occurred when reading the file." + "\n"
+ e.getMessage() );
-                messageBox.open();
-                return;
-            }
-            catch ( FileNotFoundException e )
-            {
-                MessageBox messageBox = new MessageBox(
-                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK
| SWT.ICON_ERROR );
-                messageBox.setText( "Error!" );
-                messageBox.setMessage( "An error occurred when reading the file." + "\n"
+ e.getMessage() );
-                messageBox.open();
-                return;
-            }
+            MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                SWT.OK | SWT.ICON_ERROR );
+            messageBox.setText( "Error!" );
+            messageBox.setMessage( "An error occurred when reading the file." + "\n" + e.getMessage()
);
+            messageBox.open();
+            return;
         }
     }
 
@@ -202,6 +181,7 @@
      */
     public void doSave( IProgressMonitor monitor )
     {
+        // Saving the Server Configuration
         monitor.beginTask( "Saving the Server Configuration", 5 );
         generalPage.save();
         monitor.worked( 1 );
@@ -212,36 +192,74 @@
         extendedOperationsPage.save();
         monitor.worked( 1 );
 
-        // Checking if the ServerConfiguration is already existing or if it's a new file.
-        if ( serverConfiguration.getPath() == null )
+        try
         {
-            FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.SAVE );
-            fd.setText( "Select a file" );
-            fd.setFilterExtensions( new String[]
-                { "*.xml", "*.*" } );
-            fd.setFilterNames( new String[]
-                { "XML files", "All files" } );
-            String selectedFile = fd.open();
-            // selected == null if 'cancel' has been pushed
-            if ( selectedFile == null || "".equals( selectedFile ) )
-            {
-                monitor.setCanceled( true );
-                return;
+            IEditorInput input = getEditorInput();
+            String inputClassName = input.getClass().getName();
+            if ( input instanceof FileEditorInput )
+            // FileEditorInput class is used when the file is opened
+            // from an project in the workspace.
+            {
+                // Saving the ServerConfiguration to disk
+                FileEditorInput fei = ( FileEditorInput ) input;
+                String xml = ServerConfigurationWriter.toXml( serverConfiguration );
+                fei.getFile().setContents( new ByteArrayInputStream( xml.getBytes() ), true,
true, monitor );
+            }
+            else if ( inputClassName.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput"
)
+                || inputClassName.equals( "org.eclipse.ui.ide.FileStoreEditorInput" ) )
+            // The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
+            // is used when opening a file from the menu File > Open... in Eclipse 3.2.x
+            // The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
+            // opening a file from the menu File > Open... in Eclipse 3.3.x
+            {
+                // Saving the ServerConfiguration to disk
+                BufferedWriter outFile = new BufferedWriter( new FileWriter( input.getToolTipText()
) );
+                String xml = ServerConfigurationWriter.toXml( serverConfiguration );
+                outFile.write( xml );
+                outFile.close();
+            }
+            else if ( input instanceof ServerConfigurationEditorInput )
+            {
+                // The 'ServerConfigurationEditorInput' class is used when a
+                // new Server Configuration File is created.
+                ServerConfigurationEditorInput serverConfigurationEditorInput = ( ServerConfigurationEditorInput
) input;
+
+                // Checking if the ServerConfiguration has already been saved
+                if ( serverConfigurationEditorInput.getPath() == null )
+                {
+                    FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                        SWT.SAVE );
+                    fd.setText( "Select a file" );
+                    fd.setFilterExtensions( new String[]
+                        { "*.xml", "*.*" } );
+                    fd.setFilterNames( new String[]
+                        { "XML files", "All files" } );
+                    String selectedFile = fd.open();
+                    // selected == null if 'cancel' has been pushed
+                    if ( selectedFile == null || "".equals( selectedFile ) )
+                    {
+                        monitor.setCanceled( true );
+                        return;
+                    }
+
+                    // TODO Add the overwrite code...
+
+                    serverConfigurationEditorInput.setPath( selectedFile );
+                    setTitleToolTip( getEditorInput().getToolTipText() );
+                }
+
+                // Saving the ServerConfiguration to disk
+                BufferedWriter outFile = new BufferedWriter( new FileWriter( serverConfigurationEditorInput.getPath()
) );
+                String xml = ServerConfigurationWriter.toXml( serverConfiguration );
+                outFile.write( xml );
+                outFile.close();
             }
 
-            // TODO Add the overwrite code...
-
-            serverConfiguration.setPath( selectedFile );
-            setTitleToolTip( getEditorInput().getToolTipText() );
-        }
-
-        // Saving the ServerConfiguration to disk
-        try
-        {
-            ServerConfigurationWriter writer = new ServerConfigurationWriter();
-            writer.write( serverConfiguration );
+            monitor.worked( 1 );
+            setDirty( false );
+            monitor.done();
         }
-        catch ( ServerConfigurationWriterException e )
+        catch ( Exception e )
         {
             MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                 SWT.OK | SWT.ICON_ERROR );
@@ -252,10 +270,6 @@
             monitor.done();
             return;
         }
-
-        monitor.worked( 1 );
-        setDirty( false );
-        monitor.done();
     }
 
 

Modified: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java?rev=599648&r1=599647&r2=599648&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
(original)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
Thu Nov 29 16:05:00 2007
@@ -36,6 +36,8 @@
 {
     /** The Server Configuration */
     private ServerConfiguration serverConfiguration;
+    /** The path of the file */
+    private String path;
 
 
     /**
@@ -62,12 +64,35 @@
     }
 
 
+    /**
+     * Gets the path.
+     *
+     * @return
+     *      the path
+     */
+    public String getPath()
+    {
+        return path;
+    }
+
+
+    /**
+     * Sets the path.
+     * 
+     * @param path
+     *      the path
+     */
+    public void setPath( String path )
+    {
+        this.path = path;
+    }
+
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.IEditorInput#getToolTipText()
      */
     public String getToolTipText()
     {
-        String path = serverConfiguration.getPath();
         if ( path == null )
         {
             return "New Configuration File";
@@ -134,22 +159,21 @@
         {
             return false;
         }
-        
+
         if ( obj instanceof ServerConfigurationEditorInput )
         {
             ServerConfigurationEditorInput input = ( ServerConfigurationEditorInput ) obj;
             if ( input.exists() && exists() )
             {
-                String inputPath = input.getServerConfiguration().getPath();
-                String myPath = getServerConfiguration().getPath();
+                String inputPath = input.getPath();
 
-                if ( inputPath != null && myPath != null )
+                if ( inputPath != null && path != null )
                 {
-                    return inputPath.equals( myPath );
+                    return inputPath.equals( path );
                 }
             }
         }
-        
+
         return false;
     }
 }

Modified: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java?rev=599648&r1=599647&r2=599648&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java
(original)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java
Thu Nov 29 16:05:00 2007
@@ -32,9 +32,6 @@
  */
 public class ServerConfiguration
 {
-    /** The path of the Server Configuration file */
-    private String path;
-
     // LDAP Configuration
 
     /** The port */
@@ -444,18 +441,6 @@
 
 
     /**
-     * Gets the Path of the file corresponding to the ServerConfiguration.
-     *
-     * @return
-     *      the Path of the corresponding file
-     */
-    public String getPath()
-    {
-        return path;
-    }
-
-
-    /**
      * Gets the LDAP Port.
      *
      * @return
@@ -1005,18 +990,6 @@
     public void setPassword( String password )
     {
         this.password = password;
-    }
-
-
-    /**
-     * Sets the Path of the file corresponding to the ServerConfiguration.
-     *
-     * @param path
-     *      the new value
-     */
-    public void setPath( String path )
-    {
-        this.path = path;
     }
 
 

Modified: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java?rev=599648&r1=599647&r2=599648&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java
(original)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java
Thu Nov 29 16:05:00 2007
@@ -35,10 +35,13 @@
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.apacheds.configuration.Activator;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
 
 
 /**
@@ -65,12 +68,24 @@
     {
         try
         {
+            EntityResolver resolver = new EntityResolver()
+            {
+                public InputSource resolveEntity( String publicId, String systemId )
+                {
+                    if ( publicId.equals( "-//SPRING//DTD BEAN//EN" ) )
+                    {
+                        InputStream in = Activator.class.getResourceAsStream( "spring-beans.dtd"
);
+                        return new InputSource( in );
+                    }
+                    return null;
+                }
+            };
+
             SAXReader reader = new SAXReader();
+            reader.setEntityResolver( resolver );
             Document document = reader.read( path );
 
             ServerConfiguration serverConfiguration = new ServerConfiguration();
-            serverConfiguration.setPath( path );
-
             parse( document, serverConfiguration );
 
             return serverConfiguration;
@@ -107,7 +122,21 @@
     {
         try
         {
+            EntityResolver resolver = new EntityResolver()
+            {
+                public InputSource resolveEntity( String publicId, String systemId )
+                {
+                    if ( publicId.equalsIgnoreCase( "-//SPRING//DTD BEAN//EN" ) )
+                    {
+                        InputStream in = Activator.class.getResourceAsStream( "spring-beans.dtd"
);
+                        return new InputSource( in );
+                    }
+                    return null;
+                }
+            };
+
             SAXReader reader = new SAXReader();
+            reader.setEntityResolver( resolver );
             Document document = reader.read( inputStream );
 
             ServerConfiguration serverConfiguration = new ServerConfiguration();

Modified: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java?rev=599648&r1=599647&r2=599648&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java
(original)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java
Thu Nov 29 16:05:00 2007
@@ -20,9 +20,6 @@
 package org.apache.directory.studio.apacheds.configuration.model;
 
 
-import java.io.BufferedWriter;
-import java.io.FileWriter;
-
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -49,19 +46,17 @@
 public class ServerConfigurationWriter
 {
     /**
-     * Writes the Server Configuration to disk.
+     * TODO
      *
      * @param serverConfiguration
      *      the Server Configuration
      * @throws ServerConfigurationWriterException
      *      if an error occurrs when writing the Server Configuration file
      */
-    public void write( ServerConfiguration serverConfiguration ) throws ServerConfigurationWriterException
+    public static String toXml( ServerConfiguration serverConfiguration ) throws ServerConfigurationWriterException
     {
         try
         {
-            BufferedWriter outFile = new BufferedWriter( new FileWriter( serverConfiguration.getPath()
) );
-
             Document document = DocumentHelper.createDocument();
             Element root = document.addElement( "beans" );
 
@@ -98,11 +93,11 @@
             // CustomEditors Bean
             createCustomEditorsBean( root );
 
-            Document stylizedDocuement = styleDocument( document );
-            stylizedDocuement.addDocType( "beans", "-//SPRING//DTD BEAN//EN",
+            Document stylizedDocument = styleDocument( document );
+            stylizedDocument.addDocType( "beans", "-//SPRING//DTD BEAN//EN",
                 "http://www.springframework.org/dtd/spring-beans.dtd" );
-            outFile.write( stylizedDocuement.asXML() );
-            outFile.close();
+
+            return stylizedDocument.asXML();
         }
         catch ( Exception e )
         {
@@ -122,7 +117,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createEnvironmentBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createEnvironmentBean( Element root, ServerConfiguration serverConfiguration
)
     {
         Element environmentBean = root.addElement( "bean" );
         environmentBean.addAttribute( "id", "environment" );
@@ -173,7 +168,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createChangePasswordConfigurationBean( Element root, ServerConfiguration
serverConfiguration )
+    private static void createChangePasswordConfigurationBean( Element root, ServerConfiguration
serverConfiguration )
     {
         createProtocolConfigurationBean( root, "changePasswordConfiguration",
             "org.apache.directory.server.changepw.ChangePasswordConfiguration", serverConfiguration
@@ -189,7 +184,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createNtpConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createNtpConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
     {
         createProtocolConfigurationBean( root, "ntpConfiguration", "org.apache.directory.server.ntp.NtpConfiguration",
             serverConfiguration.isEnableNtp(), serverConfiguration.getNtpPort() );
@@ -204,7 +199,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createDnsConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createDnsConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
     {
         createProtocolConfigurationBean( root, "dnsConfiguration", "org.apache.directory.server.dns.DnsConfiguration",
             serverConfiguration.isEnableDns(), serverConfiguration.getDnsPort() );
@@ -219,7 +214,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createKdcConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createKdcConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
     {
         createProtocolConfigurationBean( root, "kdcConfiguration", "org.apache.directory.server.kdc.KdcConfiguration",
             serverConfiguration.isEnableKerberos(), serverConfiguration.getKerberosPort()
);
@@ -234,7 +229,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createLdapsConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createLdapsConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
     {
         Element ldapsConfiguration = createProtocolConfigurationBean( root, "ldapsConfiguration",
             "org.apache.directory.server.ldap.LdapConfiguration", serverConfiguration.isEnableLdaps(),
@@ -255,7 +250,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createLdapConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createLdapConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
     {
         Element ldapConfiguration = createProtocolConfigurationBean( root, "ldapConfiguration",
             "org.apache.directory.server.ldap.LdapConfiguration", true, serverConfiguration.getLdapPort()
);
@@ -356,7 +351,7 @@
      * @return
      *      the corresponding Protocol Configuration Bean
      */
-    private Element createProtocolConfigurationBean( Element root, String id, String className,
boolean enabled,
+    private static Element createProtocolConfigurationBean( Element root, String id, String
className, boolean enabled,
         int ipPort )
     {
         Element protocolConfigurationBean = root.addElement( "bean" );
@@ -385,7 +380,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
+    private static void createConfigurationBean( Element root, ServerConfiguration serverConfiguration
)
     {
         Element configurationBean = root.addElement( "bean" );
         configurationBean.addAttribute( "id", "configuration" );
@@ -514,7 +509,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createSystemPartitionConfigurationBean( Element root, ServerConfiguration
serverConfiguration )
+    private static void createSystemPartitionConfigurationBean( Element root, ServerConfiguration
serverConfiguration )
     {
         Partition systemPartition = null;
         for ( Partition partition : serverConfiguration.getPartitions() )
@@ -541,7 +536,7 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createUserPartitionsConfigurationsBean( Element root, ServerConfiguration
serverConfiguration )
+    private static void createUserPartitionsConfigurationsBean( Element root, ServerConfiguration
serverConfiguration )
     {
         int counter = 1;
         for ( Partition partition : serverConfiguration.getPartitions() )
@@ -565,7 +560,7 @@
      * @param name
      *      the name to use
      */
-    private void createPartitionConfigurationBean( Element root, Partition partition, String
name )
+    private static void createPartitionConfigurationBean( Element root, Partition partition,
String name )
     {
         Element partitionBean = root.addElement( "bean" );
         partitionBean.addAttribute( "id", name );
@@ -658,7 +653,7 @@
      * @param root
      *      the root Element
      */
-    private void createCustomEditorsBean( Element root )
+    private static void createCustomEditorsBean( Element root )
     {
         Element customEditorsBean = root.addElement( "bean" );
         customEditorsBean.addAttribute( "class", "org.springframework.beans.factory.config.CustomEditorConfigurer"
);
@@ -682,7 +677,7 @@
      *      the stylized Document
      * @throws TransformerException 
      */
-    private Document styleDocument( Document document ) throws TransformerException
+    private static Document styleDocument( Document document ) throws TransformerException
     {
         // load the transformer using JAXP
         TransformerFactory factory = TransformerFactory.newInstance();



Mime
View raw message