directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r576474 - in /directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core: ConnectionManager.java io/ConnectionIO.java
Date Mon, 17 Sep 2007 15:15:48 GMT
Author: pamarcelot
Date: Mon Sep 17 08:15:47 2007
New Revision: 576474

URL: http://svn.apache.org/viewvc?rev=576474&view=rev
Log:
Fix for DIRSTUDIO-191 (Connection Name mess up if it contains non-ascii chars).

Modified:
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java?rev=576474&r1=576473&r2=576474&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
(original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
Mon Sep 17 08:15:47 2007
@@ -22,9 +22,9 @@
 
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -262,7 +262,7 @@
         // To avoid a corrupt file, save object to a temp file first 
         try
         {
-            ConnectionIO.save( connectionParameters, new FileWriter( getConnectionStoreFileName()
+ "-temp" ) );
+            ConnectionIO.save( connectionParameters, new FileOutputStream( getConnectionStoreFileName()
+ "-temp" ) );
         }
         catch ( IOException e )
         {
@@ -277,7 +277,7 @@
         {
             file.delete();
         }
-        
+
         try
         {
             String content = FileUtils.readFileToString( tempFile, "UTF-8" );
@@ -300,14 +300,15 @@
 
         try
         {
-            connectionParameters = ConnectionIO.load( new FileReader( getConnectionStoreFileName()
) );
+            connectionParameters = ConnectionIO.load( new FileInputStream( getConnectionStoreFileName()
) );
         }
         catch ( Exception e )
         {
             // If loading failed, try with temp file
             try
             {
-                connectionParameters = ConnectionIO.load( new FileReader( getConnectionStoreFileName()
+ "-temp" ) );
+                connectionParameters = ConnectionIO
+                    .load( new FileInputStream( getConnectionStoreFileName() + "-temp" )
);
             }
             catch ( FileNotFoundException e1 )
             {

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java?rev=576474&r1=576473&r2=576474&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
(original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
Mon Sep 17 08:15:47 2007
@@ -20,9 +20,8 @@
 package org.apache.directory.studio.connection.core.io;
 
 
-import java.io.BufferedWriter;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -30,13 +29,6 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
@@ -45,9 +37,9 @@
 import org.dom4j.DocumentException;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
-import org.dom4j.io.DocumentResult;
-import org.dom4j.io.DocumentSource;
+import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
 
 
 /**
@@ -78,14 +70,14 @@
     /**
      * Loads the connections using the reader
      *
-     * @param reader
-     *      the reader
+     * @param stream
+     *      the FileInputStream
      * @return
      *      the connections
      * @throws ConnectionIOException 
      *      if an error occurs when converting the document
      */
-    public static List<ConnectionParameter> load( FileReader reader ) throws ConnectionIOException
+    public static List<ConnectionParameter> load( FileInputStream stream ) throws ConnectionIOException
     {
         List<ConnectionParameter> connections = new ArrayList<ConnectionParameter>();
 
@@ -94,7 +86,7 @@
 
         try
         {
-            document = saxReader.read( reader );
+            document = saxReader.read( stream );
         }
         catch ( DocumentException e )
         {
@@ -240,12 +232,12 @@
      *
      * @param connections
      *      the connections
-     * @param writer
-     *      the writer
+     * @param stream
+     *      the OutputStream
      * @throws IOException
      *      if an I/O error occurs
      */
-    public static void save( List<ConnectionParameter> connections, FileWriter writer
) throws IOException
+    public static void save( List<ConnectionParameter> connections, FileOutputStream
stream ) throws IOException
     {
         // Creating the Document
         Document document = DocumentHelper.createDocument();
@@ -262,9 +254,11 @@
         }
 
         // Writing the file to disk
-        BufferedWriter buffWriter = new BufferedWriter( writer );
-        buffWriter.write( styleDocument( document ).asXML() );
-        buffWriter.close();
+        OutputFormat outformat = OutputFormat.createPrettyPrint();
+        outformat.setEncoding( "UTF-8" );
+        XMLWriter writer = new XMLWriter( stream, outformat );
+        writer.write( document );
+        writer.flush();
     }
 
 
@@ -318,45 +312,5 @@
                 extendedPropertyElement.addAttribute( VALUE_TAG, element.getValue() );
             }
         }
-    }
-
-
-    /**
-     * XML Pretty Printer XSLT Transformation
-     * 
-     * @param document
-     *      the Dom4j Document
-     * @return
-     */
-    private static Document styleDocument( Document document )
-    {
-        // load the transformer using JAXP
-        TransformerFactory factory = TransformerFactory.newInstance();
-        Transformer transformer = null;
-        try
-        {
-            transformer = factory.newTransformer( new StreamSource( ConnectionCorePlugin.class
-                .getResourceAsStream( "XmlFileFormat.xslt" ) ) );
-        }
-        catch ( TransformerConfigurationException e1 )
-        {
-            // Will never occur
-        }
-
-        // now lets style the given document
-        DocumentSource source = new DocumentSource( document );
-        DocumentResult result = new DocumentResult();
-        try
-        {
-            transformer.transform( source, result );
-        }
-        catch ( TransformerException e )
-        {
-            // Will never occur
-        }
-
-        // return the transformed document
-        Document transformedDoc = result.getDocument();
-        return transformedDoc;
     }
 }



Mime
View raw message