Author: jflesch
Date: 2006-12-11 00:18:58 +0000 (Mon, 11 Dec 2006)
New Revision: 11340

Added:
   trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
Removed:
   trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java
Modified:
   trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
   trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
   trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
Log:
Fix 2 NPE

Modified: trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2006-12-10 23:58:43 UTC 
(rev 11339)
+++ trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2006-12-11 00:18:58 UTC 
(rev 11340)
@@ -11,6 +11,9 @@
         * Quick test to see if the string could be a key
         */
        public static boolean isAKey(String key) {
+               if (key == null)
+                   return false;
+
                return (key.startsWith("CHK@")
                        || key.startsWith("SSK@")
                        || key.startsWith("USK@")

Modified: trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java  2006-12-10 23:58:43 UTC 
(rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java  2006-12-11 00:18:58 UTC 
(rev 11340)
@@ -15,7 +15,7 @@
 import thaw.plugins.index.IndexBrowserPanel;
 import thaw.plugins.index.IndexManagementHelper;
 import thaw.plugins.index.IndexTreeNode;
-import thaw.plugins.index.TableCreator;
+import thaw.plugins.index.DatabaseManager;

 public class IndexBrowser extends ToolbarModifier implements Plugin, 
ChangeListener, java.util.Observer {

@@ -53,7 +53,7 @@
                newDb = false;

                if (core.getConfig().getValue("indexDatabaseVersion") == null) {
-                       TableCreator.createTables(hsqldb);
+                       DatabaseManager.createTables(hsqldb);
                        newDb = true;
                        core.getConfig().setValue("indexDatabaseVersion", "1");
                }

Copied: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java (from rev 
11311, trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java)
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java                 
        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2006-12-11 
00:18:58 UTC (rev 11340)
@@ -0,0 +1,142 @@
+package thaw.plugins.index;
+
+import java.sql.SQLException;
+
+import thaw.core.Logger;
+import thaw.plugins.Hsqldb;
+
+/**
+ * Create all the tables used to save the indexes.
+ * <br/>
+ * "Comprenne qui pourra" :P
+ *
+ * <pre>
+ * indexCategories (name, positionInTree)
+ *  |-- indexCategories (name, positionInTree)
+ *  | |-- [...]
+ *  |
+ *  |-- indexes (name, publicKey, [privateKey], positionInTree)
+ *    |-- links (indexName, indexPublicKey)
+ *    |-- files (filename, publicKey, mime, size)
+ *      |-- metadatas (name, value)
+ * </pre>
+ *
+ * positionInTree == position in its JTree branch.
+ */
+public class DatabaseManager {
+
+       public DatabaseManager() {
+
+       }
+
+       /**
+        * Can be safely called, even if the tables already exist.
+        */
+       public static void createTables(final Hsqldb db) {
+               //sendQuery(db,
+               //        "SET IGNORECASE TRUE");
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE indexCategories ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "name VARCHAR(255) NOT NULL,"
+                         + "positionInTree INTEGER NOT NULL,"
+                         + "modifiableIndexes BOOLEAN NOT NULL," /* Obsolete */
+                         + "parent INTEGER NULL,"
+                         + "PRIMARY KEY (id),"
+                         + "FOREIGN KEY (parent) REFERENCES indexCategories 
(id))");
+
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE indexes ("
+                         + "id INTEGER IDENTITY NOT NULL, "
+                         + "originalName VARCHAR(255) NOT NULL, "
+                         + "displayName VARCHAR(255) NULL, "
+                         + "publicKey VARCHAR(255) NOT NULL, "
+                         + "privateKey VARCHAR(255) NULL, "
+                         + "author VARCHAR(255) NULL, "
+                         + "positionInTree INTEGER NOT NULL, "
+                         + "revision INTEGER NOT NULL, "
+                         + "parent INTEGER NULL, "
+                         + "PRIMARY KEY (id), "
+                         + "FOREIGN KEY (parent) REFERENCES indexCategories 
(id))");
+
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE categories ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "name VARCHAR(255) NOT NULL)");
+
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE files ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "filename VARCHAR(255) NOT NULL,"
+                         + "publicKey VARCHAR(350) NOT NULL," // key ~= 100 + 
filename == 255 max => 350
+                         + "localPath VARCHAR(500) NULL,"
+                         + "mime VARCHAR(50) NULL,"
+                         + "size BIGINT NOT NULL,"
+                         + "category INTEGER NULL,"
+                         + "indexParent INTEGER NOT NULL,"
+                         + "PRIMARY KEY (id),"
+                         + "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
+                         + "FOREIGN KEY (category) REFERENCES categories 
(id))");
+
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE links ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "publicKey VARCHAR(350) NOT NULL," // key ~= 100 + 
filename == 255 max
+                         + "mark INTEGER NOT NULL,"
+                         + "comment VARCHAR(512) NOT NULL,"
+                         + "indexParent INTEGER NOT NULL,"
+                         + "indexTarget INTEGER NULL,"
+                         + "PRIMARY KEY (id),"
+                         + "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
+                         + "FOREIGN KEY (indexTarget) REFERENCES indexes 
(id))");
+
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE metadataNames ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "name VARCHAR(255) NOT NULL,"
+                         + "PRIMARY KEY (id))");
+
+               TableCreator.sendQuery(db,
+                         "CREATE CACHED TABLE metadatas ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "nameId INTEGER NOT NULL,"
+                         + "value VARCHAR(255) NOT NULL,"
+                         + "fileId INTEGER NOT NULL,"
+                         + "PRIMARY KEY (id),"
+                         + "FOREIGN KEY (fileId) REFERENCES files (id),"
+                         + "FOREIGN KEY (nameId) REFERENCES metadataNames 
(id))");
+
+       }
+
+       public static void dropTables(final Hsqldb db) {
+               TableCreator.sendQuery(db, "DROP TABLE metadatas");
+               TableCreator.sendQuery(db, "DROP TABLE metadataNames");
+
+               TableCreator.sendQuery(db, "DROP TABLE files");
+               TableCreator.sendQuery(db, "DROP TABLE links");
+
+               TableCreator.sendQuery(db, "DROP TABLE indexes");
+               TableCreator.sendQuery(db, "DROP TABLE indexCategories");
+       }
+
+
+       /**
+        * Returns no error / Throws no exception.
+        */
+       protected static void sendQuery(final Hsqldb db, final String query) {
+               try {
+                       db.executeQuery(query);
+               } catch(final SQLException e) {
+                       Logger.notice(new TableCreator(), "While (re)creating 
sql tables: "+e.toString());
+               }
+       }
+
+
+       public static void exportDatabase(IndexTree indexTree) {
+
+       }
+
+       public static void importDatabase(IndexTree indexTree) {
+
+       }
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-12-10 
23:58:43 UTC (rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-12-11 
00:18:58 UTC (rev 11340)
@@ -317,7 +317,7 @@
                        if (column == 2) {
                                String key = file.getPublicKey();

-                               if (!thaw.core.FreenetURIHelper.isAKey(key))
+                               if (key == null || 
!thaw.core.FreenetURIHelper.isAKey(key))
                                        key = 
I18n.getMessage("thaw.common.unknown");

                                return key;

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-12-10 23:58:43 UTC 
(rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-12-11 00:18:58 UTC 
(rev 11340)
@@ -1094,8 +1094,12 @@

                final Element rootEl = xmlDoc.getDocumentElement();

+               loadXMLFromRoot(rootEl);
+       }
+
+       public void loadXMLFromRoot(Element rootEl) {
                loadHeader(rootEl);
-               this.loadLinks(rootEl);
+               loadLinks(rootEl);
                loadFileList(rootEl);
        }

@@ -1209,6 +1213,12 @@
                return ids;
        }

+       public Vector getIndexes() {
+               final Vector idx = new Vector();
+               idx.add(this);
+               return idx;
+       }
+
        public boolean isModifiable() {
                return (privateKey != null);
        }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java   2006-12-10 
23:58:43 UTC (rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java   2006-12-11 
00:18:58 UTC (rev 11340)
@@ -406,7 +406,42 @@
                return result;
        }

+       public Vector getIndexes()
+       {
+               if(children == null)
+                       children = loadChildren();

+               final Vector result = new Vector();
+
+               for(final Iterator it = children.iterator();
+                   it.hasNext();) {
+                       final IndexTreeNode node = 
(IndexTreeNode)((DefaultMutableTreeNode)it.next()).getUserObject();
+                       result.addAll(node.getIndexes());
+               }
+
+               return result;
+       }
+
+       public Vector getAllIndexCategories()
+       {
+               if(children == null)
+                       children = loadChildren();
+
+               final Vector result = new Vector();
+
+               for(final Iterator it = children.iterator();
+                   it.hasNext();) {
+                       final Object node = 
((DefaultMutableTreeNode)it.next()).getUserObject();
+                       if (node instanceof IndexCategory) {
+                               result.add(node);
+                               
result.addAll(((IndexCategory)node).getAllIndexCategories());
+                       }
+               }
+
+               return result;
+       }
+
+
        public Index getIndex(final int id)
        {
                if(children == null)

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2006-12-10 23:58:43 UTC (rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2006-12-11 00:18:58 UTC (rev 11340)
@@ -101,7 +101,7 @@

        public static class IndexCreator extends BasicIndexAction {
                public IndexCreator(final FCPQueueManager queueManager, final 
IndexBrowserPanel indexBrowser, final AbstractButton actionSource) {
-                       super(null, indexBrowser, actionSource);
+                       super(queueManager, indexBrowser, actionSource);
                }

                public void setTarget(final IndexTreeNode node) {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java   2006-12-10 
23:58:43 UTC (rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java   2006-12-11 
00:18:58 UTC (rev 11340)
@@ -57,6 +57,11 @@

        public Vector getIndexIds();

+       /**
+        * All the indexes !
+        */
+       public Vector getIndexes();
+
        public Index getIndex(int id);

        public void addObserver(java.util.Observer o);

Deleted: trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java    2006-12-10 
23:58:43 UTC (rev 11339)
+++ trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java    2006-12-11 
00:18:58 UTC (rev 11340)
@@ -1,133 +0,0 @@
-package thaw.plugins.index;
-
-import java.sql.SQLException;
-
-import thaw.core.Logger;
-import thaw.plugins.Hsqldb;
-
-/**
- * Create all the tables used to save the indexes.
- * <br/>
- * "Comprenne qui pourra" :P
- *
- * <pre>
- * indexCategories (name, positionInTree)
- *  |-- indexCategories (name, positionInTree)
- *  | |-- [...]
- *  |
- *  |-- indexes (name, publicKey, [privateKey], positionInTree)
- *    |-- links (indexName, indexPublicKey)
- *    |-- files (filename, publicKey, mime, size)
- *      |-- metadatas (name, value)
- * </pre>
- *
- * positionInTree == position in its JTree branch.
- */
-public class TableCreator {
-
-       public TableCreator() {
-
-       }
-
-       /**
-        * Can be safely called, even if the tables already exist.
-        */
-       public static void createTables(final Hsqldb db) {
-               //sendQuery(db,
-               //        "SET IGNORECASE TRUE");
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE indexCategories ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "name VARCHAR(255) NOT NULL,"
-                         + "positionInTree INTEGER NOT NULL,"
-                         + "modifiableIndexes BOOLEAN NOT NULL," /* Obsolete */
-                         + "parent INTEGER NULL,"
-                         + "PRIMARY KEY (id),"
-                         + "FOREIGN KEY (parent) REFERENCES indexCategories 
(id))");
-
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE indexes ("
-                         + "id INTEGER IDENTITY NOT NULL, "
-                         + "originalName VARCHAR(255) NOT NULL, "
-                         + "displayName VARCHAR(255) NULL, "
-                         + "publicKey VARCHAR(255) NOT NULL, "
-                         + "privateKey VARCHAR(255) NULL, "
-                         + "author VARCHAR(255) NULL, "
-                         + "positionInTree INTEGER NOT NULL, "
-                         + "revision INTEGER NOT NULL, "
-                         + "parent INTEGER NULL, "
-                         + "PRIMARY KEY (id), "
-                         + "FOREIGN KEY (parent) REFERENCES indexCategories 
(id))");
-
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE categories ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "name VARCHAR(255) NOT NULL)");
-
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE files ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "filename VARCHAR(255) NOT NULL,"
-                         + "publicKey VARCHAR(350) NOT NULL," // key ~= 100 + 
filename == 255 max => 350
-                         + "localPath VARCHAR(500) NULL,"
-                         + "mime VARCHAR(50) NULL,"
-                         + "size BIGINT NOT NULL,"
-                         + "category INTEGER NULL,"
-                         + "indexParent INTEGER NOT NULL,"
-                         + "PRIMARY KEY (id),"
-                         + "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
-                         + "FOREIGN KEY (category) REFERENCES categories 
(id))");
-
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE links ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "publicKey VARCHAR(350) NOT NULL," // key ~= 100 + 
filename == 255 max
-                         + "mark INTEGER NOT NULL,"
-                         + "comment VARCHAR(512) NOT NULL,"
-                         + "indexParent INTEGER NOT NULL,"
-                         + "indexTarget INTEGER NULL,"
-                         + "PRIMARY KEY (id),"
-                         + "FOREIGN KEY (indexParent) REFERENCES indexes (id),"
-                         + "FOREIGN KEY (indexTarget) REFERENCES indexes 
(id))");
-
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE metadataNames ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "name VARCHAR(255) NOT NULL,"
-                         + "PRIMARY KEY (id))");
-
-               TableCreator.sendQuery(db,
-                         "CREATE CACHED TABLE metadatas ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "nameId INTEGER NOT NULL,"
-                         + "value VARCHAR(255) NOT NULL,"
-                         + "fileId INTEGER NOT NULL,"
-                         + "PRIMARY KEY (id),"
-                         + "FOREIGN KEY (fileId) REFERENCES files (id),"
-                         + "FOREIGN KEY (nameId) REFERENCES metadataNames 
(id))");
-
-       }
-
-       public static void dropTables(final Hsqldb db) {
-               TableCreator.sendQuery(db, "DROP TABLE metadatas");
-               TableCreator.sendQuery(db, "DROP TABLE metadataNames");
-
-               TableCreator.sendQuery(db, "DROP TABLE files");
-               TableCreator.sendQuery(db, "DROP TABLE links");
-
-               TableCreator.sendQuery(db, "DROP TABLE indexes");
-               TableCreator.sendQuery(db, "DROP TABLE indexCategories");
-       }
-
-
-       /**
-        * Returns no error / Throws no exception.
-        */
-       protected static void sendQuery(final Hsqldb db, final String query) {
-               try {
-                       db.executeQuery(query);
-               } catch(final SQLException e) {
-                       Logger.notice(new TableCreator(), "While (re)creating 
sql tables: "+e.toString());
-               }
-       }
-}


Reply via email to