LDAPConnection conn = null;
Hashtable env;
InitialDirContext ctx = null;
Importer importer;
Exporter exporter;
PrintImportListener printer;
if ( jndi ) {
env = new Hashtable();
env.put( Context.INITIAL_CONTEXT_FACTORY, "com.netscape.jndi.ldap.LdapContextFactory" );
env.put( Context.PROVIDER_URL, "ldap://" + args[ 1 ] );
env.put( Context.SECURITY_PRINCIPAL, args[ 2 ] );
env.put( Context.SECURITY_CREDENTIALS, args[ 3 ] );
ctx = new InitialDirContext( env );
} else {
conn = new LDAPConnection();
conn.connect( args[ 1 ], LDAPv2.DEFAULT_PORT );
conn.authenticate( args[ 2 ], args[ 3 ] );
}
if ( jndi ) {
importer = new JNDIImporter( ctx );
} else {
importer = new MozillaImporter( conn );
}
printer = new PrintImportListener( new PrintWriter( System.out, true ) );
importer.setImportEventListener( printer );
importer.readImportDescriptor( Test.class.getResourceAsStream( "import.xml" ) );
importer.importDocument( Test.class.getResourceAsStream( "test.xml" ) );
if ( jndi ) {
exporter = new JNDIExporter( ctx );
} else {
exporter = new MozillaExporter( conn );
}
exporter.readSearchDescriptor( Test.class.getResourceAsStream( "search.xml" ) );
exporter.setImportDescriptor( importer.getImportDescriptor() );
exporter.export( System.out, false, true );
if ( jndi ) {
ctx.close();
} else {
conn.disconnect();