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: *
054: DOCUMENT ME!
055: *
056: * @author smack
057: */
058: public class AnonymousDownload extends LsClassicPropertiesEditor {
059: //private final static String CLIENT_CLASS_NAME = "org.libresource.so6.client.soap.ClientISoapImpl";
060: //private final static String CLIENT_CLASS_NAME = "org.libresource.so6.core.client.ClientIServletImpl";
061: private static final String CLIENT_CLASS_NAME = "com.artenum.so6.dataflow.ClientIHttpClient";
062:
063: /**
064: * @param name
065: */
066: public AnonymousDownload(String basePath, String serverUrl,
067: String synchronizerUri, String login, String password,
068: long lastTicket) {
069: super ("Anonymous Download");
070:
071: //
072: addPathPropertie(WsConnection.PATH, "Base Path :", basePath);
073: addTextPropertie(ClientI.SO6_QUEUE_ID, "Synchronizer URI :",
074: synchronizerUri);
075: addTextPropertie(ClientI.SO6_LOGIN, "Login :", login);
076: addPasswordPropertie(ClientI.SO6_PASSWORD, "Password :",
077: password);
078:
079: Hashtable props = editProperties();
080:
081: if (props != null) {
082: new IndeterminateProgressView("Anonymous so6 access",
083: "Please wait during the download and the patch application...");
084: props.put(ClientIServletImpl.SO6_SERVICE_URL, serverUrl);
085:
086: try {
087: File baseDir = new File((String) props
088: .get(WsConnection.PATH), Workspace.SO6PREFIX);
089: baseDir.mkdirs();
090:
091: File propsFile = new File(baseDir,
092: "download.properties");
093:
094: if (!propsFile.exists()) {
095: FileOutputStream fos = new FileOutputStream(
096: propsFile);
097: Properties p = new Properties();
098: p.putAll(props);
099:
100: if (p.getProperty(ClientI.SO6_LOGIN)
101: .equals("guest")
102: || (p.getProperty(ClientI.SO6_LOGIN).trim()
103: .length() == 0)) {
104: p.remove(ClientI.SO6_LOGIN);
105: p.remove(ClientI.SO6_PASSWORD);
106: } else {
107: p
108: .setProperty(
109: ClientI.SO6_PASSWORD,
110: CryptUtil
111: .encode(p
112: .getProperty(ClientI.SO6_PASSWORD)));
113: }
114:
115: p.setProperty(WsConnection.SYNC_CLIENT_NAME,
116: CLIENT_CLASS_NAME);
117: p.store(fos, "Do not edit");
118: fos.close();
119: }
120:
121: // Checkout now !!
122: AnonymousAccess aa;
123:
124: //
125: String limit = "Limit download to " + lastTicket;
126:
127: if (lastTicket != -1) {
128: aa = new AnonymousAccess(propsFile.getPath(),
129: lastTicket);
130: } else {
131: aa = new AnonymousAccess(propsFile.getPath());
132: }
133:
134: //System.out.println(limit);
135: aa.execute();
136: } catch (Exception e) {
137: e.printStackTrace();
138: JOptionPane.showMessageDialog(null,
139: "<html><b>Error while trying to download the content of the queue</b><br>"
140: + e.getMessage() + "</html>");
141: System.exit(0);
142: }
143: } else {
144: System.exit(0);
145: }
146: }
147:
148: /**
149: * Creates a new AnonymousDownload object.
150: *
151: * @param downloadFilePath DOCUMENT ME!
152: */
153: public AnonymousDownload(String downloadFilePath) {
154: super ("Anonymous Download");
155:
156: //
157: addPathPropertie("basePath", "Download file path :",
158: downloadFilePath);
159:
160: Hashtable props = editProperties();
161:
162: if (props != null) {
163: String[] newArgs = new String[1];
164:
165: try {
166: AnonymousAccess aa = new AnonymousAccess((String) props
167: .get("basePath"));
168: aa.execute();
169: } catch (Exception e) {
170: e.printStackTrace();
171: JOptionPane.showMessageDialog(null,
172: "<html><b>Error while trying to download the content of the queue</b><br>"
173: + e.getMessage() + "</html>");
174: System.exit(0);
175: }
176: } else {
177: System.exit(0);
178: }
179: }
180:
181: /**
182: * DOCUMENT ME!
183: *
184: * @param args DOCUMENT ME!
185: */
186: public static void main(String[] args) {
187: if (args.length == 1) {
188: new AnonymousDownload(args[0]);
189: } else if (args.length == 3) {
190: new AnonymousDownload("", args[0], args[1], args[2], "", -1);
191: } else if (args.length == 4) {
192: new AnonymousDownload("", args[0], args[1], args[2], "",
193: Long.parseLong(args[3]));
194: } else {
195: System.err.println("Usage: downloadPropertyFilePath");
196: System.err
197: .println(" (1) downloadPropertyFilePath: path of the download property file \nor\n");
198: System.err
199: .println("Usage: serverUrl synchronizerUri userLogin");
200: System.err.println(" (1) serverUrl");
201: System.err.println(" (2) synchronizerUri");
202: System.err.println(" (3) userLogin");
203: }
204:
205: System.exit(0);
206: }
207: }
|