directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r899248 - /directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
Date Thu, 14 Jan 2010 15:44:27 GMT
Author: kayyagari
Date: Thu Jan 14 15:44:27 2010
New Revision: 899248

URL: http://svn.apache.org/viewvc?rev=899248&view=rev
Log:
added support for loading the test LDIF entries from the configured file system location

Modified:
    directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java

Modified: directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java?rev=899248&r1=899247&r2=899248&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
(original)
+++ directory/apacheds/branches/apacheds-cidit/default-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
Thu Jan 14 15:44:27 2010
@@ -22,6 +22,7 @@
 
 
 import java.io.File;
+import java.io.FilenameFilter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -61,6 +62,8 @@
 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.filter.EqualityNode;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
@@ -89,7 +92,21 @@
     
     /** the parent directory of the config partition's working directory */
     private File workDir;
-    
+
+    /** LDIF file filter */
+    private FilenameFilter ldifFilter = new FilenameFilter()
+    {
+        public boolean accept( File file, String name )
+        {
+            if( file.isDirectory() )
+            {
+                return true;
+            }
+            
+            return file.getName().toLowerCase().endsWith( ".ldif" );
+        }
+    };
+
     private static final Logger LOG = LoggerFactory.getLogger( ConfigPartitionReader.class
);
 
 
@@ -277,8 +294,8 @@
         EntryAttribute testEntryAttr = dsEntry.get( "ads-dsTestEntries" );
         if ( testEntryAttr != null )
         {
-            //process the test entries, should this be a FS location?
-            //dirService.setTestEntries( testEntries );
+            String entryFilePath = testEntryAttr.getString();
+            dirService.setTestEntries( getTestEntries( entryFilePath ) );
         }
 
         if ( !isEnabled( dsEntry ) )
@@ -590,6 +607,44 @@
         return journal;
     }
     
+
+    private List<LdifEntry> getTestEntries( String entryFilePath ) throws Exception
+    {
+        List<LdifEntry> entries = new ArrayList<LdifEntry>();
+        
+        File file = new File( entryFilePath );
+        if( !file.exists() )
+        {
+            LOG.warn( "LDIF test entry file path doesn't exist {}", entryFilePath );
+        }
+        else
+        {
+            LOG.info( "parsing the LDIF file(s) present at the path {}", entryFilePath );
+            loadEntries( file, entries );
+        }
+        
+        return entries;
+    }
+    
+    
+    private void loadEntries( File ldifFile, List<LdifEntry> entries ) throws Exception
+    {
+        if( ldifFile.isDirectory() )
+        {
+            File[] files = ldifFile.listFiles( ldifFilter );
+            for( File f : files )
+            {
+                loadEntries( f, entries );
+            }
+        }
+        else
+        {
+            LdifReader reader = new LdifReader();
+            entries.addAll( reader.parseLdifFile( ldifFile.getAbsolutePath() ) );
+            reader.close();
+        }
+    }
+    
     
     /**
      * internal class used for holding the Interceptor classname and order configuration



Mime
View raw message