directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1045127 - /directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java
Date Mon, 13 Dec 2010 14:17:22 GMT
Author: pamarcelot
Date: Mon Dec 13 14:17:22 2010
New Revision: 1045127

URL: http://svn.apache.org/viewvc?rev=1045127&view=rev
Log:
Renamed 'write...' methods.
Added a new 'writeToString()' which convert the configuration to simple a string.

Modified:
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java

Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java?rev=1045127&r1=1045126&r2=1045127&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java
(original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java
Mon Dec 13 14:17:22 2010
@@ -125,9 +125,9 @@ public class ConfigWriter
      * @throws IOException
      *      if an error occurs when writing the file
      */
-    public void write( String path ) throws ConfigurationException, IOException
+    public void writeToPath( String path ) throws ConfigurationException, IOException
     {
-        write( new File( path ) );
+        writeToFile( new File( path ) );
     }
 
 
@@ -141,19 +141,38 @@ public class ConfigWriter
      * @throws IOException
      *      if an error occurs when writing the file
      */
-    public void write( File file ) throws ConfigurationException, IOException
+    public void writeToFile( File file ) throws ConfigurationException, IOException
+    {
+        // Writing the file to disk
+        FileWriter writer = new FileWriter( file );
+        writer.append( writeToString() );
+        writer.close();
+    }
+
+
+    /**
+     * Writes the configuration to a String object.
+     *
+     * @return
+     *      a String containing the LDIF 
+     *      representation of the configuration
+     * @throws ConfigurationException
+     *      if an error occurs during the conversion to LDIF
+     */
+    public String writeToString() throws ConfigurationException
     {
         // Converting the configuration bean to a list of LDIF entries
         convertConfigurationBeanToLdifEntries();
 
-        // Writing the file to disk
-        FileWriter writer = new FileWriter( file );
-        writer.append( "version: 1\n" );
+        // Building the StringBuilder
+        StringBuilder sb = new StringBuilder();
+        sb.append( "version: 1\n" );
         for ( LdifEntry entry : entries )
         {
-            writer.append( entry.toString() );
+            sb.append( entry.toString() );
         }
-        writer.close();
+
+        return sb.toString();
     }
 
 



Mime
View raw message