001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.tools.encrypt_prop;
025:
026: import java.io.DataOutputStream;
027: import java.io.File;
028: import java.io.FileOutputStream;
029: import java.io.InputStream;
030: import java.io.OutputStream;
031: import java.net.URL;
032: import java.util.Properties;
033: import java.util.StringTokenizer;
034:
035: import javax.swing.JFileChooser;
036: import javax.swing.JOptionPane;
037: import javax.swing.filechooser.FileFilter;
038:
039: import org.objectweb.salome_tmf.tools.languages.Language;
040:
041: public class configDBTool extends javax.swing.JFrame {
042:
043: File propFile = null;
044: Properties prop = new Properties();
045: boolean keyFileExists = true;
046: URL urlDir = null;
047: static boolean calledInInstallProc = false;
048: static String installDir = null;
049: public static String locale = "en";
050: final static String DEFAULT_WITH_ICAL = "false";
051: final static String DEFAULT_DB_LOCK = "0";
052: final static String DEFAULT_LOCK_ON_TEST_EXEC = "false";
053: final static String DEFAULT_LOCK_EXECUTED_TEST = "true";
054: final static String DEFAULT_SQLENGINE_SOAP = "false";
055:
056: /** Creates new form EncryptDBPropTool */
057: public configDBTool() {
058: initComponents();
059: cancelButton.setText(Language.getInstance().getText("Annuler"));
060: debugField.setText("false");
061: ideDevField.setText("false");
062: allowPluginsField.setText("true");
063: netChangeTackField.setText("false");
064: //availableLocalsField.setText("fr,en");
065: //this.setLocation(100,150);
066: this .setLocationRelativeTo(this .getParent());
067: if (calledInInstallProc) {
068: chooseFileButton.setEnabled(false);
069: }
070: }
071:
072: /** This method is called from within the constructor to
073: * initialize the form.
074: * WARNING: Do NOT modify this code. The content of this method is
075: * always regenerated by the Form Editor.
076: */
077: private void initComponents() {//GEN-BEGIN:initComponents
078: propsFilePanel = new javax.swing.JPanel();
079: propFileLabel = new javax.swing.JLabel();
080: propFileField = new javax.swing.JTextField();
081: chooseFileButton = new javax.swing.JButton();
082: jdbcDriverLabel = new javax.swing.JLabel();
083: jdbcDriverField = new javax.swing.JTextField();
084: jPanel1 = new javax.swing.JPanel();
085: jLabel3 = new javax.swing.JLabel();
086: jLabel1 = new javax.swing.JLabel();
087: jLabel6 = new javax.swing.JLabel();
088: jLabel7 = new javax.swing.JLabel();
089: hostField = new javax.swing.JTextField();
090: jPanel8 = new javax.swing.JPanel();
091: jLabel8 = new javax.swing.JLabel();
092: jLabel9 = new javax.swing.JLabel();
093: jLabel2 = new javax.swing.JLabel();
094: dbNameField = new javax.swing.JTextField();
095: jPanel2 = new javax.swing.JPanel();
096: jLabel4 = new javax.swing.JLabel();
097: dbUserLabel = new javax.swing.JLabel();
098: dbUserField = new javax.swing.JTextField();
099: jPanel3 = new javax.swing.JPanel();
100: userPwdLabel = new javax.swing.JLabel();
101: userPwdField = new javax.swing.JPasswordField();
102: sqlEngineLabel = new javax.swing.JLabel();
103: sqlEngineField = new javax.swing.JTextField();
104: jPanel15 = new javax.swing.JPanel();
105:
106: debugField = new javax.swing.JTextField();
107: debugLabel = new javax.swing.JLabel();
108: ideDevField = new javax.swing.JTextField();
109: ideDevLabel = new javax.swing.JLabel();
110: allowPluginsField = new javax.swing.JTextField();
111: allowPluginsLabel = new javax.swing.JLabel();
112: netChangeTackField = new javax.swing.JTextField();
113: netChangeTackLabel = new javax.swing.JLabel();
114: /*availableLocalsField = new javax.swing.JTextField();
115: availableLocalsLabel = new javax.swing.JLabel();*/
116:
117: jPanel9 = new javax.swing.JPanel();
118: jPanel10 = new javax.swing.JPanel();
119: jPanel11 = new javax.swing.JPanel();
120: jPanel12 = new javax.swing.JPanel();
121: jPanel13 = new javax.swing.JPanel();
122: jPanel14 = new javax.swing.JPanel();
123: buttonsPanel = new javax.swing.JPanel();
124: jPanel4 = new javax.swing.JPanel();
125: encryptButton = new javax.swing.JButton();
126: createDBButton = new javax.swing.JButton();
127: cancelButton = new javax.swing.JButton();
128: jPanel5 = new javax.swing.JPanel();
129: jPanel6 = new javax.swing.JPanel();
130: jPanel7 = new javax.swing.JPanel();
131:
132: setTitle(Language.getInstance().getText(
133: "Outil_de_configuration_de_la_base_de_données"));
134: setLocationRelativeTo(this );
135: addWindowListener(new java.awt.event.WindowAdapter() {
136: public void windowClosing(java.awt.event.WindowEvent evt) {
137: exitForm(evt);
138: }
139: });
140:
141: propsFilePanel.setLayout(new java.awt.GridLayout(12, 3, 3, 3));
142:
143: propsFilePanel.setMinimumSize(new java.awt.Dimension(750, 350));
144: propsFilePanel
145: .setPreferredSize(new java.awt.Dimension(750, 350));
146: propFileLabel
147: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
148: propFileLabel.setText(Language.getInstance().getText(
149: "Fichier_de_configuration_:"));
150: propsFilePanel.add(propFileLabel);
151:
152: propFileField.setEditable(false);
153: propsFilePanel.add(propFileField);
154:
155: chooseFileButton
156: .setIcon(new javax.swing.ImageIcon(
157: getClass()
158: .getResource(
159: "/org/objectweb/salome_tmf/tools/encrypt_prop/images/openFile.gif")));
160: chooseFileButton.setText(Language.getInstance().getText(
161: "Ouvrir_un_fichier..."));
162: chooseFileButton
163: .addActionListener(new java.awt.event.ActionListener() {
164: public void actionPerformed(
165: java.awt.event.ActionEvent evt) {
166: chooseFilePerformed(evt);
167: }
168: });
169:
170: propsFilePanel.add(chooseFileButton);
171:
172: jdbcDriverLabel
173: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
174: jdbcDriverLabel.setText(Language.getInstance().getText(
175: "Driver_JDBC_:"));
176: propsFilePanel.add(jdbcDriverLabel);
177:
178: jdbcDriverField.setText("com.mysql.jdbc.Driver");
179: propsFilePanel.add(jdbcDriverField);
180:
181: jPanel1.setLayout(new java.awt.BorderLayout());
182:
183: //jLabel3.setText("com.mysql.jdbc.Driver");
184: jPanel1.add(jLabel3, java.awt.BorderLayout.WEST);
185:
186: //jLabel1.setText(Language.getInstance().getText("Exemple_:"));
187: jPanel1.add(jLabel1, java.awt.BorderLayout.NORTH);
188:
189: jPanel1.add(jLabel6, java.awt.BorderLayout.SOUTH);
190:
191: propsFilePanel.add(jPanel1);
192:
193: sqlEngineLabel
194: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
195: sqlEngineLabel.setText("SQL Engine :");
196: propsFilePanel.add(sqlEngineLabel);
197:
198: sqlEngineField
199: .setText("org.objectweb.salome_tmf.databaseSQL.SQLObjectFactory");
200: propsFilePanel.add(sqlEngineField);
201:
202: propsFilePanel.add(jPanel15);
203:
204: jLabel7
205: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
206: jLabel7.setText(Language.getInstance().getText(
207: "Serveur_de_la_base_de_données_:"));
208: propsFilePanel.add(jLabel7);
209:
210: propsFilePanel.add(hostField);
211:
212: jPanel8.setLayout(new java.awt.BorderLayout());
213:
214: jLabel8.setText(Language.getInstance().getText("Exemple_:_"));
215: jPanel8.add(jLabel8, java.awt.BorderLayout.NORTH);
216:
217: jLabel9.setText("lat****.rd.francetelecom.fr");
218: jPanel8.add(jLabel9, java.awt.BorderLayout.CENTER);
219:
220: propsFilePanel.add(jPanel8);
221:
222: jLabel2
223: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
224: jLabel2.setText(Language.getInstance().getText(
225: "Nom_de_la_base_de_données_:"));
226: propsFilePanel.add(jLabel2);
227:
228: propsFilePanel.add(dbNameField);
229:
230: jPanel2.setLayout(new java.awt.BorderLayout());
231:
232: jPanel2.add(jLabel4, java.awt.BorderLayout.CENTER);
233:
234: propsFilePanel.add(jPanel2);
235:
236: dbUserLabel
237: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
238: dbUserLabel.setText(Language.getInstance().getText(
239: "Nom_de_l'utilisateur_de_la_base_:"));
240: propsFilePanel.add(dbUserLabel);
241:
242: propsFilePanel.add(dbUserField);
243:
244: propsFilePanel.add(jPanel3);
245:
246: userPwdLabel
247: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
248: userPwdLabel.setText(Language.getInstance().getText(
249: "Mot_de_passe_de_l'utilisateur:"));
250: propsFilePanel.add(userPwdLabel);
251:
252: propsFilePanel.add(userPwdField);
253:
254: propsFilePanel.add(jPanel9);
255: // Debug
256: debugLabel
257: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
258: debugLabel.setText(Language.getInstance().getText(
259: "Mode_debug_(booléen)_:"));
260: propsFilePanel.add(debugLabel);
261:
262: propsFilePanel.add(debugField);
263:
264: propsFilePanel.add(jPanel10);
265:
266: // IDE Dev
267: ideDevLabel
268: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
269: ideDevLabel.setText(Language.getInstance().getText(
270: "IDE_Dev._(booléen)_:"));
271: propsFilePanel.add(ideDevLabel);
272:
273: propsFilePanel.add(ideDevField);
274:
275: propsFilePanel.add(jPanel11);
276:
277: // Allow plugins
278: allowPluginsLabel
279: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
280: allowPluginsLabel.setText(Language.getInstance().getText(
281: "Autoriser_les_plugins_(booléen)_:"));
282: propsFilePanel.add(allowPluginsLabel);
283:
284: propsFilePanel.add(allowPluginsField);
285:
286: propsFilePanel.add(jPanel12);
287:
288: // Network changements tracking
289: netChangeTackLabel
290: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
291: netChangeTackLabel.setText(Language.getInstance().getText(
292: "Net._tracking_(booleén)_:"));
293: propsFilePanel.add(netChangeTackLabel);
294:
295: propsFilePanel.add(netChangeTackField);
296:
297: propsFilePanel.add(jPanel13);
298:
299: // Network changements tracking
300: /*availableLocalsLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
301: availableLocalsLabel.setText(Language.getInstance().getText("Available_locales_(fr,en...)_:"));
302: propsFilePanel.add(availableLocalsLabel);
303:
304: propsFilePanel.add(availableLocalsField);*/
305:
306: propsFilePanel.add(jPanel14);
307:
308: getContentPane().add(propsFilePanel,
309: java.awt.BorderLayout.CENTER);
310:
311: buttonsPanel.setLayout(new java.awt.BorderLayout());
312:
313: encryptButton
314: .setFont(new java.awt.Font("MS Sans Serif", 1, 11));
315: encryptButton.setForeground(new java.awt.Color(0, 153, 0));
316: encryptButton
317: .setIcon(new javax.swing.ImageIcon(
318: getClass()
319: .getResource(
320: "/org/objectweb/salome_tmf/tools/encrypt_prop/images/encrypt.gif")));
321: encryptButton.setText(Language.getInstance().getText(
322: "Sauvegarder_fichier"));
323: encryptButton
324: .addActionListener(new java.awt.event.ActionListener() {
325: public void actionPerformed(
326: java.awt.event.ActionEvent evt) {
327: encryptPerformed(evt);
328: }
329: });
330:
331: jPanel4.add(encryptButton);
332:
333: createDBButton
334: .setFont(new java.awt.Font("MS Sans Serif", 1, 11));
335: createDBButton.setForeground(new java.awt.Color(0, 0, 255));
336: createDBButton
337: .setIcon(new javax.swing.ImageIcon(
338: getClass()
339: .getResource(
340: "/org/objectweb/salome_tmf/tools/encrypt_prop/images/db.gif")));
341: createDBButton.setText(Language.getInstance().getText(
342: "Créer_la_base_de_données"));
343: createDBButton
344: .setPreferredSize(new java.awt.Dimension(240, 41));
345: createDBButton
346: .addActionListener(new java.awt.event.ActionListener() {
347: public void actionPerformed(
348: java.awt.event.ActionEvent evt) {
349: createDBPerformed(evt);
350: }
351: });
352:
353: jPanel4.add(createDBButton);
354:
355: cancelButton.setFont(new java.awt.Font("MS Sans Serif", 0, 10));
356: cancelButton.setForeground(new java.awt.Color(255, 0, 0));
357: cancelButton.setText(Language.getInstance().getText("Annuler"));
358: cancelButton.setMinimumSize(new java.awt.Dimension(121, 41));
359: cancelButton.setPreferredSize(new java.awt.Dimension(121, 41));
360: cancelButton
361: .addActionListener(new java.awt.event.ActionListener() {
362: public void actionPerformed(
363: java.awt.event.ActionEvent evt) {
364: cancelPerformed(evt);
365: }
366: });
367:
368: jPanel4.add(cancelButton);
369:
370: buttonsPanel.add(jPanel4, java.awt.BorderLayout.CENTER);
371:
372: getContentPane().add(buttonsPanel, java.awt.BorderLayout.SOUTH);
373:
374: getContentPane().add(jPanel5, java.awt.BorderLayout.NORTH);
375:
376: getContentPane().add(jPanel6, java.awt.BorderLayout.EAST);
377:
378: getContentPane().add(jPanel7, java.awt.BorderLayout.WEST);
379:
380: pack();
381: }//GEN-END:initComponents
382:
383: private void createDBPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createDBPerformed
384: // TODO add your handling code here:
385: createDBForm dbForm = new createDBForm(this );
386: //dbForm.setHostName(hostField.getText());
387: dbForm.setHostName("localhost");
388: String driverJDBC = jdbcDriverField.getText();
389: String sqlEngine = sqlEngineField.getText();
390: String dbName = dbNameField.getText();
391: String salomeUsr = dbUserField.getText();
392: String clairPwd = new String(userPwdField.getPassword());
393: //String salomeUsrPwd = new String(userPwdField.getPassword());
394:
395: if (jdbcDriverField.equals("")) {
396: JOptionPane
397: .showMessageDialog(
398: this ,
399: Language
400: .getInstance()
401: .getText(
402: "Vous_devez_saisir_le_nom_du_driver_JDBC_!"),
403: Language.getInstance().getText("Erreur..."),
404: JOptionPane.ERROR_MESSAGE);
405: } else {
406: if (dbName.equals("")) {
407: JOptionPane
408: .showMessageDialog(
409: this ,
410: Language
411: .getInstance()
412: .getText(
413: "Vous_devez_saisir_le_nom_de_la_base_de_données!"),
414: Language.getInstance().getText(
415: "Erreur..."),
416: JOptionPane.ERROR_MESSAGE);
417: } else {
418: if (salomeUsr.equals("")) {
419: JOptionPane
420: .showMessageDialog(
421: this ,
422: Language
423: .getInstance()
424: .getText(
425: "Vous_devez_saisir_le_nom_de_l'utilisateur_de_Salomé_TMF!"),
426: Language.getInstance().getText(
427: "Erreur..."),
428: JOptionPane.ERROR_MESSAGE);
429: } else {
430: if (propFileField.getText().equals("")) {
431: JOptionPane
432: .showMessageDialog(
433: this ,
434: Language
435: .getInstance()
436: .getText(
437: "Vous_devez_ouvrir_et_créer_un_nouveau_fichier_properties_(en_saisissant_les_\n")
438: + Language
439: .getInstance()
440: .getText(
441: "champs_puis__cliquer_sur_le_bouton_\"Sauvegarder_fichier\")_avant_de_créer_\n")
442: + Language
443: .getInstance()
444: .getText(
445: "la_base_de_données!"),
446: Language.getInstance().getText(
447: "Erreur..."),
448: JOptionPane.ERROR_MESSAGE);
449: } else {
450: dbForm.setJDBCdriver(driverJDBC);
451: dbForm.setDBName(dbName);
452: dbForm.setSalomeUser(salomeUsr);
453: dbForm.setSalomeUserPwd(clairPwd);
454: dbForm.show();
455: }
456: }
457: }
458: }
459:
460: }//GEN-LAST:event_createDBPerformed
461:
462: private void encryptPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_encryptPerformed
463: prop.setProperty("DriverJDBC", jdbcDriverField.getText());
464: prop.setProperty("SQLEngine", sqlEngineField.getText());
465: prop.setProperty("URL", "jdbc:mysql://" + hostField.getText()
466: + "/" + dbNameField.getText());
467: prop.setProperty("User", dbUserField.getText());
468: String clearKey = new String(userPwdField.getPassword());
469: // New variables
470: prop.setProperty("Debug", debugField.getText());
471: prop.setProperty("IDE_Dev", ideDevField.getText());
472: prop.setProperty("AllowPlugins", allowPluginsField.getText());
473: prop
474: .setProperty("NetChangeTrack", netChangeTackField
475: .getText());
476: //prop.setProperty("LocalesList",availableLocalsField.getText());
477: //prop.setProperty("Locale",locale);
478:
479: // TODO add your handling code here:
480: // Cas ou le fichier properties existe
481: if (calledInInstallProc) {
482: try {
483: URL urlInstall = new File(installDir
484: + java.io.File.separator + "cfg").toURL();
485: MD5paswd.writekey(urlInstall.getPath());
486: MD5paswd.readkey(urlInstall);
487: String cryptedKey = MD5paswd.encrypString(clearKey);
488: prop.setProperty("Password", cryptedKey);
489: } catch (Exception e1) {
490: e1.printStackTrace();
491: JOptionPane
492: .showMessageDialog(
493: this ,
494: Language
495: .getInstance()
496: .getText(
497: "Problèmes_rencontrés_suite_à_la_tentative_de_lecture_de_la_clé_!"),
498: Language.getInstance().getText(
499: "Erreur..."),
500: JOptionPane.ERROR_MESSAGE);
501: }
502: try {
503: prop.setProperty("WithICAL", DEFAULT_WITH_ICAL);
504: prop.setProperty("DBLOCK", DEFAULT_DB_LOCK);
505: prop.setProperty("LockOnTestExec",
506: DEFAULT_LOCK_ON_TEST_EXEC);
507: prop.setProperty("LockExecutedTest",
508: DEFAULT_LOCK_EXECUTED_TEST);
509: prop.setProperty("SQLEngineSOAP",
510: DEFAULT_SQLENGINE_SOAP);
511: propFile = new File(installDir + java.io.File.separator
512: + "cfg" + java.io.File.separator
513: + "DB_Connexion.properties");
514: OutputStream os = new DataOutputStream(
515: new FileOutputStream(propFile));
516: prop.store(os, "");
517:
518: } catch (Exception e2) {
519: e2.printStackTrace();
520: JOptionPane
521: .showMessageDialog(
522: this ,
523: Language
524: .getInstance()
525: .getText(
526: "Problèmes_rencontrés_suite_à_la_tentative_d'écriture_sur_le_fichier_"),
527: Language.getInstance().getText(
528: "Erreur..."),
529: JOptionPane.ERROR_MESSAGE);
530: }
531: JOptionPane
532: .showMessageDialog(
533: this ,
534: Language
535: .getInstance()
536: .getText(
537: "Les_fichiers_de_configuration_de_la_base_et_de_la_clé_ont_été_sauvegardés_dans\n_")
538: + installDir + "/cfg/ !", Language
539: .getInstance().getText("Info..."),
540: JOptionPane.INFORMATION_MESSAGE);
541: propFileField.setText(propFile.getAbsolutePath());
542: chooseFileButton.setEnabled(true);
543: } else {
544: if (!propFileField.getText().equals("")) {
545: // Cas ou la clé de cryptage existe
546: if (keyFileExists) {
547: try {
548: MD5paswd.readkey(urlDir);
549: } catch (Exception e1) {
550: e1.printStackTrace();
551: JOptionPane
552: .showMessageDialog(
553: this ,
554: Language
555: .getInstance()
556: .getText(
557: "Problèmes_rencontrés_suite_à_la_tentative_de_lecture_de_la_clé_!"),
558: Language.getInstance().getText(
559: "Erreur..."),
560: JOptionPane.ERROR_MESSAGE);
561: }
562: }
563: // Cas ou cette clé n'existe pas
564: else {
565: try {
566: MD5paswd.writekey(urlDir.getPath());
567: keyFileExists = true;
568: MD5paswd.readkey(urlDir);
569: } catch (Exception e1) {
570: e1.printStackTrace();
571: JOptionPane
572: .showMessageDialog(
573: this ,
574: Language
575: .getInstance()
576: .getText(
577: "Problèmes_rencontrés_suite_à_la_tentative_d'écriture_de_la_clé_!"),
578: Language.getInstance().getText(
579: "Erreur..."),
580: JOptionPane.ERROR_MESSAGE);
581: }
582:
583: }
584:
585: String cryptedKey = MD5paswd.encrypString(clearKey);
586: prop.setProperty("Password", cryptedKey);
587:
588: try {
589: OutputStream os = new DataOutputStream(
590: new FileOutputStream(propFile));
591: prop.store(os, "");
592: JOptionPane
593: .showMessageDialog(
594: this ,
595: Language
596: .getInstance()
597: .getText(
598: "Le_fichier_a_bien_été_sauvegardé_!"),
599: Language.getInstance().getText(
600: "Info..."),
601: JOptionPane.INFORMATION_MESSAGE);
602: } catch (Exception e2) {
603: e2.printStackTrace();
604: JOptionPane
605: .showMessageDialog(
606: this ,
607: Language
608: .getInstance()
609: .getText(
610: "Problèmes_rencontrés_suite_à_la_tentative_d'écriture_du_fichier!"),
611: Language.getInstance().getText(
612: "Erreur..."),
613: JOptionPane.ERROR_MESSAGE);
614: }
615: }
616: // Cas ou le fichier properties n'existe pas
617: else {
618: JOptionPane
619: .showMessageDialog(
620: this ,
621: Language
622: .getInstance()
623: .getText(
624: "Vous_devez_choisir_un_répertoire_où_le_'DB_Connexion.properties'_\n")
625: + Language
626: .getInstance()
627: .getText(
628: "_et_'key.txt'_seront_sauvés."),
629: Language.getInstance().getText(
630: "Info..."),
631: JOptionPane.INFORMATION_MESSAGE);
632:
633: JFileChooser fileChooser = new JFileChooser();
634: fileChooser.setApproveButtonText(Language.getInstance()
635: .getText("Valider"));
636: fileChooser.setCurrentDirectory(new File("."));
637: fileChooser
638: .setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
639: int returnVal = fileChooser
640: .showOpenDialog(configDBTool.this );
641: if (returnVal == JFileChooser.APPROVE_OPTION) {
642: try {
643: urlDir = fileChooser.getSelectedFile().toURL();
644: MD5paswd.writekey(urlDir.getPath());
645: keyFileExists = true;
646: MD5paswd.readkey(urlDir);
647: String cryptedKey = MD5paswd
648: .encrypString(clearKey);
649: prop.setProperty("Password", cryptedKey);
650: } catch (Exception e1) {
651: e1.printStackTrace();
652: JOptionPane
653: .showMessageDialog(
654: this ,
655: Language
656: .getInstance()
657: .getText(
658: "Problèmes_rencontrés_suite_à_la_tentative_de_lecture_de_la_clé!"),
659: Language.getInstance().getText(
660: "Erreur..."),
661: JOptionPane.ERROR_MESSAGE);
662: }
663: try {
664: prop.setProperty("WithICAL", DEFAULT_WITH_ICAL);
665: prop.setProperty("DBLOCK", DEFAULT_DB_LOCK);
666: prop.setProperty("LockOnTestExec",
667: DEFAULT_LOCK_ON_TEST_EXEC);
668: prop.setProperty("LockExecutedTest",
669: DEFAULT_LOCK_EXECUTED_TEST);
670: prop.setProperty("SQLEngineSOAP",
671: DEFAULT_SQLENGINE_SOAP);
672: propFile = new File(fileChooser
673: .getSelectedFile().getPath()
674: + java.io.File.separator
675: + "DB_Connexion.properties");
676: OutputStream os = new DataOutputStream(
677: new FileOutputStream(propFile));
678: prop.store(os, "");
679:
680: } catch (Exception e2) {
681: e2.printStackTrace();
682: JOptionPane
683: .showMessageDialog(
684: this ,
685: Language
686: .getInstance()
687: .getText(
688: "Problèmes_rencontrés_suite_à_la_tentative_d'écriture_de_la_clé!"),
689: Language.getInstance().getText(
690: "Erreur..."),
691: JOptionPane.ERROR_MESSAGE);
692: }
693: JOptionPane
694: .showMessageDialog(
695: this ,
696: Language
697: .getInstance()
698: .getText(
699: "Le_fichier_de_configuration_de_la_base_et_la_clé_ont_bien_été_sauvegardés_!"),
700: Language.getInstance().getText(
701: "Info..."),
702: JOptionPane.INFORMATION_MESSAGE);
703: propFileField.setText(propFile.getAbsolutePath());
704: }
705: }
706: }
707: }//GEN-LAST:event_encryptPerformed
708:
709: private void cancelPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelPerformed
710: // TODO add your handling code here:
711: this .dispose();
712: }//GEN-LAST:event_cancelPerformed
713:
714: private void chooseFilePerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFilePerformed
715: // TODO add your handling code here:
716: JFileChooser fileChooser = new JFileChooser();
717: fileChooser.setApproveButtonText(Language.getInstance()
718: .getText("Valider"));
719: fileChooser.setCurrentDirectory(new File("."));
720: FileFilter[] fileFilterTab = fileChooser
721: .getChoosableFileFilters();
722: for (int i = 0; i < fileFilterTab.length; i++) {
723: fileChooser.removeChoosableFileFilter(fileFilterTab[i]);
724: }
725: fileChooser.addChoosableFileFilter(new PropsFileFilter(
726: "Properties file [*.properties]", ".properties"));
727: int returnVal = fileChooser.showOpenDialog(configDBTool.this );
728: if (returnVal == JFileChooser.APPROVE_OPTION) {
729: propFile = fileChooser.getSelectedFile();
730: propFileField.setText(propFile.getAbsolutePath());
731: URL urlFile = null;
732:
733: try {
734: urlFile = propFile.toURL();
735: InputStream in = urlFile.openStream();
736: prop.load(in);
737: in.close();
738: } catch (Exception e1) {
739: e1.printStackTrace();
740: JOptionPane
741: .showMessageDialog(
742: this ,
743: Language
744: .getInstance()
745: .getText(
746: "Problèmes_rencontrés_suite_à_la_tentative_de_lecture_du_fichier!"),
747: Language.getInstance().getText(
748: "Erreur..."),
749: JOptionPane.ERROR_MESSAGE);
750: }
751:
752: jdbcDriverField.setText(prop.getProperty("DriverJDBC"));
753: String dbURL = prop.getProperty("URL");
754: StringTokenizer st = new StringTokenizer(dbURL, "/", false);
755: int length = st.countTokens();
756: String[] blocks = new String[length];
757: int i = 0;
758: for (; st.hasMoreTokens();) {
759: blocks[i] = st.nextToken().trim();
760: i++;
761: }
762: dbNameField.setText(blocks[length - 1]);
763: hostField.setText(blocks[length - 2]);
764: dbUserField.setText(prop.getProperty("User"));
765: String cryptedPwd = prop.getProperty("Password");
766:
767: //New varaiables
768: debugField.setText(prop.getProperty("Debug"));
769: ideDevField.setText(prop.getProperty("IDE_Dev"));
770: allowPluginsField.setText(prop.getProperty("AllowPlugins"));
771: netChangeTackField.setText(prop
772: .getProperty("NetChangeTrack"));
773:
774: //availableLocalsField.setText(prop.getProperty("LocalesList"));
775:
776: String urlFileTxt = urlFile.toString();
777: try {
778: urlDir = new URL(urlFileTxt.substring(0, urlFileTxt
779: .lastIndexOf("/")));
780: MD5paswd.readkey(urlDir);
781: String pwd = MD5paswd.decryptString(cryptedPwd);
782: userPwdField.setText(pwd);
783: } catch (Exception e3) {
784: e3.printStackTrace();
785: JOptionPane
786: .showMessageDialog(
787: this ,
788: Language
789: .getInstance()
790: .getText(
791: "Le_fichier__('key.txt')_n'existe_pas._\n")
792: + Language
793: .getInstance()
794: .getText(
795: "Le_mot_de_passe_ne_peut_être_décrypté,_mais_vous_pouvez_le_changer._\n")
796: + Language
797: .getInstance()
798: .getText(
799: "Le_fichier_'key.txt'_sera_crée."),
800: Language.getInstance().getText(
801: "Avertissement..."),
802: JOptionPane.WARNING_MESSAGE);
803: keyFileExists = false;
804: userPwdField.setText("");
805: }
806:
807: }
808: }//GEN-LAST:event_chooseFilePerformed
809:
810: /** Exit the Application */
811: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
812: System.exit(0);
813: }//GEN-LAST:event_exitForm
814:
815: /**
816: * @param args the command line arguments
817: */
818: public static void main(String args[]) {
819: if (args.length == 2) {
820: calledInInstallProc = true;
821: installDir = args[0];
822: if (args[1].equals("fra")) {
823: locale = "fr";
824: } else if (args[1].equals("eng")) {
825: locale = "en";
826: }
827: }
828: new configDBTool().show();
829: }
830:
831: // Variables declaration - do not modify//GEN-BEGIN:variables
832: private javax.swing.JPanel buttonsPanel;
833: private javax.swing.JButton cancelButton;
834: private javax.swing.JButton chooseFileButton;
835: private javax.swing.JButton createDBButton;
836: private javax.swing.JTextField dbNameField;
837: private javax.swing.JTextField dbUserField;
838: private javax.swing.JLabel dbUserLabel;
839: private javax.swing.JButton encryptButton;
840: private javax.swing.JTextField hostField;
841: private javax.swing.JLabel jLabel1;
842: private javax.swing.JLabel jLabel2;
843: private javax.swing.JLabel jLabel3;
844: private javax.swing.JLabel jLabel4;
845: private javax.swing.JLabel jLabel6;
846: private javax.swing.JLabel jLabel7;
847: private javax.swing.JLabel jLabel8;
848: private javax.swing.JLabel jLabel9;
849: private javax.swing.JPanel jPanel1;
850: private javax.swing.JPanel jPanel2;
851: private javax.swing.JPanel jPanel3;
852: private javax.swing.JPanel jPanel4;
853: private javax.swing.JPanel jPanel5;
854: private javax.swing.JPanel jPanel6;
855: private javax.swing.JPanel jPanel7;
856: private javax.swing.JPanel jPanel8;
857: private javax.swing.JPanel jPanel9;
858: private javax.swing.JPanel jPanel10;
859: private javax.swing.JPanel jPanel11;
860: private javax.swing.JPanel jPanel12;
861: private javax.swing.JPanel jPanel13;
862: private javax.swing.JPanel jPanel14;
863: private javax.swing.JPanel jPanel15;
864: private javax.swing.JTextField jdbcDriverField;
865: private javax.swing.JLabel jdbcDriverLabel;
866: private javax.swing.JTextField propFileField;
867: private javax.swing.JLabel propFileLabel;
868: private javax.swing.JPanel propsFilePanel;
869: private javax.swing.JPasswordField userPwdField;
870: private javax.swing.JLabel userPwdLabel;
871: private javax.swing.JLabel sqlEngineLabel;
872: private javax.swing.JTextField sqlEngineField;
873:
874: private javax.swing.JTextField debugField;
875: private javax.swing.JLabel debugLabel;
876: private javax.swing.JTextField ideDevField;
877: private javax.swing.JLabel ideDevLabel;
878: private javax.swing.JTextField allowPluginsField;
879: private javax.swing.JLabel allowPluginsLabel;
880: private javax.swing.JTextField netChangeTackField;
881: private javax.swing.JLabel netChangeTackLabel;
882: /*private javax.swing.JTextField availableLocalsField;
883: private javax.swing.JLabel availableLocalsLabel;*/
884: // End of variables declaration//GEN-END:variables
885: }
|