Author: jflesch
Date: 2007-05-01 19:19:01 +0000 (Tue, 01 May 2007)
New Revision: 13092

Modified:
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
   trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java
Log:
add two options to import and exports keys to / from the logs

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-05-01 
18:45:50 UTC (rev 13091)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-05-01 
19:19:01 UTC (rev 13092)
@@ -453,7 +453,7 @@
 thaw.plugin.transferLogs.transferLogsShort=Journal

 thaw.plugin.transferLogs.purgeLogs=Purger le journal
-thaw.plugin.transferLogs.copyKey=Copier la clef li?e ? cette entr?e
+thaw.plugin.transferLogs.copyKey=Copier les clefs li?es aux entr?es 
s?lectionn?es

 thaw.plugin.transferLogs.date=Date
 thaw.plugin.transferLogs.message=Message
@@ -471,5 +471,9 @@
 thaw.plugin.transferLogs.finalStatus=Status final
 thaw.plugin.transferLogs.none=(aucune)

-thaw.plugin.transferLogs.importLogs=Import keys
-thaw.plugin.transferLogs.exportLogs=Export keys
+thaw.plugin.transferLogs.importLogs=Importer une liste de clefs
+thaw.plugin.transferLogs.exportLogs=Exporter une liste de clefs
+thaw.plugin.transferLogs.chooseFile=Choisisez un fichier
+thaw.plugin.transferLogs.importedKey=Clef import?e
+
+

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-05-01 18:45:50 UTC 
(rev 13091)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-05-01 19:19:01 UTC 
(rev 13092)
@@ -458,7 +458,7 @@
 thaw.plugin.transferLogs.transferLogsShort=Logs

 thaw.plugin.transferLogs.purgeLogs=Purge logs
-thaw.plugin.transferLogs.copyKey=Copy the key related to this entry
+thaw.plugin.transferLogs.copyKey=Copy the keys related to the selected entries

 thaw.plugin.transferLogs.date=Date
 thaw.plugin.transferLogs.message=Message
@@ -475,3 +475,8 @@

 thaw.plugin.transferLogs.finalStatus=Final status
 thaw.plugin.transferLogs.none=(none)
+
+thaw.plugin.transferLogs.importKeys=Import key list
+thaw.plugin.transferLogs.exportKeys=Export key list
+thaw.plugin.transferLogs.chooseFile=Choose a file
+thaw.plugin.transferLogs.importedKey=Imported key

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-05-01 18:45:50 UTC 
(rev 13091)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-05-01 19:19:01 UTC 
(rev 13092)
@@ -303,7 +303,7 @@
 thaw.plugin.index.autoRefreshInterval=Intervalle de rafraichissement (en 
secondes):
 thaw.plugin.index.nmbIndexPerRefresh=Nombre d'indexes rafraichis au cours de 
l'intervalle:

-thaw.plugin.index.importExportPlugin=Index import / export
+thaw.plugin.index.importExportPlugin=Import / export de la base de 
donn\u00e9es d'indexes
 thaw.plugin.index.export=Export
 thaw.plugin.index.import=Import
 thaw.plugin.index.export.indexKeys=Clefs des indexes + les dossiers
@@ -435,6 +435,12 @@
 thaw.plugin.signature.ignoreLowerThan=Ignorer les signatures avec un status 
inf\u00e9rieur \u00e0


+thaw.plugin.signature.delete.areYouSureTitle=Suicider votre vous-m\u00eame 
anonyme ?
+thaw.plugin.signature.delete.areYouSure=\u00cates-vous s\u00fbr de vouloir 
supprimer cette identit\u00e9 ?
+
+thaw.plugin.signature.delete.cant=Impossible de supprimer cette identit\u00e9 
: Quelques messages doivent probablement \u00eatre toujours rattach\u00e9s 
\u00e0 cette identit\u00e9
+
+
 # Zeroconf

 thaw.zeroconf.searchingNode=Recherche de noeuds Freenet ...
@@ -447,7 +453,7 @@
 thaw.plugin.transferLogs.transferLogsShort=Journal

 thaw.plugin.transferLogs.purgeLogs=Purger le journal
-thaw.plugin.transferLogs.copyKey=Copier la clef li\u00e9e \u00e0 cette 
entr\u00e9e
+thaw.plugin.transferLogs.copyKey=Copier les clefs li\u00e9es aux entr\u00e9es 
s\u00e9lectionn\u00e9es

 thaw.plugin.transferLogs.date=Date
 thaw.plugin.transferLogs.message=Message
@@ -464,3 +470,10 @@

 thaw.plugin.transferLogs.finalStatus=Status final
 thaw.plugin.transferLogs.none=(aucune)
+
+thaw.plugin.transferLogs.importLogs=Importer une liste de clefs
+thaw.plugin.transferLogs.exportLogs=Exporter une liste de clefs
+thaw.plugin.transferLogs.chooseFile=Choisisez un fichier
+thaw.plugin.transferLogs.importedKey=Clef import\u00e9e
+
+

Modified: trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java  2007-05-01 18:45:50 UTC 
(rev 13091)
+++ trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java  2007-05-01 19:19:01 UTC 
(rev 13092)
@@ -24,11 +24,19 @@

 import java.sql.*;

+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.DataInputStream;
+import java.io.BufferedReader;

+
 import thaw.core.Core;
 import thaw.core.Logger;
 import thaw.gui.IconBox;
 import thaw.gui.Table;
+import thaw.gui.FileChooser;
 import thaw.gui.GUIHelper;
 import thaw.core.I18n;
 import thaw.core.Plugin;
@@ -101,12 +109,19 @@

                purgeLogs = new 
JButton(I18n.getMessage("thaw.plugin.transferLogs.purgeLogs"), 
IconBox.minDelete);
                copyKey = new 
JButton(I18n.getMessage("thaw.plugin.transferLogs.copyKey"), IconBox.minCopy );
+               importKeys = new 
JButton(I18n.getMessage("thaw.plugin.transferLogs.importKeys"), 
IconBox.minImportAction);
+               exportKeys = new 
JButton(I18n.getMessage("thaw.plugin.transferLogs.exportKeys"), 
IconBox.minExportAction);
+
                purgeLogs.addActionListener(this);
                copyKey.addActionListener(this);
+               importKeys.addActionListener(this);
+               exportKeys.addActionListener(this);


-               JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
+               JPanel buttonPanel = new JPanel();
                buttonPanel.add(purgeLogs);
+               buttonPanel.add(importKeys);
+               buttonPanel.add(exportKeys);
                buttonPanel.add(copyKey);

                JPanel southPanel = new JPanel(new BorderLayout());
@@ -520,6 +535,120 @@
        }


+       private File chooseFile(boolean save) {
+               FileChooser fileChooser = new FileChooser();
+               
fileChooser.setTitle(I18n.getMessage("thaw.plugin.transferLogs.chooseFile"));
+               fileChooser.setDirectoryOnly(false);
+               fileChooser.setDialogType(save ? FileChooser.SAVE_DIALOG
+                                         : FileChooser.OPEN_DIALOG);
+               return fileChooser.askOneFile();
+       }
+
+
+       private class KeyImporter implements Runnable {
+               public KeyImporter() { }
+
+               public void run() {
+                       java.sql.Timestamp date = new java.sql.Timestamp((new 
java.util.Date()).getTime());
+
+
+                       File file  = chooseFile(false);
+
+                       if (file == null)
+                               return;
+
+                       try {
+                               FileInputStream fstream = new 
FileInputStream(file);
+
+                               DataInputStream in = new 
DataInputStream(fstream);
+                               BufferedReader br = new BufferedReader(new 
InputStreamReader(in));
+
+                               String strLine;
+
+                               while ((strLine = br.readLine()) != null)   {
+                                       String key = strLine.trim();
+
+                                       if (!FreenetURIHelper.isAKey(key))
+                                               continue;
+
+                                       boolean isDup = isDup(key);
+                                       String str = 
I18n.getMessage("thaw.plugin.transferLogs.importedKey")
+                                               + " : 
"+FreenetURIHelper.getFilenameFromKey(key);
+
+                                       try {
+                                               synchronized(db.dbLock) {
+                                                       PreparedStatement st;
+
+                                                       st = 
db.getConnection().prepareStatement("INSERT INTO transferEvents "+
+                                                                               
                 "(date, msg, key, isDup, isSuccess) "+
+                                                                               
                 " VALUES "+
+                                                                               
                 "(?, ?, ?, ?, FALSE)");
+                                                       st.setTimestamp(1, 
date);
+                                                       st.setString(2, str);
+                                                       st.setString(3, key);
+                                                       st.setBoolean(4, isDup);
+
+                                                       st.execute();
+                                               }
+                                       } catch(SQLException e) {
+                                               Logger.error(this, "Error while 
adding an event to the logs: "+e.toString());
+                                       }
+                               }
+
+                       in.close();
+
+                       } catch(java.io.FileNotFoundException e) {
+                               Logger.error(this, "(1) Unable to import keys 
because: "+e.toString());
+                       } catch(java.io.IOException e) {
+                               Logger.error(this, "(2) Unable to import keys 
because: "+e.toString());
+                       }
+
+                       model.reloadList();
+               }
+       }
+
+
+       private class KeyExporter implements Runnable {
+               public KeyExporter() { }
+
+               public void run() {
+                       File file  = chooseFile(true);
+
+                       if (file == null)
+                               return;
+
+                       try {
+                               FileOutputStream out = new 
FileOutputStream(file);
+
+                               synchronized(db.dbLock) {
+                                       PreparedStatement st;
+
+                                       st = 
db.getConnection().prepareStatement("SELECT DISTINCT key "+
+                                                                               
 "FROM transferEvents "+
+                                                                               
 "WHERE key is NOT NULL");
+
+                                       ResultSet set = st.executeQuery();
+
+                                       while(set.next()) {
+                                               
out.write((set.getString("key")+"\n").getBytes("UTF-8"));
+                                       }
+                               }
+
+                               out.close();
+
+                       } catch(SQLException e) {
+                               Logger.error(this, "Unable to export keys 
because: "+e.toString());
+                       } catch(java.io.FileNotFoundException e) {
+                               Logger.error(this, "(1) Unable to export keys 
because : "+e.toString());
+                       } catch(java.io.IOException e) {
+                               Logger.error(this, "(2) Unable to export keys 
because : "+e.toString());
+                       }
+
+               }
+       }
+
+
+
        public void actionPerformed(ActionEvent e) {

                if (e.getSource() == purgeLogs) {
@@ -551,5 +680,18 @@

                        return;
                }
+
+
+               if (e.getSource() == importKeys) {
+                       Thread th = new Thread(new KeyImporter());
+                       th.start();
+                       return;
+               }
+
+               if (e.getSource() == exportKeys) {
+                       Thread th = new Thread(new KeyExporter());
+                       th.start();
+                       return;
+               }
        }
 }


Reply via email to