Author: norman
Date: Mon Apr 26 19:46:23 2010
New Revision: 938208

URL: http://svn.apache.org/viewvc?rev=938208&view=rev
Log:
Make sure we use the FileSystem service for all FileRepository actions

Modified:
    
james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
    
james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/MockFileSystem.java
    
james/server/trunk/user-function/src/test/java/org/apache/james/userrepository/UsersFileRepositoryTest.java

Modified: 
james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java?rev=938208&r1=938207&r2=938208&view=diff
==============================================================================
--- 
james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
 (original)
+++ 
james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
 Mon Apr 26 19:46:23 2010
@@ -53,15 +53,13 @@ public abstract class AbstractFileReposi
     implements Repository, Configurable, LogEnabled {
     protected static final boolean DEBUG = false;
 
-    protected static final String HANDLED_URL = "file://";
     protected static final int BYTE_MASK = 0x0f;
     protected static final char[] HEX_DIGITS = new char[]
     {
         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 
'E', 'F'
     };
 
-    protected String m_path;
-    protected String m_destination;
+    protected File m_destination;
     protected String m_extension;
     protected String m_name;
     protected FilenameFilter m_filter;
@@ -72,11 +70,9 @@ public abstract class AbstractFileReposi
     private Log logger;
     
     public void configure(HierarchicalConfiguration configuration) throws 
ConfigurationException{        
-        if( null == m_destination )
-        {
-            final String destination = configuration.getString( 
"[...@destinationurl]" );
-            setDestination( destination );
-        }
+        final String destination = configuration.getString( 
"[...@destinationurl]" );
+        setDestination( destination );
+        
     }
     
     
@@ -113,28 +109,15 @@ public abstract class AbstractFileReposi
         
         File directory;
 
-        // Check for absolute path
-        if( m_path.startsWith( "/" ) )
-        {
-            directory = new File( m_path );
-        }
-        else
-        {
-            directory = new File( m_baseDirectory, m_path );
-        }
-
         try
         {
-            directory = directory.getCanonicalFile();
+            directory = m_baseDirectory.getCanonicalFile();
         }
         catch( final IOException ioe )
         {
             throw new ConfigurationException( "Unable to form canonical 
representation of " +
-                                              directory );
+                    m_baseDirectory );
         }
-
-        m_path = directory.toString();
-
         
        
         m_name = "Repository";
@@ -145,7 +128,7 @@ public abstract class AbstractFileReposi
 
         directory.mkdirs();
 
-        getLogger().info( getClass().getName() + " opened in " + m_path );
+        getLogger().info( getClass().getName() + " opened in " + m_destination 
);
 
         //We will look for all numbered repository files in this
         //  directory and rename them to non-numbered repositories,
@@ -186,19 +169,23 @@ public abstract class AbstractFileReposi
      * Set the destination for the repository
      * 
      * @param destination the destination under which the repository get stored
+     * @throws ConfigurationException 
      * @throws ConfigurationException get thrown on invalid destintion syntax
      */
     protected void setDestination( final String destination )
         throws ConfigurationException
     {
-        if( !destination.startsWith( HANDLED_URL ) )
+        if( !destination.startsWith( FileSystem.FILE_PROTOCOL ) )
         {
-            throw new ConfigurationException( "cannot handle destination " + 
destination );
+            throw new ConfigurationException( "cannot handle destination " + 
destination);
         }
 
         
-        m_path = destination.substring( HANDLED_URL.length() );
-        m_destination = destination;
+        try {
+            m_destination = fileSystem.getFile(destination);
+        } catch (FileNotFoundException e) {
+            throw new ConfigurationException("Unable to acces destination " + 
destination, e);
+        }
 
     }
 
@@ -237,7 +224,7 @@ public abstract class AbstractFileReposi
 
         try
         {
-            child.setDestination( m_destination + File.pathSeparatorChar +
+            child.setDestination( m_destination.getAbsolutePath() + 
File.pathSeparatorChar +
                                   childName + File.pathSeparator );
         }
         catch( final ConfigurationException ce )
@@ -359,7 +346,7 @@ public abstract class AbstractFileReposi
      */
     public Iterator<String> list()
     {
-        final File storeDir = new File( m_path );
+        final File storeDir = new File( m_baseDirectory.getAbsolutePath() );
         final String[] names = storeDir.list( m_filter );
         final List<String> list = new ArrayList<String>();
 
@@ -397,7 +384,7 @@ public abstract class AbstractFileReposi
         }
 
         StringBuffer result = new StringBuffer();
-        result.append( m_path );
+        result.append( m_baseDirectory.getAbsolutePath() );
         result.append( File.separator );
         result.append( buffer );
         result.append( m_extension );

Modified: 
james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/MockFileSystem.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/MockFileSystem.java?rev=938208&r1=938207&r2=938208&view=diff
==============================================================================
--- 
james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/MockFileSystem.java
 (original)
+++ 
james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/MockFileSystem.java
 Mon Apr 26 19:46:23 2010
@@ -51,7 +51,7 @@ public class MockFileSystem implements F
                                        }
                     // return new File("./src"+fileURL.substring(6));
                 } else {
-                    throw new UnsupportedOperationException("getFile: 
"+fileURL);
+                    return new 
File(fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
                 }
             } else {
                 throw new UnsupportedOperationException("getFile: "+fileURL);

Modified: 
james/server/trunk/user-function/src/test/java/org/apache/james/userrepository/UsersFileRepositoryTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/user-function/src/test/java/org/apache/james/userrepository/UsersFileRepositoryTest.java?rev=938208&r1=938207&r2=938208&view=diff
==============================================================================
--- 
james/server/trunk/user-function/src/test/java/org/apache/james/userrepository/UsersFileRepositoryTest.java
 (original)
+++ 
james/server/trunk/user-function/src/test/java/org/apache/james/userrepository/UsersFileRepositoryTest.java
 Mon Apr 26 19:46:23 2010
@@ -64,7 +64,7 @@ public class UsersFileRepositoryTest ext
             }
 
             public File getFile(String fileURL) throws FileNotFoundException {
-                throw new UnsupportedOperationException();
+                return new 
File(fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
             }
             
         };



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to