Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 72646 invoked from network); 14 Jan 2010 15:44:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jan 2010 15:44:56 -0000 Received: (qmail 59069 invoked by uid 500); 14 Jan 2010 15:44:56 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 59005 invoked by uid 500); 14 Jan 2010 15:44:56 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 58996 invoked by uid 99); 14 Jan 2010 15:44:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 15:44:56 +0000 X-ASF-Spam-Status: No, hits=-1999.6 required=10.0 tests=ALL_TRUSTED,SUBJECT_FUZZY_TION X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 15:44:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0AE6B23889CB; Thu, 14 Jan 2010 15:44:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100114154428.0AE6B23889CB@eris.apache.org> 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 getTestEntries( String entryFilePath ) throws Exception + { + List entries = new ArrayList(); + + 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 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