001: /**
002: * Redistribution and use of this software and associated documentation
003: * ("Software"), with or without modification, are permitted provided
004: * that the following conditions are met:
005: *
006: * 1. Redistributions of source code must retain copyright
007: * statements and notices. Redistributions must also contain a
008: * copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the
011: * above copyright notice, this list of conditions and the
012: * following disclaimer in the documentation and/or other
013: * materials provided with the distribution.
014: *
015: * 3. The name "Exolab" must not be used to endorse or promote
016: * products derived from this Software without prior written
017: * permission of Intalio, Inc. For written permission,
018: * please contact info@exolab.org.
019: *
020: * 4. Products derived from this Software may not be called "Exolab"
021: * nor may "Exolab" appear in their names without prior written
022: * permission of Intalio, Inc. Exolab is a registered
023: * trademark of Intalio, Inc.
024: *
025: * 5. Due credit should be given to the Exolab Project
026: * (http://www.exolab.org/).
027: *
028: * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
032: * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039: * OF THE POSSIBILITY OF SUCH DAMAGE.
040: *
041: * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
042: *
043: * $Id: Test.java 6963 2007-04-23 22:08:53Z rjoachim $
044: */package dsml;
045:
046: import java.io.PrintWriter;
047: import java.util.Hashtable;
048: import netscape.ldap.LDAPConnection;
049: import netscape.ldap.LDAPv2;
050: import javax.naming.Context;
051: import javax.naming.directory.InitialDirContext;
052: import org.exolab.castor.dsml.Importer;
053: import org.exolab.castor.dsml.Exporter;
054: import org.exolab.castor.dsml.ImportExportException;
055: import org.exolab.castor.dsml.mozilla.MozillaImporter;
056: import org.exolab.castor.dsml.mozilla.MozillaExporter;
057: import org.exolab.castor.dsml.jndi.JNDIImporter;
058: import org.exolab.castor.dsml.jndi.JNDIExporter;
059: import org.exolab.castor.dsml.tools.PrintImportListener;
060:
061: /**
062: *
063: *
064: * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
065: * @version $Revision: 6963 $ $Date: 2004-10-25 14:32:31 -0600 (Mon, 25 Oct 2004) $
066: */
067:
068: public class Test {
069:
070: public static final String usage = "Usage: test.sh dsml [jndi|mozilla] <host> <root-dn> <rood-pwd>";
071:
072: public static void main(String args[]) {
073: boolean jndi = false;
074:
075: if (args.length < 4) {
076: System.out.println(usage);
077: System.exit(1);
078: }
079: if (args[0].equalsIgnoreCase("jndi"))
080: jndi = true;
081: else if (args[0].equalsIgnoreCase("mozilla"))
082: jndi = false;
083: else {
084: System.out.println(usage);
085: System.exit(1);
086: }
087:
088: try {
089:
090: LDAPConnection conn = null;
091: Hashtable env;
092: InitialDirContext ctx = null;
093: Importer importer;
094: Exporter exporter;
095: PrintImportListener printer;
096:
097: if (jndi) {
098: env = new Hashtable();
099: env.put(Context.INITIAL_CONTEXT_FACTORY,
100: "com.netscape.jndi.ldap.LdapContextFactory");
101: env.put(Context.PROVIDER_URL, "ldap://" + args[1]);
102: env.put(Context.SECURITY_PRINCIPAL, args[2]);
103: env.put(Context.SECURITY_CREDENTIALS, args[3]);
104: ctx = new InitialDirContext(env);
105: } else {
106: conn = new LDAPConnection();
107: conn.connect(args[1], LDAPv2.DEFAULT_PORT);
108: conn.authenticate(args[2], args[3]);
109: }
110:
111: if (jndi) {
112: importer = new JNDIImporter(ctx);
113: } else {
114: importer = new MozillaImporter(conn);
115: }
116: printer = new PrintImportListener(new PrintWriter(
117: System.out, true));
118: importer.setImportEventListener(printer);
119: importer.readImportDescriptor(Test.class
120: .getResourceAsStream("import.xml"));
121: importer.importDocument(Test.class
122: .getResourceAsStream("test.xml"));
123:
124: if (jndi) {
125: exporter = new JNDIExporter(ctx);
126: } else {
127: exporter = new MozillaExporter(conn);
128: }
129: exporter.readSearchDescriptor(Test.class
130: .getResourceAsStream("search.xml"));
131: exporter
132: .setImportDescriptor(importer.getImportDescriptor());
133: exporter.export(System.out, false, true);
134:
135: if (jndi) {
136: ctx.close();
137: } else {
138: conn.disconnect();
139: }
140:
141: } catch (Exception except) {
142: if (except instanceof ImportExportException) {
143: except = ((ImportExportException) except)
144: .getException();
145: }
146: System.out.println(except);
147: except.printStackTrace();
148: }
149: }
150:
151: }
|