KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > install > ConfigurationPanel


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.install;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import java.io.*;
19 import java.net.*;
20 import java.sql.*;
21 import java.util.*;
22 import java.util.regex.*;
23
24 import org.apache.log4j.LogManager;
25 import org.apache.log4j.Logger;
26 import org.apache.log4j.ConsoleAppender;
27 import org.apache.log4j.Level;
28
29 import javax.mail.*;
30 import javax.mail.internet.*;
31 import javax.swing.*;
32
33 import oracle.jdbc.*;
34 import org.compiere.*;
35 import org.compiere.apps.*;
36 import org.compiere.db.*;
37 import org.compiere.util.*;
38
39
40 /**
41  * Configuration Panel
42  *
43  * @author Jorg Janke
44  * @author Marek Mosiewicz<marek.mosiewicz@jotel.com.pl> support for RMI over HTTP - now reimplemented/removed jj
45  * @version $Id: ConfigurationPanel.java,v 1.8 2003/09/30 14:32:04 jjanke Exp $
46  */

47 public class ConfigurationPanel extends JPanel implements ActionListener
48 {
49     /**
50      * Constructor
51      * @param statusBar for info
52      * @throws Exception
53      */

54     public ConfigurationPanel (JLabel statusBar) throws Exception JavaDoc
55     {
56         LogManager.resetConfiguration();
57         Logger root = Logger.getRootLogger();
58     // root.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
59
root.addAppender(new ConsoleAppender(new LogLayout()));
60         root.setLevel(Level.ALL);
61         Log.setTraceLevel(10);
62
63         m_statusBar = statusBar;
64         jbInit();
65         dynInit();
66     } // ConfigurationPanel
67

68     public static final String JavaDoc COMPIERE_ENV_FILE = "CompiereEnv.properties";
69
70     public static final String JavaDoc COMPIERE_HOME = "COMPIERE_HOME";
71     public static final String JavaDoc JAVA_HOME = "JAVA_HOME";
72     public static final String JavaDoc COMPIERE_JAVA_OPTIONS = "COMPIERE_JAVA_OPTIONS";
73
74     public static final String JavaDoc COMPIERE_APPS_SERVER = "COMPIERE_APPS_SERVER";
75     public static final String JavaDoc COMPIERE_JNP_PORT = "COMPIERE_JNP_PORT";
76     public static final String JavaDoc COMPIERE_WEB_PORT = "COMPIERE_WEB_PORT";
77     public static final String JavaDoc COMPIERE_SSL_PORT = "COMPIERE_SSL_PORT";
78
79     public static final String JavaDoc COMPIERE_DB_SERVER = "COMPIERE_DB_SERVER";
80     public static final String JavaDoc COMPIERE_DB_PORT = "COMPIERE_DB_PORT";
81     public static final String JavaDoc COMPIERE_DB_NAME = "COMPIERE_DB_NAME";
82
83     public static final String JavaDoc COMPIERE_DB_USER = "COMPIERE_DB_USER";
84     public static final String JavaDoc COMPIERE_DB_PASSWORD = "COMPIERE_DB_PASSWORD";
85     public static final String JavaDoc COMPIERE_DB_SYSTEM = "COMPIERE_DB_SYSTEM";
86
87     public static final String JavaDoc COMPIERE_DB_URL = "COMPIERE_DB_URL";
88     public static final String JavaDoc COMPIERE_DB_TNS = "COMPIERE_DB_TNS";
89
90     public static final String JavaDoc COMPIERE_MAIL_SERVER = "COMPIERE_MAIL_SERVER";
91     public static final String JavaDoc COMPIERE_MAIL_USER = "COMPIERE_MAIL_USER";
92     public static final String JavaDoc COMPIERE_MAIL_PASSWORD = "COMPIERE_MAIL_PASSWORD";
93     public static final String JavaDoc COMPIERE_ADMIN_EMAIL = "COMPIERE_ADMIN_EMAIL";
94
95     public static final String JavaDoc COMPIERE_FTP_SERVER = "COMPIERE_FTP_SERVER";
96     public static final String JavaDoc COMPIERE_FTP_USER = "COMPIERE_FTP_USER";
97     public static final String JavaDoc COMPIERE_FTP_PASSWORD = "COMPIERE_FTP_PASSWORD";
98     public static final String JavaDoc COMPIERE_FTP_PREFIX = "COMPIERE_FTP_PREFIX";
99
100     private String JavaDoc m_errorString;
101     private File m_javaHome;
102     private File m_compiereHome;
103     private InetAddress m_appsServer;
104     private int m_WebPort;
105     private int m_JNPPort;
106     private InetAddress m_databaseServer;
107     private int m_databasePort;
108     private String JavaDoc m_databaseName;
109     private String JavaDoc m_connectionString;
110     private String JavaDoc m_systemPassword;
111     private String JavaDoc m_databaseUser;
112     private String JavaDoc m_databasePassword;
113     private String JavaDoc m_TNSName;
114
115     private InetAddress m_mailServer;
116     private InternetAddress m_adminEMail;
117     private String JavaDoc m_mailUser;
118     private String JavaDoc m_mailPassword;
119
120     private volatile boolean m_success = false;
121     private volatile boolean m_testing = false;
122
123     /** Translation */
124     static ResourceBundle res = ResourceBundle.getBundle("org.compiere.install.SetupRes");
125
126     /** Driver */
127     private static Driver s_driver = null;
128     /** Environment Properties */
129     private Properties m_properties = new Properties();
130     /** Status Bar */
131     private JLabel m_statusBar;
132
133     private static ImageIcon iOpen = new ImageIcon(ConfigurationPanel.class.getResource("openFile.gif"));
134     private static ImageIcon iSave = new ImageIcon(Compiere.class.getResource("images/Save16.gif"));
135     private static ImageIcon iHelp = new ImageIcon(Compiere.class.getResource("images/Help16.gif"));
136
137
138     // ------------- Static UI
139
private GridBagLayout gridBagLayout = new GridBagLayout();
140     private JLabel lCompiereHome = new JLabel();
141     private JTextField fCompiereHome = new JTextField();
142     private JLabel lWebPort = new JLabel();
143     private JTextField fWebPort = new JTextField();
144     private JLabel lAppsServer = new JLabel();
145     private JTextField fAppsServer = new JTextField();
146     private JLabel lDatabaseType = new JLabel();
147     private JComboBox fDatabaseType = new JComboBox();
148     private JLabel lDatabaseName = new JLabel();
149     private JLabel lDatabasePort = new JLabel();
150     private JLabel lDatabaseUser = new JLabel();
151     private JLabel lDatabasePassword = new JLabel();
152     private JTextField fDatabaseName = new JTextField();
153     private JTextField fDatabasePort = new JTextField();
154     private JTextField fDatabaseUser = new JTextField();
155     private JPasswordField fDatabasePassword = new JPasswordField();
156     private JLabel lTNSName = new JLabel();
157     private JComboBox fTNSName = new JComboBox();
158     private JLabel lSystemPassword = new JLabel();
159     private JPasswordField fSystemPassword = new JPasswordField();
160     private JLabel lMailServer = new JLabel();
161     private JTextField fMailServer = new JTextField();
162     private JLabel lAdminEMail = new JLabel();
163     private JTextField fAdminEMail = new JTextField();
164     private JLabel lDatabaseServer = new JLabel();
165     private JTextField fDatabaseServer = new JTextField();
166     private JLabel lJavaHome = new JLabel();
167     private JTextField fJavaHome = new JTextField();
168     private JButton bCompiereHome = new JButton(iOpen);
169     private JButton bJavaHome = new JButton(iOpen);
170     private JButton bHelp = new JButton(iHelp);
171     private JButton bTest = new JButton();
172     private JButton bSave = new JButton(iSave);
173     private JLabel lJNPPort = new JLabel();
174     private JTextField fJNPPort = new JTextField();
175     private JLabel lMailUser = new JLabel();
176     private JLabel lMailPassword = new JLabel();
177     private JTextField fMailUser = new JTextField();
178     private JPasswordField fMailPassword = new JPasswordField();
179
180
181     /**
182      * Static Layout Init
183      * @throws Exception
184      */

185     private void jbInit() throws Exception JavaDoc
186     {
187         lCompiereHome.setToolTipText(res.getString("CompiereHomeInfo"));
188         lCompiereHome.setText(res.getString("CompiereHome"));
189         this.setLayout(gridBagLayout);
190         fCompiereHome.setText("D:\\Compiere2");
191         lWebPort.setToolTipText(res.getString("WebPortInfo"));
192         lWebPort.setText(res.getString("WebPort"));
193         fWebPort.setText("80");
194         lAppsServer.setToolTipText(res.getString("AppsServerInfo"));
195         lAppsServer.setText(res.getString("AppsServer"));
196         fAppsServer.setText("server.company.com");
197         lDatabaseType.setToolTipText(res.getString("DatabaseTypeInfo"));
198         lDatabaseType.setText(res.getString("DatabaseType"));
199         lDatabaseName.setToolTipText(res.getString("DatabaseNameInfo"));
200         lDatabaseName.setText(res.getString("DatabaseName"));
201         lDatabasePort.setToolTipText(res.getString("DatabasePortInfo"));
202         lDatabasePort.setText(res.getString("DatabasePort"));
203         lDatabaseUser.setToolTipText(res.getString("DatabaseUserInfo"));
204         lDatabaseUser.setText(res.getString("DatabaseUser"));
205         lDatabasePassword.setToolTipText(res.getString("DatabasePasswordInfo"));
206         lDatabasePassword.setText(res.getString("DatabasePassword"));
207         fDatabaseName.setText("compiere");
208         fDatabasePort.setText("1521");
209         fDatabaseUser.setText("compiere");
210         fDatabasePassword.setText("compiere");
211         lTNSName.setToolTipText(res.getString("TNSNameInfo"));
212         lTNSName.setText(res.getString("TNSName"));
213         fTNSName.setEditable(true);
214         lSystemPassword.setToolTipText(res.getString("SystemPasswordInfo"));
215         lSystemPassword.setText(res.getString("SystemPassword"));
216         fSystemPassword.setText("manager");
217         lMailServer.setToolTipText(res.getString("MailServerInfo"));
218         lMailServer.setText(res.getString("MailServer"));
219         fMailServer.setText("mail.company.com");
220         lAdminEMail.setToolTipText(res.getString("AdminEMailInfo"));
221         lAdminEMail.setText(res.getString("AdminEMail"));
222         fAdminEMail.setText("admin@company.com");
223         bTest.setToolTipText(res.getString("TestInfo"));
224         bTest.setText(res.getString("Test"));
225         bSave.setToolTipText(res.getString("SaveInfo"));
226         bSave.setText(res.getString("Save"));
227         lDatabaseServer.setToolTipText(res.getString("DatabaseServerInfo"));
228         lDatabaseServer.setText(res.getString("DatabaseServer"));
229         lJavaHome.setToolTipText(res.getString("JavaHomeInfo"));
230         lJavaHome.setText(res.getString("JavaHome"));
231         fJavaHome.setText("Java141");
232         lJNPPort.setToolTipText(res.getString("JNPPortInfo"));
233         lJNPPort.setText(res.getString("JNPPort"));
234         fJNPPort.setText("1099");
235         bHelp.setToolTipText(res.getString("HelpInfo"));
236         lMailUser.setToolTipText(res.getString("MailUserInfo"));
237         lMailUser.setText(res.getString("MailUser"));
238         lMailPassword.setToolTipText(res.getString("MailPasswordInfo"));
239         lMailPassword.setText(res.getString("MailPassword"));
240         fMailUser.setText("compiere");
241         fMailPassword.setText("compiere");
242
243         //
244
this.add(lCompiereHome, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
245             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
246         this.add(fCompiereHome, new GridBagConstraints(1, 1, 1, 1, 0.5, 0.0
247             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
248         this.add(lWebPort, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
249             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
250         this.add(fWebPort, new GridBagConstraints(1, 3, 1, 1, 0.5, 0.0
251             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
252         this.add(lAppsServer, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
253             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
254         this.add(fAppsServer, new GridBagConstraints(1, 2, 1, 1, 0.5, 0.0
255             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
256         this.add(lDatabaseType, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
257             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
258         this.add(fDatabaseType, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
259             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
260         this.add(lDatabasePort, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
261             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
262         this.add(lDatabaseUser, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
263             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
264         this.add(fDatabaseName, new GridBagConstraints(1, 6, 1, 1, 0.5, 0.0
265             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
266         this.add(fDatabasePort, new GridBagConstraints(1, 7, 1, 1, 0.5, 0.0
267             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
268         this.add(fDatabaseUser, new GridBagConstraints(1, 8, 1, 1, 0.5, 0.0
269             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0));
270         this.add(lTNSName, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0
271             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
272         this.add(fTNSName, new GridBagConstraints(3, 5, 1, 1, 0.5, 0.0
273             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
274         this.add(lMailServer, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0
275             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
276         this.add(lSystemPassword, new GridBagConstraints(2, 7, 1, 1, 0.0, 0.0
277             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
278         this.add(fSystemPassword, new GridBagConstraints(3, 7, 1, 1, 0.5, 0.0
279             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
280         this.add(fDatabasePassword, new GridBagConstraints(3, 8, 1, 1, 0.5, 0.0
281             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0));
282         this.add(lDatabasePassword, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0
283             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
284         this.add(fMailServer, new GridBagConstraints(1, 9, 1, 1, 0.5, 0.0
285             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0));
286         this.add(bTest, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
287             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
288         this.add(bSave, new GridBagConstraints(3, 11, 1, 1, 0.0, 0.0
289             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
290         this.add(lDatabaseServer, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
291             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
292         this.add(fDatabaseServer, new GridBagConstraints(1, 5, 1, 1, 0.5, 0.0
293             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
294         this.add(lDatabaseName, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
295             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
296         this.add(lJavaHome, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
297             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
298         this.add(fJavaHome, new GridBagConstraints(1, 0, 1, 1, 0.5, 0.0
299             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
300         this.add(bCompiereHome, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
301             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
302         this.add(bHelp, new GridBagConstraints(2, 11, 1, 1, 0.0, 0.0
303             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
304         this.add(bJavaHome, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
305             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
306         this.add(lJNPPort, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
307             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
308         this.add(fJNPPort, new GridBagConstraints(3, 3, 1, 1, 0.5, 0.0
309             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
310         this.add(lMailPassword, new GridBagConstraints(2, 10, 1, 1, 0.0, 0.0
311             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
312         this.add(fMailPassword, new GridBagConstraints(3, 10, 1, 1, 0.5, 0.0
313             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0));
314         this.add(lAdminEMail, new GridBagConstraints(2, 9, 1, 1, 0.0, 0.0
315             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0));
316         this.add(fMailUser, new GridBagConstraints(1, 10, 1, 1, 0.5, 0.0
317             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0));
318         this.add(fAdminEMail, new GridBagConstraints(3, 9, 1, 1, 0.5, 0.0
319             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0));
320         this.add(lMailUser, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0
321             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 0), 0, 0));
322         //
323
bCompiereHome.addActionListener(this);
324         bJavaHome.addActionListener(this);
325         bHelp.addActionListener(this);
326         bTest.addActionListener(this);
327         bSave.addActionListener(this);
328     } // jbInit
329

330
331     /**
332      * Dynamic Init
333      * @throws Exception
334      */

335     private void dynInit() throws Exception JavaDoc
336     {
337         // Layout - Column Length
338
fWebPort.setColumns(30);
339         fJNPPort.setColumns(30);
340
341         // DatabaseType
342
fDatabaseType.addItem("Oracle 9i2");
343
344         // Compiere Home
345
String JavaDoc ch = System.getProperty(COMPIERE_HOME);
346         if (ch == null || ch.length() == 0)
347             ch = System.getProperty("user.dir");
348         fCompiereHome.setText(ch);
349         boolean envLoaded = false;
350         String JavaDoc fileName = ch + File.separator + COMPIERE_ENV_FILE;
351         File env = new File (fileName);
352         System.out.println(env + " - exists=" + env.exists());
353         if (env.exists())
354         {
355             try
356             {
357                 FileInputStream fis = new FileInputStream(env);
358                 m_properties.load(fis);
359                 fis.close();
360             }
361             catch (Exception JavaDoc e)
362             {
363                 System.err.println(e.toString());
364             }
365             System.out.println("Loading ...");
366             if (m_properties.size() > 5)
367                 envLoaded = true;
368             //
369
fCompiereHome.setText((String JavaDoc)m_properties.get(COMPIERE_HOME));
370             fJavaHome.setText((String JavaDoc)m_properties.get(JAVA_HOME));
371             fAppsServer.setText((String JavaDoc)m_properties.get(COMPIERE_APPS_SERVER));
372             fWebPort.setText((String JavaDoc)m_properties.get(COMPIERE_WEB_PORT));
373             fJNPPort.setText((String JavaDoc)m_properties.get(COMPIERE_JNP_PORT));
374
375             fDatabaseServer.setText((String JavaDoc)m_properties.get(COMPIERE_DB_SERVER));
376             fDatabasePort.setText((String JavaDoc)m_properties.get(COMPIERE_DB_PORT));
377             fDatabaseName.setText((String JavaDoc)m_properties.get(COMPIERE_DB_NAME));
378
379             fDatabaseUser.setText((String JavaDoc)m_properties.get(COMPIERE_DB_USER));
380             fDatabasePassword.setText((String JavaDoc)m_properties.get(COMPIERE_DB_PASSWORD));
381             fSystemPassword.setText((String JavaDoc)m_properties.get(COMPIERE_DB_SYSTEM));
382             fillTNSName((String JavaDoc)m_properties.get(COMPIERE_DB_TNS));
383
384             fMailServer.setText((String JavaDoc)m_properties.get(COMPIERE_MAIL_SERVER));
385             fMailUser.setText((String JavaDoc)m_properties.get(COMPIERE_MAIL_USER));
386             fMailPassword.setText((String JavaDoc)m_properties.get(COMPIERE_MAIL_PASSWORD));
387             fAdminEMail.setText((String JavaDoc)m_properties.get(COMPIERE_ADMIN_EMAIL));
388         }
389
390         // No environment file found - defaults
391
if (!envLoaded)
392         {
393             System.out.println("Setting Defaults");
394             // Java Home, e.g. D:\j2sdk1.4.1\jre
395
String JavaDoc javaHome = System.getProperty("java.home");
396             if (javaHome.endsWith("jre"))
397                 javaHome = javaHome.substring(0, javaHome.length()-4);
398             fJavaHome.setText(javaHome);
399             // AppsServer
400
fAppsServer.setText(InetAddress.getLocalHost().getHostName());
401             // Database Server
402
fDatabaseServer.setText(InetAddress.getLocalHost().getHostName());
403             // Mail Server
404
fMailServer.setText(InetAddress.getLocalHost().getHostName());
405             // Get TNS Names
406
fillTNSName("");
407         } // !envLoaded
408

409         // Default FTP stuff
410
if (!m_properties.containsKey(COMPIERE_FTP_SERVER))
411         {
412             m_properties.setProperty(COMPIERE_FTP_SERVER, "localhost");
413             m_properties.setProperty(COMPIERE_FTP_USER, "anonymous");
414             m_properties.setProperty(COMPIERE_FTP_PASSWORD, "user@host.com");
415             m_properties.setProperty(COMPIERE_FTP_PREFIX, "my");
416         }
417         // Default Java Options
418
if (!m_properties.containsKey(COMPIERE_JAVA_OPTIONS))
419             m_properties.setProperty(COMPIERE_JAVA_OPTIONS, "-Xms32m -Xmx128m");
420
421         // (String)m_properties.get(COMPIERE_DB_URL) // derived
422
} // dynInit
423

424     /**
425      * Fill TNS Name
426      * @param defaultValue defaultValue
427      */

428     private void fillTNSName (String JavaDoc defaultValue)
429     {
430         // default value to lowercase or null
431
String JavaDoc def = defaultValue;
432         if (def != null && def.trim().length() == 0)
433             def = null;
434         if (def != null)
435         {
436             def = def.toLowerCase();
437             fTNSName.addItem(def);
438         }
439
440         // Search for Oracle Info
441
String JavaDoc path = System.getProperty("java.library.path");
442         String JavaDoc[] entries = path.split(File.pathSeparator);
443         for (int e = 0; e < entries.length; e++)
444         {
445             String JavaDoc entry = entries[e].toLowerCase();
446             if (entry.indexOf("ora") != -1 && entry.endsWith("bin"))
447             {
448                 StringBuffer JavaDoc sb = getTNS_File (entries[e].substring(0, entries[e].length()-4));
449                 String JavaDoc[] tnsnames = getTNS_Names (sb);
450                 if (tnsnames != null)
451                 {
452                     for (int i = 0; i < tnsnames.length; i++)
453                     {
454                         String JavaDoc tns = tnsnames[i];
455                         if (!tns.equals(def))
456                             fTNSName.addItem(tns);
457                     }
458                     break;
459                 }
460             }
461         } // for all path entries
462

463         // Set first entry
464
fTNSName.addActionListener(this);
465         if (fTNSName.getItemCount() > 0)
466             fTNSName.setSelectedIndex(0);
467     } // fillTNSName
468

469     /**
470      * Get File tnmsnames.ora in StringBuffer
471      * @param oraHome ORACLE_HOME
472      * @return tnsnames.ora or null
473      */

474     private StringBuffer JavaDoc getTNS_File (String JavaDoc oraHome)
475     {
476         String JavaDoc tnsnames = oraHome + File.separator
477             + "network" + File.separator
478             + "admin" + File.separator
479             + "tnsnames.ora";
480         File tnsfile = new File (tnsnames);
481         if (!tnsfile.exists())
482             return null;
483
484         System.out.println("Searching " + tnsnames);
485         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
486         try
487         {
488             FileReader fr = new FileReader (tnsfile);
489             int c;
490             while ((c = fr.read()) != -1)
491                 sb.append((char)c);
492         }
493         catch (IOException ex)
494         {
495             System.err.println("Error Reading " + tnsnames);
496             ex.printStackTrace();
497             return null;
498         }
499         if (sb.length() == 0)
500             return null;
501         return sb;
502     } // getTNS_File
503

504     /**
505      * Get TNS Names entries.
506      * Assumes standard tnsmanes.ora formatting of NetMgr
507      * @param tnsnames content of tnsnames.ora
508      * @return tns names or null
509      */

510     private String JavaDoc[] getTNS_Names (StringBuffer JavaDoc tnsnames)
511     {
512         if (tnsnames == null)
513             return null;
514
515         ArrayList list = new ArrayList();
516         Pattern pattern = Pattern.compile("$", Pattern.MULTILINE);
517         String JavaDoc[] lines = pattern.split(tnsnames);
518         for (int i = 0; i < lines.length; i++)
519         {
520             String JavaDoc line = lines[i].trim();
521             if (line.length() > 0
522                 && Character.isLetter(line.charAt(0)) // no # (
523
&& line.indexOf("=") != -1
524                 && line.indexOf("EXTPROC_") == -1
525                 && line.indexOf("_HTTP") == -1)
526             {
527                 String JavaDoc entry = line.substring(0, line.indexOf('=')).trim().toLowerCase();
528                 System.out.println("- " + entry);
529                 list.add(entry);
530             }
531         }
532         // Convert to Array
533
if (list.size() == 0)
534             return null;
535         String JavaDoc[] retValue = new String JavaDoc[list.size()];
536         list.toArray(retValue);
537         return retValue;
538     } // getTNS_Names
539

540     /*************************************************************************/
541
542     /**
543      * ActionListener
544      * @param e event
545      */

546     public void actionPerformed(ActionEvent e)
547     {
548         if (m_testing)
549             return;
550         // TNS Name Changed
551
if (e.getSource() == fTNSName)
552         {
553             String JavaDoc tns = (String JavaDoc)fTNSName.getSelectedItem();
554             if (tns != null)
555             {
556                 int pos = tns.indexOf('.');
557                 if (pos != -1)
558                     tns = tns.substring(0, pos);
559                 fDatabaseName.setText(tns);
560             }
561         }
562
563         else if (e.getSource() == bJavaHome)
564             setPath (fJavaHome);
565         else if (e.getSource() == bCompiereHome)
566             setPath (fCompiereHome);
567         else if (e.getSource() == bHelp)
568             new Setup_Help((Frame)SwingUtilities.getWindowAncestor(this));
569         else if (e.getSource() == bTest)
570             startTest();
571         else if (e.getSource() == bSave)
572             save();
573     } // actionPerformed
574

575     /**
576      * Set Path in Field
577      * @param field field to set Path
578      */

579     private void setPath (JTextField field)
580     {
581         JFileChooser fc = new JFileChooser(field.getText());
582         fc.setDialogType(JFileChooser.OPEN_DIALOG);
583         fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
584         fc.setMultiSelectionEnabled(false);
585         if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
586             field.setText(fc.getSelectedFile().getAbsolutePath());
587     } // setPath
588

589     /*************************************************************************/
590
591     /**
592      * Start Test Async.
593      * @return SwingWorker
594      */

595     private SwingWorker startTest()
596     {
597         SwingWorker worker = new SwingWorker()
598         {
599             // Start it
600
public Object JavaDoc construct()
601             {
602                 m_testing = true;
603                 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
604                 bTest.setEnabled(false);
605                 m_success = false;
606                 m_errorString = null;
607                 try
608                 {
609                     test();
610                 }
611                 catch (Exception JavaDoc ex)
612                 {
613                     ex.printStackTrace();
614                     m_errorString = ex.getMessage();
615                 }
616                 //
617
setCursor(Cursor.getDefaultCursor());
618                 if (m_errorString == null)
619                     m_success = true;
620                 bTest.setEnabled(true);
621                 m_testing = false;
622                 return new Boolean JavaDoc(m_success);
623             }
624             // Finish it
625
public void finished()
626             {
627                 if (m_errorString != null)
628                 {
629                     System.err.println(m_errorString);
630                     JOptionPane.showConfirmDialog (null, m_errorString, res.getString("ServerError"),
631                         JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
632                 }
633             }
634         };
635         worker.start();
636         return worker;
637     } // startIt
638

639     /**
640      * Test it
641      * @throws Exception
642      */

643     private void test() throws Exception JavaDoc
644     {
645         System.out.println();
646         System.out.println("** Test **");
647         bSave.setEnabled(false);
648
649
650         // Java Home
651
m_errorString = res.getString("ErrorJavaHome");
652         m_javaHome = new File (fJavaHome.getText());
653         if (!m_javaHome.exists())
654             return;
655         File tools = new File (fJavaHome.getText() + File.separator + "lib" + File.separator + "tools.jar");
656         if (!tools.exists())
657         {
658             System.err.println("Not Found Java SDK = " + tools);
659             return;
660         }
661         System.out.println("OK: JavaHome=" + m_javaHome.getAbsolutePath());
662         m_properties.setProperty(JAVA_HOME, m_javaHome.getAbsolutePath());
663
664         // Java Version
665
final String JavaDoc VERSION = "1.4.1";
666         final String JavaDoc VERSION2 = "1.4.2";
667         boolean versionOK = false;
668         String JavaDoc jh = m_javaHome.getAbsolutePath();
669         if (jh.indexOf(VERSION) != -1) // file name has version = assuming OK
670
versionOK = true;
671         if (!versionOK && jh.indexOf(VERSION2) != -1) //
672
versionOK = true;
673         String JavaDoc thisJH = System.getProperty("java.home");
674         if (thisJH.indexOf(jh) != -1) // wre are running the version currently
675
{
676             String JavaDoc thisJV = System.getProperty("java.version");
677             versionOK = thisJV.indexOf(VERSION) != -1;
678             if (versionOK)
679               System.out.println(" Java Version OK = " + thisJV);
680         }
681         if (!versionOK)
682           System.out.println("** Please check Java Version - should be " + VERSION2 + "*");
683
684         // Compiere Home
685
m_errorString = res.getString("ErrorCompiereHome");
686         m_compiereHome = new File (fCompiereHome.getText());
687         if (!m_compiereHome.exists())
688         {
689             System.err.println("Not found CompiereHome = " + m_compiereHome);
690             return;
691         }
692         System.out.println("OK: CompiereHome = " + m_compiereHome);
693         m_properties.setProperty(COMPIERE_HOME, m_compiereHome.getAbsolutePath());
694
695
696         // AppsServer
697
m_errorString = res.getString("ErrorAppsServer");
698         String JavaDoc server = fAppsServer.getText();
699         if (server == null || server.length() == 0 || server.toLowerCase().indexOf("localhost") != -1)
700         {
701             System.err.println("Not correct AppsServer = " + m_appsServer);
702             return;
703         }
704         m_appsServer = InetAddress.getByName(server);
705         System.out.println("OK: AppsServer = " + m_appsServer);
706         m_properties.setProperty(COMPIERE_APPS_SERVER, m_appsServer.getHostName());
707
708         // Web Port
709
m_errorString = res.getString("ErrorWebPort");
710         m_statusBar.setText(lWebPort.getText());
711         m_WebPort = Integer.parseInt(fWebPort.getText());
712         // HTML Port Use
713
if (testPort ("http", m_appsServer.getHostName(), m_WebPort, "/") || !testServerPort(m_WebPort))
714         {
715             System.err.println("Not correct WebPort = " + m_WebPort);
716             return;
717         }
718         System.out.println("OK: WebPort = " + m_WebPort);
719         m_properties.setProperty(COMPIERE_WEB_PORT, String.valueOf(m_WebPort));
720         // Derive SSL Port
721
int sslPort = m_WebPort == 80 ? 443 : 8443;
722         System.out.println("SSL WebPort = " + sslPort);
723         m_properties.setProperty(COMPIERE_SSL_PORT, String.valueOf(sslPort));
724
725
726         // JNP Port
727
m_errorString = res.getString("ErrorJNPPort");
728         m_statusBar.setText(lJNPPort.getText());
729         m_JNPPort = Integer.parseInt(fJNPPort.getText());
730         // HTML Port Use
731
if (testPort (m_appsServer, m_JNPPort, false) || !testServerPort(m_JNPPort))
732         {
733             System.err.println("Not correct JNPPort = " + m_JNPPort);
734             return;
735         }
736         System.out.println("OK: JNPPort = " + m_JNPPort);
737         m_properties.setProperty(COMPIERE_JNP_PORT, String.valueOf(m_JNPPort));
738
739
740         // Database Server
741
m_errorString = res.getString("ErrorDatabaseServer");
742         m_statusBar.setText(lDatabaseServer.getText());
743         server = fDatabaseServer.getText();
744         if (server == null || server.length() == 0 || server.toLowerCase().indexOf("localhost") != -1)
745         {
746             System.err.println("Not correct Database Server = " + server);
747             return;
748         }
749         m_databaseServer = InetAddress.getByName(server);
750         System.out.println("OK: Database Server = " + m_databaseServer);
751         m_properties.setProperty(COMPIERE_DB_SERVER, m_databaseServer.getHostName());
752
753
754         // Database Port
755
m_errorString = res.getString("ErrorDatabasePort");
756         m_databasePort = Integer.parseInt(fDatabasePort.getText());
757         // Database Port Use
758
if (!testPort (m_databaseServer, m_databasePort, true))
759         {
760             System.err.println("Error Database Port = " + m_databasePort);
761             return;
762         }
763         System.out.println("OK: Database Port = " + m_databasePort);
764         m_properties.setProperty(COMPIERE_DB_PORT, String.valueOf(m_databasePort));
765
766
767         // JDBC Database Info
768
m_errorString = res.getString("ErrorJDBC");
769         m_statusBar.setText(lDatabaseName.getText());
770         m_databaseName = fDatabaseName.getText(); // SID
771
m_systemPassword = new String JavaDoc(fSystemPassword.getPassword());
772         if (!testJDBC("system", m_systemPassword))
773         {
774             System.err.println("Error Database Name = " + m_databaseName);
775             System.err.println("Error Database SystemID = system/" + m_systemPassword);
776             return;
777         }
778         System.out.println("OK: Database Name = " + m_databaseName);
779         m_properties.setProperty(COMPIERE_DB_NAME, m_databaseName);
780         System.out.println("OK: Database SystemID = system/" + m_systemPassword);
781         m_properties.setProperty(COMPIERE_DB_SYSTEM, m_systemPassword);
782         // URL (derived) jdbc:oracle:thin:@prod1:1521:prod1
783
StringBuffer JavaDoc url = new StringBuffer JavaDoc("jdbc:oracle:thin:@")
784             .append(m_databaseServer).append(":")
785             .append(m_databasePort).append(":").append(m_databaseName);
786         System.out.println("OK: Database URL = " + url.toString());
787         m_properties.setProperty(COMPIERE_DB_URL, url.toString());
788
789
790         // Database User Info
791
m_databaseUser = fDatabaseUser.getText(); // UID
792
m_databasePassword = new String JavaDoc(fDatabasePassword.getPassword()); // PWD
793
// Ignore result as it might not be imported
794
if (testJDBC(m_databaseUser, m_databasePassword))
795             System.out.println("OK: Database UserID = " + m_databaseUser + "/" + m_databasePassword);
796         else
797             System.out.println("Not created yet: Database UserID = " + m_databaseUser + "/" + m_databasePassword);
798         m_properties.setProperty(COMPIERE_DB_USER, m_databaseUser);
799         m_properties.setProperty(COMPIERE_DB_PASSWORD, m_databasePassword);
800
801
802         // TNS Name Info
803
m_errorString = res.getString("ErrorTNS");
804         m_statusBar.setText(lTNSName.getText());
805         m_TNSName = (String JavaDoc)fTNSName.getSelectedItem();
806         if (!testTNS("system", m_systemPassword))
807         {
808             System.err.println("Error Database TNS Name = " + m_TNSName);
809             return;
810         }
811         System.out.println("OK: Database TNS Name = " + m_TNSName);
812         m_properties.setProperty(COMPIERE_DB_TNS, m_TNSName);
813
814
815         // Mail Server
816
m_errorString = res.getString("ErrorMailServer");
817         m_statusBar.setText(lMailServer.getText());
818         server = fMailServer.getText();
819         if (server == null || server.length() == 0)
820         {
821             System.err.println("Error Mail Server = " + server);
822             return;
823         }
824         m_mailServer = InetAddress.getByName(server);
825         System.out.println("OK: Mail Server = " + m_mailServer);
826         m_properties.setProperty(COMPIERE_MAIL_SERVER, m_mailServer.getHostName());
827
828
829         // Mail User
830
m_errorString = "ErrorMailUser";
831         m_statusBar.setText(lMailUser.getText());
832         m_mailUser = fMailUser.getText();
833         m_mailPassword = new String JavaDoc(fMailPassword.getPassword());
834         m_properties.setProperty(COMPIERE_MAIL_USER, m_mailUser);
835         m_properties.setProperty(COMPIERE_MAIL_PASSWORD, m_mailPassword);
836         System.out.println(" Mail User = " + m_mailUser + "/" + m_mailPassword);
837
838         // Mail Address
839
m_errorString = res.getString("ErrorMail");
840         m_adminEMail = new InternetAddress (fAdminEMail.getText());
841         //
842
if (testMail())
843             System.out.println("OK: Admin EMail = " + m_adminEMail);
844         else
845             System.out.println("Not verified Admin EMail = " + m_adminEMail);
846         m_properties.setProperty(COMPIERE_ADMIN_EMAIL, m_adminEMail.toString());
847
848         //
849
m_statusBar.setText(res.getString("Ok"));
850         System.out.println("** Test OK **");
851         bSave.setEnabled(true);
852         m_errorString = null;
853     } // test
854

855
856     /**
857      * Test Apps Server Port (client perspective)
858      * @param protocol protocol (http, ..)
859      * @param server server name
860      * @param port port
861      * @param file file name
862      * @return true if able to connect
863      */

864     private boolean testPort (String JavaDoc protocol, String JavaDoc server, int port, String JavaDoc file)
865     {
866         URL url = null;
867         try
868         {
869             url = new URL (protocol, server, port, file);
870         }
871         catch (MalformedURLException ex)
872         {
873             ex.printStackTrace();
874             return false;
875         }
876         System.out.println(" URL=" + url);
877         try
878         {
879             URLConnection c = url.openConnection();
880             Object JavaDoc o = c.getContent();
881             System.err.println(" URL Connection in use=" + url); // error
882
}
883         catch (Exception JavaDoc ex)
884         {
885             return false;
886         }
887         return true;
888     } // testPort
889

890     /**
891      * Test Server Port
892      * @param port port
893      * @return true if able to create
894      */

895     private boolean testServerPort (int port)
896     {
897         try
898         {
899             ServerSocket ss = new ServerSocket (port);
900             System.out.println(" ServerPort " + ss.getInetAddress() + ":" + ss.getLocalPort());
901             ss.close();
902         }
903         catch (Exception JavaDoc ex)
904         {
905             System.err.println(ex);
906             return false;
907         }
908         return true;
909     } // testPort
910

911
912     /**
913      * Test Port
914      * @param host host
915      * @param port port
916      * @param shouldBenUsed true if it should be used
917      * @return true if some server answered on port
918      */

919     public boolean testPort (InetAddress host, int port, boolean shouldBenUsed)
920     {
921         Socket pingSocket = null;
922         try
923         {
924             pingSocket = new Socket(host, port);
925         }
926         catch (Exception JavaDoc e)
927         {
928             if (shouldBenUsed)
929                 System.err.println(" Open Socket " + host + " on " + port + ": " + e.getMessage());
930             return false;
931         }
932         if (!shouldBenUsed)
933             System.err.println(" Open Socket " + host + " on " + port);
934         if (pingSocket == null)
935             return false;
936         // success
937
try
938         {
939             pingSocket.close();
940         }
941         catch (IOException e)
942         {
943             System.out.println(" CloseSocket=" + e.toString());
944         }
945         return true;
946     } // testPort
947

948     /**
949      * Test JDBC Connection to Server
950      * @param uid user id
951      * @param pwd password
952      * @return true if OK
953      */

954     private boolean testJDBC (String JavaDoc uid, String JavaDoc pwd)
955     {
956         // jdbc:oracle:thin:@dev:1521:dev1
957
m_connectionString = "jdbc:oracle:thin:@"
958             + m_databaseServer.getHostName() + ":" + m_databasePort + ":" + m_databaseName;
959         System.out.println(" JDBC = " + m_connectionString);
960
961         try
962         {
963             if (s_driver == null)
964             {
965                 s_driver = new OracleDriver();
966                 DriverManager.registerDriver(s_driver);
967             }
968             Connection con = DriverManager.getConnection(m_connectionString,
969                 uid, pwd);
970         }
971         catch (Exception JavaDoc e)
972         {
973             System.err.println(e.toString());
974             return false;
975         }
976         return true;
977     } // testJDBC
978

979     /**
980      * Test TNS Connection
981      * @param uid user id
982      * @param pwd password
983      * @return true if OK
984      */

985     private boolean testTNS (String JavaDoc uid, String JavaDoc pwd)
986     {
987         String JavaDoc connectionString = "jdbc:oracle:oci8:@" + m_TNSName;
988         System.out.println(" TNS = " + connectionString);
989         try
990         {
991             if (s_driver == null)
992             {
993                 s_driver = new OracleDriver();
994                 DriverManager.registerDriver(s_driver);
995             }
996             Connection con = DriverManager.getConnection(connectionString,
997                 uid, pwd);
998         }
999         catch (UnsatisfiedLinkError JavaDoc ule)
1000        {
1001            System.err.println("Check setup of Oracle Server / Oracle Client / LD_LIBRARY_PATH");
1002            System.err.println(ule.toString());
1003            return false;
1004        }
1005        catch (Exception JavaDoc e)
1006        {
1007            System.err.println(e.toString());
1008            return false;
1009        }
1010        return true;
1011    } // testTNS
1012

1013    /**
1014     * Test Mail
1015     * @return true of OK
1016     */

1017    private boolean testMail()
1018    {
1019        boolean smtpOK = false;
1020        boolean imapOK = false;
1021        if (testPort (m_mailServer, 25, true))
1022        {
1023            System.out.println("OK: SMTP Server contacted");
1024            smtpOK = true;
1025        }
1026        else
1027            System.err.println("Error: SMTP Server NOT available");
1028        //
1029
if (testPort (m_mailServer, 110, true))
1030            System.out.println("OK: POP3 Server contacted");
1031        else
1032            System.err.println("Error: POP3 Server NOT available");
1033        if (testPort (m_mailServer, 143, true))
1034        {
1035            System.out.println("OK: IMAP4 Server contacted");
1036            imapOK = true;
1037        }
1038        else
1039            System.err.println("Error: IMAP4 Server NOT available");
1040        //
1041
if (!smtpOK)
1042            return false;
1043        //
1044
try
1045        {
1046            EMail em = new EMail (m_mailServer.getHostName (),
1047                       m_adminEMail.toString (), m_adminEMail.toString (),
1048                       "Compiere Server Setup Test", "Test: " + m_properties);
1049            em.setEMailUser (m_mailUser, m_mailPassword);
1050            if (EMail.SENT_OK.equals (em.send ()))
1051            {
1052                System.out.println ("OK: Send Test Email to " + m_adminEMail);
1053            }
1054            else
1055            {
1056                System.err.println ("Error: Could NOT send Email to "
1057                    + m_adminEMail);
1058            }
1059        }
1060        catch (Exception JavaDoc ex)
1061        {
1062            System.err.println("testMail - " + ex.getLocalizedMessage());
1063            return false;
1064        }
1065
1066        //
1067
if (!imapOK)
1068            return false;
1069
1070        // Test Read Mail Access
1071
Properties props = new Properties();
1072        props.put("mail.store.protocol", "smtp");
1073        props.put("mail.transport.protocol", "smtp");
1074        props.put("mail.host", m_mailServer.getHostName());
1075        props.put("mail.user", m_mailUser);
1076        props.put("mail.smtp.auth", "true");
1077        System.out.println(" Connecting to " + m_mailServer.getHostName());
1078        //
1079
Session session = null;
1080        Store store = null;
1081        try
1082        {
1083            EMailAuthenticator auth = new EMailAuthenticator (m_mailUser, m_mailPassword);
1084            session = Session.getDefaultInstance(props, auth);
1085            session.setDebug (Log.isTraceLevel (10));
1086            System.out.println(" Session=" + session);
1087            // Connect to Store
1088
store = session.getStore("imap");
1089            System.out.println(" Store=" + store);
1090        }
1091        catch (NoSuchProviderException nsp)
1092        {
1093            System.err.println("Error Mail IMAP Provider - " + nsp.getMessage());
1094            return false;
1095        }
1096        catch (Exception JavaDoc e)
1097        {
1098            System.err.println("Error Mail IMAP - " + e.getMessage());
1099            return false;
1100        }
1101        try
1102        {
1103            store.connect(m_mailServer.getHostName(), m_mailUser, m_mailPassword);
1104            System.out.println(" Store - connected");
1105            Folder folder = store.getDefaultFolder();
1106            Folder inbox = folder.getFolder("INBOX");
1107            System.out.println("OK: Mail Connect to " + inbox.getFullName() + " #Msg=" + inbox.getMessageCount());
1108            //
1109
store.close();
1110        }
1111        catch (MessagingException mex)
1112        {
1113            System.err.println("Error Mail Connect " + mex.getMessage());
1114            return false;
1115        }
1116        return true;
1117    } // testMail
1118

1119    /*************************************************************************/
1120
1121    /**
1122     * Save Settings
1123     */

1124    private void save()
1125    {
1126        SwingWorker sw = startTest();
1127        while (sw.isAlive())
1128        {
1129            try
1130            {
1131                Thread.sleep(2000);
1132            }
1133            catch (InterruptedException JavaDoc ex)
1134            {
1135                System.err.println("save-waiting: " + ex);
1136            }
1137        }
1138        sw.get(); // block
1139
if (!m_success)
1140            return;
1141
1142        // Add
1143
m_properties.setProperty("COMPIERE_MAIN_VERSION", Compiere.MAIN_VERSION);
1144        m_properties.setProperty("COMPIERE_DATE_VERSION", Compiere.DATE_VERSION);
1145        m_properties.setProperty("COMPIERE_DB_VERSION", Compiere.DB_VERSION);
1146
1147
1148
1149        // Before we save, load Ini
1150
Ini.setClient(false);
1151        String JavaDoc fileName = m_compiereHome.getAbsolutePath() + File.separator + Ini.COMPIERE_PROPERTY_FILE;
1152        Ini.loadProperties(fileName);
1153
1154        // Save Environment
1155
fileName = m_compiereHome.getAbsolutePath() + File.separator + COMPIERE_ENV_FILE;
1156        try
1157        {
1158            FileOutputStream fos = new FileOutputStream(new File(fileName));
1159            m_properties.store(fos, COMPIERE_ENV_FILE);
1160            fos.flush();
1161            fos.close();
1162        }
1163        catch (Exception JavaDoc e)
1164        {
1165            System.err.println ("Cannot save Properties to " + fileName + " - " + e.toString());
1166            JOptionPane.showConfirmDialog(this, res.getString("ErrorSave"), res.getString("CompiereServerSetup"),
1167                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
1168            return;
1169        }
1170        catch (Throwable JavaDoc t)
1171        {
1172            System.err.println ("Cannot save Properties to " + fileName + " - " + t.toString());
1173            JOptionPane.showConfirmDialog(this, res.getString("ErrorSave"), res.getString("CompiereServerSetup"),
1174                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
1175            return;
1176        }
1177        System.out.println("Properties saved to " + fileName);
1178
1179        // Sync Properties
1180
Ini.setCompiereHome(m_compiereHome.getAbsolutePath());
1181        CConnection cc = CConnection.get (Database.DB_ORACLE,
1182            m_databaseServer.getHostName(), m_databasePort, m_databaseName,
1183            m_databaseUser, m_databasePassword);
1184        cc.setAppsHost(m_appsServer.getHostName());
1185        cc.setRMIoverHTTP(false);
1186        Ini.setProperty(Ini.P_CONNECTION, cc.toStringLong());
1187        Ini.saveProperties(false);
1188
1189
1190        JOptionPane.showConfirmDialog(this, res.getString("EnvironmentSaved"),
1191            res.getString("CompiereServerSetup"),
1192            JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
1193
1194        ((Frame)SwingUtilities.getWindowAncestor(this)).dispose();
1195        System.exit(0); // remains active when License Dialog called
1196
} // save
1197

1198} // ConfigurationPanel
1199
Popular Tags