Awesome, thank you, Gokturk, I will try that! Marina
________________________________ From: Göktürk Gezer <[email protected]> To: [email protected] Sent: Wednesday, May 9, 2012 4:23 PM Subject: Re: How to import LDIF file programmatically You can use below code as your base. You might wanna slightly change it based on which version of ApacheDS you're using. And make sure your ldif file is constructed in correct order from the top to the bottom. I'd preffer to use CoreSession to issue operations to make sure they're checked, but you can issue operations on the Jdbm partition reference you've created as well.. LdifReader ldifReader = new LdifReader(new FileInputStream("yourfile.ldif")); CoreSession conn; // Obtain it from embedded DirectoryService reference. for ( LdifEntry entry : ldifReader ) { if ( entry.isLdifContent() ) { conn.add( entry.getEntry() ); continue; } switch ( entry.getChangeType() ) { case ModRdn: case ModDn: ModifyDnRequest modDnRequest = new ModifyDnRequestImpl(); modDnRequest.setName( entry.getDn() ); modDnRequest.setDeleteOldRdn( entry.isDeleteOldRdn() ); if ( entry.getNewSuperior() != null ) { modDnRequest.setNewSuperior( new Dn( entry.getNewSuperior() ) ); } if ( entry.getNewRdn() != null ) { modDnRequest.setNewRdn( new Rdn( entry.getNewRdn() ) ); } conn.modifyDn( modDnRequest ); break; case Delete: conn.delete( entry.getDn() ); break; case Modify: conn.modify( entry.getDn(), entry.getModificationArray() ); break; default: throw new IllegalArgumentException( "Unknown change type in LdifEntry: " + entry.getChangeType().toString() ); } }
