← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 697: Implemented method buildDirectory in LocationManager.

 

------------------------------------------------------------
revno: 697
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-09-14 15:35:01 +0200
message:
  Implemented method buildDirectory in LocationManager.
modified:
  dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java
  dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java	2009-08-18 13:55:55 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java	2009-09-14 13:35:01 +0000
@@ -154,21 +154,9 @@
     public File getFileForReading( String fileName, String... directories )
         throws LocationManagerException
     {
-        if ( externalDir == null )
-        {
-            throw new LocationManagerException( "External directory not set" );
-        }
-        
-        StringBuffer directory = new StringBuffer();
-        
-        directory.append( externalDir + separator );
-        
-        for ( String dir : directories )
-        {
-            directory.append( dir + separator );
-        }
-        
-        File file = new File( directory.toString(), fileName );
+        File directory = buildDirectory( directories );
+        
+        File file = new File( directory, fileName );
         
         if ( !canReadFile( file ) )
         {
@@ -218,21 +206,7 @@
     public File getFileForWriting( String fileName, String... directories )
         throws LocationManagerException
     {
-        if ( externalDir == null )
-        {
-            throw new LocationManagerException( "External directory not set" );
-        }
-        
-        StringBuffer directoryPath = new StringBuffer();
-        
-        directoryPath.append( externalDir + separator );
-        
-        for ( String dir : directories )
-        {
-            directoryPath.append( dir + separator );
-        }
-        
-        File directory = new File( directoryPath.toString() );
+        File directory = buildDirectory( directories );
         
         if ( !directoryIsValid( directory ) )
         {
@@ -243,6 +217,24 @@
         
         return file;
     }
+    
+    public File buildDirectory( String... directories )
+        throws LocationManagerException
+    {
+        if ( externalDir == null )
+        {
+            throw new LocationManagerException( "External directory not set" );
+        }
+        
+        StringBuffer directoryPath = new StringBuffer( externalDir + separator );
+                
+        for ( String dir : directories )
+        {
+            directoryPath.append( dir + separator );
+        }
+        
+        return new File( directoryPath.toString() );
+    }
 
     // -------------------------------------------------------------------------
     // External directory and environment variable

=== modified file 'dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java'
--- dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java	2009-08-18 13:55:55 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java	2009-09-14 13:35:01 +0000
@@ -186,6 +186,20 @@
             assertEquals( LocationManagerException.class, ex.getClass() );
         }
     }
+    
+    public void testBuildDirectory()
+    {
+        try
+        {
+            File dir = locationManager.buildDirectory( "test", "dir" );
+            
+            System.out.println( "Built directory: " + dir.getAbsolutePath() );
+        }
+        catch ( LocationManagerException ex )
+        {
+            System.out.println( "External directory not set" );
+        }
+    }
 
     // -------------------------------------------------------------------------
     // OutputStream