You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/10/29 03:20:55 UTC
svn commit: r329343 -
/directory/shared/protocol/trunk/common/src/main/java/org/apache/protocol/common/store/LdifFileLoader.java
Author: erodriguez
Date: Fri Oct 28 18:20:51 2005
New Revision: 329343
URL: http://svn.apache.org/viewcvs?rev=329343&view=rev
Log:
Added back constructor used by Load command.
Modified:
directory/shared/protocol/trunk/common/src/main/java/org/apache/protocol/common/store/LdifFileLoader.java
Modified: directory/shared/protocol/trunk/common/src/main/java/org/apache/protocol/common/store/LdifFileLoader.java
URL: http://svn.apache.org/viewcvs/directory/shared/protocol/trunk/common/src/main/java/org/apache/protocol/common/store/LdifFileLoader.java?rev=329343&r1=329342&r2=329343&view=diff
==============================================================================
--- directory/shared/protocol/trunk/common/src/main/java/org/apache/protocol/common/store/LdifFileLoader.java (original)
+++ directory/shared/protocol/trunk/common/src/main/java/org/apache/protocol/common/store/LdifFileLoader.java Fri Oct 28 18:20:51 2005
@@ -16,14 +16,13 @@
*/
package org.apache.protocol.common.store;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
-import java.util.Properties;
-import java.util.List;
import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.Name;
@@ -38,7 +37,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Support for commands to load an LDIF file into a DirContext.
*
@@ -59,13 +57,17 @@
/** the total count of entries loaded */
private int count;
-
/**
* Creates the LDIF file loader command.
*
* @param ctx the context to load the entries into.
* @param ldif the file of LDIF entries to load.
*/
+ public LdifFileLoader( DirContext ctx, String ldif )
+ {
+ this( ctx, new File( ldif ), null );
+ }
+
public LdifFileLoader( DirContext ctx, File ldif, List filters )
{
this.ctx = ctx;
@@ -81,7 +83,6 @@
}
}
-
/**
* Applies filters making sure failures in one filter do not effect another.
*
@@ -89,16 +90,21 @@
* @param entry the attributes of the entry
* @return true if all filters passed the entry, false otherwise
*/
- private boolean applyFilters ( String dn, Attributes entry )
+ private boolean applyFilters( String dn, Attributes entry )
{
boolean accept = true;
final int limit = filters.size();
- if ( limit == 0 ) { return true; } // don't waste time with loop
+
+ if ( limit == 0 )
+ {
+ return true;
+ } // don't waste time with loop
+
for ( int ii = 0; ii < limit; ii++ )
{
try
{
- accept &= ( ( LdifLoadFilter ) filters.get( ii ) ).filter( ldif, dn, entry, ctx );
+ accept &= ( (LdifLoadFilter) filters.get( ii ) ).filter( ldif, dn, entry, ctx );
}
catch ( NamingException e )
{
@@ -106,12 +112,14 @@
}
// early bypass if entry is rejected
- if ( ! accept ) { return false; }
+ if ( !accept )
+ {
+ return false;
+ }
}
return true;
}
-
/**
* Opens the LDIF file and loads the entries into the context.
*/
@@ -128,13 +136,18 @@
while ( iterator.hasNext() )
{
- String ldif = ( String) iterator.next();
+ String ldif = (String) iterator.next();
Attributes attributes = new LockableAttributesImpl();
ldifParser.parse( attributes, ldif );
- String dn = ( String ) attributes.remove( "dn" ).get();
+ String dn = (String) attributes.remove( "dn" ).get();
boolean filterAccepted = applyFilters( dn, attributes );
- if ( ! filterAccepted ) { continue; }
+
+ if ( !filterAccepted )
+ {
+ continue;
+ }
+
rdn = getRelativeName( ctx, dn );
try
@@ -160,13 +173,22 @@
}
finally
{
- if ( in != null ) { try { in.close(); } catch( Exception e ) { log.error( "failed to close stream", e );} }
+ if ( in != null )
+ {
+ try
+ {
+ in.close();
+ }
+ catch ( Exception e )
+ {
+ log.error( "failed to close stream", e );
+ }
+ }
}
return count;
}
-
private Name getRelativeName( DirContext ctx, String baseDn ) throws NamingException
{
Properties props = new Properties();
@@ -200,7 +222,6 @@
return searchBaseDn;
}
-
/**
* Tries to find an LDIF file either on the file system or packaged within a jar.
*
@@ -219,6 +240,7 @@
{
// if file not on system see if something is bundled with the jar ...
in = getClass().getResourceAsStream( ldif.getName() );
+
if ( in == null )
{
throw new FileNotFoundException( "LDIF file does not exist." );