001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.adapter.ls.exec.ui;
034:
035: import org.libresource.so6.adapter.ls.tools.IndeterminateProgressView;
036: import org.libresource.so6.adapter.ls.tools.LsClassicPropertiesEditor;
037: import org.libresource.so6.core.Workspace;
038: import org.libresource.so6.core.WsConnection;
039: import org.libresource.so6.core.client.ClientI;
040: import org.libresource.so6.core.client.ClientIServletImpl;
041: import org.libresource.so6.core.engine.util.CryptUtil;
042: import org.libresource.so6.core.exec.AnonymousAccess;
043:
044: import java.io.File;
045: import java.io.FileOutputStream;
046:
047: import java.util.Hashtable;
048: import java.util.Properties;
049:
050: import javax.swing.JOptionPane;
051:
052: /**
053: * @author smack
054: */
055: public class ImportConnection extends LsClassicPropertiesEditor {
056: //private final static String CLIENT_CLASS_NAME = "org.libresource.so6.client.soap.ClientISoapImpl";
057: //private static final String CLIENT_CLASS_NAME = "org.libresource.so6.client.ClientIServletImpl";
058: private static final String CLIENT_CLASS_NAME = "com.artenum.so6.dataflow.ClientIHttpClient";
059:
060: /**
061: * @param name
062: */
063: public ImportConnection(String wscPath, String serverUrl,
064: String synchronizerUri, String login, String password) {
065: super ("Import existing connection");
066:
067: //
068: addPathPropertie("wsc.path", "Connection file :", wscPath);
069: addTextPropertie(ClientI.SO6_QUEUE_ID, "Synchronizer URI :",
070: synchronizerUri);
071: addTextPropertie(ClientI.SO6_LOGIN, "Login :", login);
072: addPasswordPropertie(ClientI.SO6_PASSWORD, "Password :",
073: password);
074:
075: Hashtable props = editProperties();
076:
077: if (props != null) {
078: new IndeterminateProgressView("Updating local data",
079: "Please wait during the import operation...");
080: props.put(ClientIServletImpl.SO6_SERVICE_URL, serverUrl);
081:
082: try {
083: File baseDir = new File((String) props
084: .get(WsConnection.PATH), Workspace.SO6PREFIX);
085: baseDir.mkdirs();
086:
087: File propsFile = new File(baseDir,
088: "download.properties");
089:
090: if (!propsFile.exists()) {
091: FileOutputStream fos = new FileOutputStream(
092: propsFile);
093: Properties p = new Properties();
094: p.putAll(props);
095:
096: if (p.getProperty(ClientIServletImpl.SO6_LOGIN)
097: .equals("guest")
098: || (p.getProperty(
099: ClientIServletImpl.SO6_LOGIN)
100: .trim().length() == 0)) {
101: p.remove(ClientIServletImpl.SO6_LOGIN);
102: p.remove(ClientIServletImpl.SO6_PASSWORD);
103: } else {
104: p
105: .setProperty(
106: ClientIServletImpl.SO6_PASSWORD,
107: CryptUtil
108: .encode(p
109: .getProperty(ClientIServletImpl.SO6_PASSWORD)));
110: }
111:
112: p.setProperty(WsConnection.SYNC_CLIENT_NAME,
113: CLIENT_CLASS_NAME);
114: p.store(fos, "Do not edit");
115: fos.close();
116: }
117:
118: // Checkout now !!
119: AnonymousAccess aa = new AnonymousAccess(propsFile
120: .getPath());
121: aa.execute();
122: } catch (Exception e) {
123: e.printStackTrace();
124: JOptionPane.showMessageDialog(null,
125: "<html><b>Error while trying to import the existing connection</b><br>"
126: + e.getMessage() + "</html>");
127: System.exit(0);
128: }
129: } else {
130: System.exit(0);
131: }
132: }
133:
134: public static void main(String[] args) {
135: if (args.length == 3) {
136: new ImportConnection("", args[0], args[1], args[2], "");
137: } else {
138: System.err.println("Usage: downloadPropertyFilePath");
139: System.err
140: .println(" (1) downloadPropertyFilePath: path of the download property file \nor\n");
141: System.err
142: .println("Usage: serverUrl synchronizerUri userLogin");
143: System.err.println(" (1) serverUrl");
144: System.err.println(" (2) synchronizerUri");
145: System.err.println(" (3) userLogin");
146: }
147:
148: System.exit(0);
149: }
150: }
|