[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/history/

damencho at dev.java.net damencho at dev.java.net
Thu May 31 17:43:42 CEST 2007


User: damencho
Date: 2007-05-31 15:43:42+0000
Modified:
   sip-communicator/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/history/HistoryImpl.java

Log:
 Fix for illegal characters in folder names on Windows OS.

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/history/
========================================================================

File [changed]: HistoryServiceImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java?r1=1.11&r2=1.12
Delta lines:  +43 -0
--------------------
--- HistoryServiceImpl.java	2007-01-04 10:00:43+0000	1.11
+++ HistoryServiceImpl.java	2007-05-31 15:43:40+0000	1.12
@@ -51,6 +51,23 @@
 
     private boolean cacheEnabled = false;
 
+    /**
+     *  Characters and their replacement in created folder names
+     */
+    private final static String[][] ESCAPE_SEQUENCES = new String[][]
+    {
+        {"&", "&_amp"},
+        {"/", "&_sl"},
+        {"\\\\", "&_bs"},   // the char \
+        {":", "&_co"},
+        {"\\*", "&_as"},    // the char *
+        {"\\?", "&_qm"},    // the char ?
+        {"\"", "&_pa"},     // the char "
+        {"<", "&_lt"},
+        {">", "&_gt"},
+        {"\\|", "&_pp"}     // the char |
+    };
+
     public HistoryServiceImpl()
         throws Exception
     {
@@ -227,6 +244,10 @@
             dirs[0] = userSetDataDirectory;
         else
             dirs[0] = DATA_DIRECTORY;
+        
+        // escape chars in direcotory names
+        escapeCharacters(idComponents);
+        
         System.arraycopy(idComponents, 0, dirs, 1, dirs.length - 1);
 
         File directory = null;
@@ -371,4 +392,26 @@
         }
         dir.delete();
     }
+    
+    /**
+     * Replacing the characters that we must escape
+     * used for the created filename.
+     * 
+     * @param ids Ids - folder names as we are using 
+     *          FileSystem for storing files.
+     */
+    private void escapeCharacters(String[] ids)
+    {
+        for (int i = 0; i < ids.length; i++)
+        {
+            String currId = ids[i];
+            
+            for (int j = 0; j < ESCAPE_SEQUENCES.length; j++)
+            {
+                currId = currId.
+                    replaceAll(ESCAPE_SEQUENCES[j][0], ESCAPE_SEQUENCES[j][1]);
+            }
+            ids[i] = currId;
+        }
+    }
 }

File [changed]: HistoryImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/history/HistoryImpl.java?r1=1.11&r2=1.12
Delta lines:  +0 -1
-------------------
--- HistoryImpl.java	2007-01-04 10:00:43+0000	1.11
+++ HistoryImpl.java	2007-05-31 15:43:40+0000	1.12
@@ -258,7 +258,6 @@
      *
      * @param file File the file trying to fix
      * @return Document the fixed doc
-     * @throws Exception
      */
     public Document getFixedDocument(File file)
     {




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: cvs-help at sip-communicator.dev.java.net





More information about the commits mailing list