Author: jflesch
Date: 2007-07-03 11:50:25 +0000 (Tue, 03 Jul 2007)
New Revision: 13886

Modified:
   trunk/apps/Thaw/gpl.txt
   trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
   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/index/AutoRefresh.java
   trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
   trunk/apps/Thaw/src/thaw/plugins/index/DetailPanel.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
Log:
Add the insertion date to the indexes and display this date in the interface

Modified: trunk/apps/Thaw/gpl.txt
===================================================================
--- trunk/apps/Thaw/gpl.txt     2007-07-03 11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/gpl.txt     2007-07-03 11:50:25 UTC (rev 13886)
@@ -1,3 +1,9 @@
+The following license is only valid for the code provided in the java
+package 'thaw'. For the other packages, see the corresponding
+licenses.
+
+======================================================================
+
                    GNU GENERAL PUBLIC LICENSE
                       Version 2, June 1991


Modified: trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/ConfigWindow.java     2007-07-03 11:32:40 UTC 
(rev 13885)
+++ trunk/apps/Thaw/src/thaw/core/ConfigWindow.java     2007-07-03 11:50:25 UTC 
(rev 13886)
@@ -234,18 +234,25 @@

                        dialog.setSize(150, 30);

-                       final Dimension screenSize =
+                       Dimension screenSize =
                                Toolkit.getDefaultToolkit().getScreenSize();

-                       final Dimension dialogSize = dialog.getSize();
+                       Dimension dialogSize = dialog.getSize();
                        dialog.setLocation(dialogSize.width/2 - 
(dialogSize.width/2),
                                           dialogSize.height/2 - 
(dialogSize.height/2));

                        dialog.setVisible(true);

-                       /* should reinit the whole connection correctly */
+                       dialog.setSize(150, 30);
+
+                       dialogSize = dialog.getSize();
+                       dialog.setLocation(dialogSize.width/2 - 
(dialogSize.width/2),
+                                          dialogSize.height/2 - 
(dialogSize.height/2));
+
+
                        core.getPluginManager().stopPlugins();

+                       /* should reinit the whole connection correctly */
                        if (resetConnection && !core.initConnection()) {
                                new thaw.gui.WarningWindow(dialog,
                                                           
I18n.getMessage("thaw.warning.unableToConnectTo")+

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-07-03 
11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-07-03 
11:50:25 UTC (rev 13886)
@@ -373,6 +373,8 @@
 thaw.plugin.index.numberOfFiles=Nombre de fichiers : ?
 thaw.plugin.index.numberOfLinks=Nombre de liens : ?

+thaw.plugin.index.insertionDate=Inser? le : ?
+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connexion

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-07-03 11:32:40 UTC 
(rev 13885)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-07-03 11:50:25 UTC 
(rev 13886)
@@ -382,7 +382,9 @@

 thaw.plugin.index.numberOfFiles=Number of files : ?
 thaw.plugin.index.numberOfLinks=Number of links : ?
+thaw.plugin.index.insertionDate=Inserted : ?

+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connection

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-07-03 11:32:40 UTC 
(rev 13885)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-07-03 11:50:25 UTC 
(rev 13886)
@@ -373,6 +373,8 @@
 thaw.plugin.index.numberOfFiles=Nombre de fichiers : ?
 thaw.plugin.index.numberOfLinks=Nombre de liens : ?

+thaw.plugin.index.insertionDate=Inser\u00e9 le : ?
+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connexion

Modified: trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java     2007-07-03 
11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java     2007-07-03 
11:50:25 UTC (rev 13886)
@@ -93,7 +93,7 @@
                        ResultSet results;
                        int ret;

-                       st = c.prepareStatement("SELECT id, originalName, 
displayName, publicKey, privateKey, author, positionInTree, revision "+
+                       st = c.prepareStatement("SELECT id, originalName, 
displayName, publicKey, privateKey, author, positionInTree, revision, 
insertionDate "+
                                                "FROM indexes ORDER by RAND() 
LIMIT 1");

                        results = st.executeQuery();
@@ -118,6 +118,7 @@
                                                  results.getInt("revision"),
                                                  
results.getString("privateKey"),
                                                  
results.getString("displayName"),
+                                                 
results.getDate("insertionDate"),
                                                  false, false);

                                index.downloadFromFreenet(this, 
browserPanel.getIndexTree(), queueManager);

Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-07-03 
11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-07-03 
11:50:25 UTC (rev 13886)
@@ -91,7 +91,7 @@

                if (config.getValue("indexDatabaseVersion") == null) {
                        newDb = true;
-                       config.setValue("indexDatabaseVersion", "6");
+                       config.setValue("indexDatabaseVersion", "7");
                } else {

                        /* CONVERTIONS */
@@ -134,6 +134,13 @@
                                        config.setValue("indexDatabaseVersion", 
"6");
                        }

+                       if 
("6".equals(config.getValue("indexDatabaseVersion"))) {
+                               if (splashScreen != null)
+                                       splashScreen.setStatus("Converting 
database ...");
+                               if (convertDatabase_6_to_7(db))
+                                       config.setValue("indexDatabaseVersion", 
"7");
+                       }
+
                        /* ... */
                }

@@ -172,6 +179,7 @@
                          + "author VARCHAR(255) NULL, "
                          + "positionInTree INTEGER NOT NULL, "
                          + "revision INTEGER NOT NULL, "
+                         + "insertionDate DATE DEFAULT NULL NULL, "
                          + "newRev BOOLEAN DEFAULT FALSE NOT NULL, "
                          + "newComment BOOLEAN DEFAULT FALSE NOT NULL, "
                          + "parent INTEGER NULL, " /* direct parent */
@@ -966,4 +974,14 @@

                return true;
        }
+
+
+       public static boolean convertDatabase_6_to_7(Hsqldb db) {
+               if (!sendQuery(db, "ALTER TABLE indexes ADD COLUMN 
insertionDate DATE DEFAULT NULL NULL")) {
+                       Logger.error(new DatabaseManager(), "Error while 
converting the database (6 to 7) ! (adding column to index table)");
+                       return false;
+               }
+
+               return true;
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/DetailPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DetailPanel.java     2007-07-03 
11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DetailPanel.java     2007-07-03 
11:50:25 UTC (rev 13886)
@@ -12,6 +12,9 @@

 import java.sql.*;

+import java.text.DateFormat;
+
+
 import thaw.core.I18n;
 import thaw.core.Logger;
 import thaw.core.Config;
@@ -39,19 +42,25 @@

        private JLabel nmbFilesLabel;
        private JLabel nmbLinksLabel;
+       private JLabel insertionDateLabel;

+       private DateFormat dateFormat;

+
        public DetailPanel(FCPQueueManager queueManager, IndexBrowserPanel 
indexBrowser) {
+               this.dateFormat = DateFormat.getDateInstance();
                this.indexBrowser = indexBrowser;

                nmbFilesLabel = new 
JLabel(I18n.getMessage("thaw.plugin.index.numberOfFiles").replaceAll("\\?", 
""));
                nmbLinksLabel = new 
JLabel(I18n.getMessage("thaw.plugin.index.numberOfLinks").replaceAll("\\?", 
""));
+               insertionDateLabel = new 
JLabel(I18n.getMessage("thaw.plugin.index.insertionDate").replaceAll("\\?", 
""));

                panel = new JPanel(new BorderLayout());

-               JPanel stats = new JPanel(new GridLayout(1, 2));
+               JPanel stats = new JPanel(new GridLayout(1, 3));
                stats.add(nmbFilesLabel);
                stats.add(nmbLinksLabel);
+               stats.add(insertionDateLabel);

                panel.add(stats, BorderLayout.CENTER);

@@ -101,12 +110,36 @@
        }


+       private void setInsertionDate(Index index) {
+               if (index == null) {
+                       
insertionDateLabel.setText(I18n.getMessage("thaw.plugin.index.insertionDate").replaceAll("\\?",
 ""));
+                       return;
+               }
+
+               String dateStr = null;
+
+               java.sql.Date dateSql = index.getDate();
+
+               if (dateSql != null)
+                       dateStr = dateFormat.format(dateSql);
+
+               if (dateStr != null)
+                       
insertionDateLabel.setText(I18n.getMessage("thaw.plugin.index.insertionDate").replaceAll("\\?",
 dateStr));
+               else if (dateSql != null) {
+                       Logger.warning(this, "There is a date in the db, but 
I'm unable to print it");
+               }
+       }
+
+
        /* called by IndexBrowserPanel.setList() */
        public void setTarget(FileAndLinkList node) {
-               if (node instanceof Index)
+               if (node instanceof Index) {
                        setIndexTarget((Index)node);
-               else
+                       setInsertionDate((Index)node);
+               } else {
                        setIndexTarget(null);
+                       setInsertionDate(null);
+               }

                int nmbFilesInt = 0;
                int nmbLinksInt = 0;
@@ -165,9 +198,12 @@
                                                rs = st.executeQuery();
                                                rs.next();
                                                nmbLinksInt = rs.getInt(1);
+
                                        }

+                                       setInsertionDate(null);

+
                                } else if (node instanceof Index) {
                                        st = 
db.getConnection().prepareStatement("SELECT count(id) "+
                                                                                
 "FROM files WHERE files.indexParent = ?");
@@ -183,6 +219,9 @@
                                        rs = st.executeQuery();
                                        rs.next();
                                        nmbLinksInt = rs.getInt(1);
+
+                                       setInsertionDate((Index)node);
+
                                }

                        } catch(SQLException e) {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-07-03 11:32:40 UTC 
(rev 13885)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-07-03 11:50:25 UTC 
(rev 13886)
@@ -14,6 +14,7 @@
 import java.util.Observable;
 import java.util.Observer;
 import java.util.Vector;
+import java.util.Calendar;

 import javax.swing.JOptionPane;
 import javax.swing.tree.MutableTreeNode;
@@ -90,8 +91,8 @@
        private String displayName = null;
        private boolean hasChanged = false;
        private boolean newComment = false;
+       private java.sql.Date date = null;

-
        /* loaded only if asked explictly */
        private String realName = null;

@@ -103,6 +104,7 @@

        private Config config;

+       public final static String DATE_FORMAT = "yyyyMMdd";

        /**
         * @deprecated Just don't use it !
@@ -122,6 +124,7 @@
         */
        public Index(Hsqldb db, Config config, int id, TreeNode parentNode,
                     String publicKey, int rev, String privateKey, String 
displayName,
+                    java.sql.Date insertionDate,
                     boolean hasChanged, boolean newComment) {
                this(db, config, id);
                this.parentNode = parentNode;
@@ -129,6 +132,7 @@
                this.publicKey = publicKey;
                this.rev = rev;
                this.displayName = displayName;
+               this.date = insertionDate;
                this.hasChanged = hasChanged;
                this.newComment = newComment;
        }
@@ -365,7 +369,7 @@
                synchronized(db.dbLock) {
                        try {
                                PreparedStatement st =
-                                       
db.getConnection().prepareStatement("SELECT publicKey, revision, privateKey, 
displayName, newRev, newComment FROM indexes WHERE id = ? LIMIT 1");
+                                       
db.getConnection().prepareStatement("SELECT publicKey, revision, privateKey, 
displayName, newRev, newComment, insertionDate FROM indexes WHERE id = ? LIMIT 
1");

                                st.setInt(1, id);

@@ -378,6 +382,7 @@
                                        displayName = 
set.getString("displayName");
                                        hasChanged = set.getBoolean("newRev");
                                        newComment = 
set.getBoolean("newComment");
+                                       date = set.getDate("insertionDate");
                                        return true;
                                } else {
                                        Logger.error(this, "Unable to find 
index "+Integer.toString(id)+" in the database ?!");
@@ -400,7 +405,16 @@
                return publicKey;
        }

+       public java.sql.Date getDate() {
+               if (publicKey == null) {
+                       Logger.debug(this, "getDate() => loadData()");
+                       loadData();
+               }

+               return date;
+       }
+
+
        public boolean isObsolete() {
                return FreenetURIHelper.isObsolete(getPublicKey());
        }
@@ -876,6 +890,27 @@
                        if (((FCPClientPut)o).isFinished()) {
                                if (indexTree != null)
                                        indexTree.removeUpdatingIndex(this);
+
+                               try {
+                                       synchronized(db.dbLock) {
+                                               /* TODO : Find a nicer way */
+
+                                               PreparedStatement st;
+
+                                               Calendar cal= 
Calendar.getInstance();
+                                               java.sql.Date dateSql = new 
java.sql.Date(cal.getTime().getTime() );
+
+                                               st = 
db.getConnection().prepareStatement("UPDATE indexes "+
+                                                                               
         "SET insertionDate = ? "+
+                                                                               
         "WHERE id = ?");
+                                               st.setDate(1, dateSql);
+                                               st.setInt(2, id);
+
+                                               st.execute();
+                                       }
+                               } catch(SQLException e) {
+                                       Logger.error(this, "Error while 
updating the insertion date : "+e.toString());
+                               }
                        }
                }

@@ -1110,7 +1145,20 @@
                        header.appendChild(privateKeyEl);
                }

+               /* insertion date */
+               String dateStr;

+               java.text.SimpleDateFormat sdf =
+                       new java.text.SimpleDateFormat(DATE_FORMAT);
+               Calendar c1 = Calendar.getInstance(); // today
+               dateStr = sdf.format(c1.getTime());
+
+               final Element date = xmlDoc.createElement("date");
+               final Text dateText = xmlDoc.createTextNode(dateStr);
+               date.appendChild(dateText);
+
+               header.appendChild(date);
+
                /* TODO : Author */

                return header;
@@ -1314,10 +1362,13 @@

                private boolean ownerTag = false;
                private boolean privateKeyTag = false;
+               private boolean dateTag = false;
                private boolean commentsTag = false;

                private boolean hasCommentTag = false;

+               private String dateStr = null;
+
                private PreparedStatement insertFileSt = null;
                private PreparedStatement insertLinkSt = null;

@@ -1351,6 +1402,11 @@
                                return;
                        }

+                       if ("date".equals(rawName)) {
+                               dateTag = true;
+                               return;
+                       }
+
                        if ("index".equals(rawName)) { /* links */

                                int nextId;
@@ -1491,6 +1547,37 @@
                                return;
                        }

+                       if ("date".equals(rawName)) {
+                               dateTag = false;
+                               return;
+                       }
+
+                       if ("header".equals(rawName)) {
+                               try {
+                                       synchronized(db.dbLock) {
+                                               java.sql.Date dateSql = null;
+
+                                               if (dateStr != null) {
+                                                       
java.text.SimpleDateFormat sdf =
+                                                               new 
java.text.SimpleDateFormat(DATE_FORMAT);
+                                                       java.util.Date dateUtil 
= sdf.parse(dateStr, new java.text.ParsePosition(0));
+                                                       dateSql = new 
java.sql.Date(dateUtil.getTime());
+                                               }
+
+                                               PreparedStatement st =
+                                                       
db.getConnection().prepareStatement("UPDATE indexes "+
+                                                                               
            "SET insertionDate = ? "+
+                                                                               
            "WHERE id = ?");
+                                               st.setDate(1, dateSql);
+                                               st.setInt(2, id);
+
+                                               st.execute();
+                                       }
+                               } catch(SQLException e) {
+                                       Logger.error(this, "Error while 
updating index insertion date: "+e.toString());
+                               }
+                       }
+
                        if ("comments".equals(rawName)) {
                                commentsTag = false;
                                return;
@@ -1514,6 +1601,10 @@
                                return;
                        }

+                       if (dateTag) {
+                               dateStr = txt;
+                       }
+
                        if (privateKeyTag) {
                                if (privateKey == null || 
privateKey.trim().equals(txt.trim())) {
                                        /**
@@ -1525,12 +1616,24 @@
                                         * the provided key doesn't match with 
the one we have,
                                         * we won't publish it anymore
                                         */
-                                       Logger.notice(this, "A private key was 
provided, but didn't match with the one we have ; ignored.");
+                                       Logger.warning(this, "A private key was 
provided, but didn't match with the one we have ; ignored.");

                                }

-                               if (privateKey == null)
-                                       setPrivateKey(txt.trim());
+                               if (privateKey == null) {
+                                       String newPrivate = txt.trim();
+
+                                       /* check that nobody is trying to 
inject some FCP commands
+                                        * through the private key
+                                        */
+                                       if (!newPrivate.startsWith("SSK@")
+                                           || newPrivate.indexOf('\n') >= 0) {
+                                               Logger.warning(this, "Invalid 
private key");
+                                               return;
+                                       }
+
+                                       setPrivateKey(newPrivate);
+                               }
                                return;
                        }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java     2007-07-03 
11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java     2007-07-03 
11:50:25 UTC (rev 13886)
@@ -89,8 +89,8 @@
                                n = new Index(db, config,
                                              set.getInt("id"), this, 
set.getString("publicKey"),
                                              set.getInt("revision"), 
set.getString("privateKey"),
-                                             set.getString("displayName"), 
set.getBoolean("newRev"),
-                                             set.getBoolean("newComment"));
+                                             set.getString("displayName"), 
set.getDate("insertionDate"),
+                                             set.getBoolean("newRev"), 
set.getBoolean("newComment"));

                        int pos = set.getInt("positionInTree");

@@ -145,11 +145,11 @@


                                if (id >= 0) {
-                                       st = 
db.getConnection().prepareStatement("SELECT id, positionInTree, displayName, 
publicKey, privateKey, revision, newRev, newComment FROM indexes "
+                                       st = 
db.getConnection().prepareStatement("SELECT id, positionInTree, displayName, 
publicKey, privateKey, revision, newRev, newComment, insertionDate FROM indexes 
"
                                                                                
 + "WHERE parent = ? ORDER BY positionInTree");
                                        st.setInt(1, id);
                                } else {
-                                       st = 
db.getConnection().prepareStatement("SELECT id, positionInTree, displayName, 
publicKey, privateKey, revision, newRev, newComment FROM indexes "
+                                       st = 
db.getConnection().prepareStatement("SELECT id, positionInTree, displayName, 
publicKey, privateKey, revision, newRev, newComment, insertionDate FROM indexes 
"
                                                                                
 + "WHERE parent IS NULL ORDER BY positionInTree");
                                }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-07-03 11:32:40 UTC (rev 13885)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-07-03 11:50:25 UTC (rev 13886)
@@ -19,6 +19,7 @@
 import java.util.Observable;
 import java.util.Observer;
 import java.util.Vector;
+import java.util.Calendar;

 import javax.swing.AbstractButton;
 import javax.swing.JButton;
@@ -231,7 +232,8 @@
                                        Index index = new Index(db, 
getIndexBrowserPanel().getConfig(),
                                                                id, 
(TreeNode)getTarget(),
                                                                
sskGenerator.getPublicKey(), 0, sskGenerator.getPrivateKey(),
-                                                               name, false, 
false);
+                                                               name, null,
+                                                               false, false);

                                        
((MutableTreeNode)getTarget()).insert((index), 0);

@@ -672,7 +674,7 @@
                                index = new Index(db, indexBrowser.getConfig(),
                                                  id, parent,
                                                  publicKey, revision, 
privateKey,
-                                                 name, false, false);
+                                                 name, null, false, false);

                        } catch(SQLException e) {
                                Logger.error(new IndexManagementHelper(), 
"Error while adding index: "+e.toString());


Reply via email to