directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r531264 - in /directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core: jobs/ExportCsvJob.java jobs/ExportXlsJob.java utils/LdifUtils.java
Date Sun, 22 Apr 2007 20:17:55 GMT
Author: seelmann
Date: Sun Apr 22 13:17:54 2007
New Revision: 531264

URL: http://svn.apache.org/viewvc?view=rev&rev=531264
Log:
Fix for DIRSTUDIO-82. Improved test if a value could be encoded to the requested encoding.

Modified:
    directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java
    directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java
    directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java

Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java?view=diff&rev=531264&r1=531263&r2=531264
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportCsvJob.java
Sun Apr 22 13:17:54 2007
@@ -25,6 +25,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -34,6 +35,7 @@
 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.AttributeDescription;
 import org.apache.directory.ldapstudio.browser.core.internal.model.ConnectionException;
 import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralException;
 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
@@ -124,11 +126,11 @@
                     bufferedWriter.write( attributeDelimiter );
             }
             bufferedWriter.write( BrowserCoreConstants.LINE_SEPARATOR );
-
+            
             // export
             int count = 0;
             export( connection, searchParameter, bufferedWriter, count, monitor, exportAttributes,
attributeDelimiter,
-                valueDelimiter, quoteCharacter, lineSeparator, binaryEncoding, exportDn );
+                valueDelimiter, quoteCharacter, lineSeparator, encoding, binaryEncoding,
exportDn );
 
             // close file
             bufferedWriter.close();
@@ -145,7 +147,7 @@
 
     private static void export( IConnection connection, SearchParameter searchParameter,
BufferedWriter bufferedWriter,
         int count, ExtendedProgressMonitor monitor, String[] attributes, String attributeDelimiter,
-        String valueDelimiter, String quoteCharacter, String lineSeparator, int binaryEncoding,
boolean exportDn )
+        String valueDelimiter, String quoteCharacter, String lineSeparator, String encoding,
int binaryEncoding, boolean exportDn )
         throws IOException, ConnectionException
     {
         try
@@ -160,8 +162,8 @@
                 {
 
                     LdifContentRecord record = ( LdifContentRecord ) container;
-                    bufferedWriter.write( recordToCsv( record, attributes, attributeDelimiter,
valueDelimiter,
-                        quoteCharacter, lineSeparator, binaryEncoding, exportDn ) );
+                    bufferedWriter.write( recordToCsv( connection, record, attributes, attributeDelimiter,
valueDelimiter,
+                        quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn
) );
 
                     count++;
                     monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
@@ -198,7 +200,7 @@
                         // export recursive
                         export( referralSearch.getConnection(), referralSearch.getSearchParameter(),
bufferedWriter,
                             count, monitor, attributes, attributeDelimiter, valueDelimiter,
quoteCharacter,
-                            lineSeparator, binaryEncoding, exportDn );
+                            lineSeparator, encoding, binaryEncoding, exportDn );
                     }
                 }
             }
@@ -211,12 +213,12 @@
     }
 
 
-    private static String recordToCsv( LdifContentRecord record, String[] attributes, String
attributeDelimiter,
-        String valueDelimiter, String quoteCharacter, String lineSeparator, int binaryEncoding,
boolean exportDn )
+    private static String recordToCsv( IConnection connection, LdifContentRecord record,
String[] attributes, String attributeDelimiter,
+        String valueDelimiter, String quoteCharacter, String lineSeparator, String encoding,
int binaryEncoding, boolean exportDn )
     {
 
         // group multi-valued attributes
-        Map attributeMap = getAttributeMap( record, valueDelimiter, binaryEncoding );
+        Map attributeMap = getAttributeMap( connection, record, valueDelimiter, encoding,
binaryEncoding );
 
         // print attributes
         StringBuffer sb = new StringBuffer();
@@ -233,9 +235,11 @@
         {
 
             String attributeName = attributes[i];
-            if ( attributeMap.containsKey( attributeName ) )
+            AttributeDescription ad = new AttributeDescription( attributeName );
+            String oidString = ad.toOidString( connection.getSchema() );
+            if ( attributeMap.containsKey( oidString ) )
             {
-                String value = ( String ) attributeMap.get( attributeName );
+                String value = ( String ) attributeMap.get( oidString );
 
                 // escape
                 value = value.replaceAll( quoteCharacter, quoteCharacter + quoteCharacter
);
@@ -259,18 +263,22 @@
     }
 
 
-    static Map getAttributeMap( LdifContentRecord record, String valueDelimiter, int binaryEncoding
)
+    static Map getAttributeMap( IConnection connection, LdifContentRecord record, String
valueDelimiter, String encoding, int binaryEncoding )
     {
         Map attributeMap = new HashMap();
         LdifAttrValLine[] lines = record.getAttrVals();
         for ( int i = 0; i < lines.length; i++ )
         {
             String attributeName = lines[i].getUnfoldedAttributeDescription();
-
-            if ( LdifUtils.mustEncode( lines[i].getValueAsBinary() ) )
+            if ( connection != null )
+            {
+                // convert attributeName to oid
+                AttributeDescription ad = new AttributeDescription( attributeName );
+                attributeName = ad.toOidString( connection.getSchema() );
+            }
+            String value = lines[i].getValueAsString();
+            if ( ! Charset.forName( encoding ).newEncoder().canEncode( value ) )
             {
-
-                String value = BrowserCoreConstants.BINARY;
                 if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_BASE64 )
                 {
                     value = LdifUtils.base64encode( lines[i].getValueAsBinary() );
@@ -279,6 +287,10 @@
                 {
                     value = LdifUtils.hexEncode( lines[i].getValueAsBinary() );
                 }
+                else
+                {
+                    value = BrowserCoreConstants.BINARY;
+                }
 
                 if ( attributeMap.containsKey( attributeName ) )
                 {
@@ -292,7 +304,6 @@
             }
             else
             {
-                String value = lines[i].getValueAsString();
                 if ( attributeMap.containsKey( attributeName ) )
                 {
                     String oldValue = ( String ) attributeMap.get( attributeName );

Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java?view=diff&rev=531264&r1=531263&r2=531264
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/jobs/ExportXlsJob.java
Sun Apr 22 13:17:54 2007
@@ -33,6 +33,7 @@
 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.AttributeDescription;
 import org.apache.directory.ldapstudio.browser.core.internal.model.ConnectionException;
 import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralException;
 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
@@ -189,7 +190,7 @@
                 if ( container instanceof LdifContentRecord )
                 {
                     LdifContentRecord record = ( LdifContentRecord ) container;
-                    recordToHSSFRow( record, sheet, headerRow, attributeNameMap, valueDelimiter,
binaryEncoding,
+                    recordToHSSFRow( connection, record, sheet, headerRow, attributeNameMap,
valueDelimiter, binaryEncoding,
                         exportDn );
 
                     count++;
@@ -240,12 +241,12 @@
     }
 
 
-    private static void recordToHSSFRow( LdifContentRecord record, HSSFSheet sheet, HSSFRow
headerRow,
+    private static void recordToHSSFRow( IConnection connection, LdifContentRecord record,
HSSFSheet sheet, HSSFRow headerRow,
         Map headerRowAttributeNameMap, String valueDelimiter, int binaryEncoding, boolean
exportDn )
     {
 
         // group multi-valued attributes
-        Map attributeMap = ExportCsvJob.getAttributeMap( record, valueDelimiter, binaryEncoding
);
+        Map attributeMap = ExportCsvJob.getAttributeMap( null, record, valueDelimiter, "UTF-16",
binaryEncoding );
 
         // output attributes
         HSSFRow row = sheet.createRow( sheet.getLastRowNum() + 1 );

Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java?view=diff&rev=531264&r1=531263&r2=531264
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java
Sun Apr 22 13:17:54 2007
@@ -171,42 +171,6 @@
 
 
     /**
-     * Checks if the given byte array must be encoded to be
-     * used in an LDIF.
-     *
-     * @param b the b the byte array to check
-     *
-     * @return true, if must encode
-     */
-    public static boolean mustEncode( byte[] b )
-    {
-        if ( b == null || b.length < 1 )
-        {
-            return false;
-        }
-
-        if ( b[0] == ' ' || b[0] == ':' || b[0] == '<' )
-        {
-            return true;
-        }
-        if ( b[b.length - 1] == ' ' )
-        {
-            return true;
-        }
-
-        for ( int i = 0; i < b.length; i++ )
-        {
-            if ( b[i] == '\n' || b[i] == '\r' || b[i] == '\u0000' || ( ( b[i] & 0x7F
) != 0x7F ) )
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-
-    /**
      * Checks if the given string must be encoded to be
      * used in an LDIF.
      *
@@ -255,10 +219,10 @@
      */
     public static String getStringValue( IValue value, int binaryEncoding )
     {
-        String s;
-        byte[] binary = value.getBinaryValue();
-        if ( value.isBinary() && LdifUtils.mustEncode( binary ) )
+        String s = value.getStringValue();
+        if ( value.isBinary() && LdifUtils.mustEncode( s ) )
         {
+            byte[] binary = value.getBinaryValue();
             if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_BASE64 )
             {
                 s = LdifUtils.base64encode( binary );
@@ -271,11 +235,6 @@
             {
                 s = BrowserCoreConstants.BINARY;
             }
-        }
-        else
-        {
-            s = value.getStringValue();
-
         }
         return s;
     }



Mime
View raw message