Author: jflesch
Date: 2006-12-02 19:43:20 +0000 (Sat, 02 Dec 2006)
New Revision: 11198
Modified:
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
trunk/apps/Thaw/src/thaw/plugins/index/File.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
Log:
Allow to change the index key
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-02 19:27:37 UTC
(rev 11197)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-02 19:43:20 UTC
(rev 11198)
@@ -250,3 +250,4 @@
thaw.plugin.index.gotoIndex=Go to the corresponding index
thaw.plugin.index.addKeys=Add specific key(s)
+thaw.plugin.index.changeIndexKeys=Change the index keys
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-12-02 19:27:37 UTC
(rev 11197)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-12-02 19:43:20 UTC
(rev 11198)
@@ -223,5 +223,5 @@
thaw.plugin.index.insert=Ins?rer
-thaw.plugin.index.addAlreadyExistingIndex=Ajouter un index d?j? existant
+thaw.plugin.index.addAlreadyExistingIndex=Ajouter un index d?j? pr?sent sur
Freenet
Modified: trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java 2006-12-02 19:27:37 UTC
(rev 11197)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java 2006-12-02 19:43:20 UTC
(rev 11198)
@@ -10,7 +10,7 @@
public class IndexBrowser extends ToolbarModifier implements Plugin,
ChangeListener {
- public static final String DEFAULT_INDEX = "USK at
BXd4EqMSOR589aHNHOY-e2QjI9NHwPlJurKxcvo1hBg,HkrDarIUF79uc9fjGu0S3mbp7Qf8YeMHynKf2GQO3r0,AQABAAE/Thaw/4/Thaw.xml";
+ public static final String DEFAULT_INDEX = "USK at
G-ofLp2KlhHBNPezx~GDWDKThJ-QUxJK8c2xiF~-jwE,-55vLnqo3U1H5qmKA1LLADoYGQdk-Y3hSLxyKeUyHNc,AQABAAE/Thaw/2/Thaw.xml";
private Core core;
private Hsqldb hsqldb;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-12-02 19:27:37 UTC
(rev 11197)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-12-02 19:43:20 UTC
(rev 11198)
@@ -159,7 +159,7 @@
}
public String getPublicKey() {
- return this.publicKey;
+ return publicKey;
}
public void setPublicKey(String publicKey) {
@@ -232,7 +232,10 @@
if (publicKey != null || fileName != null) {
FCPTransferQuery trans;
- trans = queueManager.getTransfer(publicKey);
+ if (getPublicKey() == null)
+ trans = queueManager.getTransfer(getFilename());
+ else
+ trans =
queueManager.getTransfer(getPublicKey());
if (trans == null) {
trans =
queueManager.getTransferByFilename(fileName);
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-12-02 19:27:37 UTC
(rev 11197)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-12-02 19:43:20 UTC
(rev 11198)
@@ -95,29 +95,13 @@
if (displayName == null)
displayName = realName;
- if (privateKey != null)
- this.privateKey = privateKey.trim();
- else
- this.privateKey = null;
+ this.revision = revision;
- if (publicKey != null)
- this.publicKey = publicKey.trim();
- else
- this.publicKey = null;
+ this.author = author;
+ setPrivateKey(privateKey);
+ setPublicKey(publicKey);
- if (privateKey != null && publicKey != null &&
publicKey.startsWith("USK@")) {
- String[] split =
FreenetURIHelper.convertUSKtoSSK(publicKey).split("/");
- publicKey = split[0];
- }
-
- if (publicKey != null && publicKey.startsWith("USK@"))
- this.revision =
FreenetURIHelper.getUSKRevision(publicKey);
- else
- this.revision = revision;
-
- this.author = author;
-
this.treeNode.setUserObject(this);
this.setTransfer();
@@ -144,8 +128,8 @@
}
public void generateKeys() {
- publicKey = "";
- privateKey = "";
+ publicKey = null;
+ privateKey = null;
sskGenerator = new FCPGenerateSSK();
sskGenerator.addObserver(this);
@@ -176,8 +160,8 @@
st.setInt(1, this.id);
st.setString(2, this.realName);
st.setString(3, this.displayName);
- st.setString(4, this.publicKey);
- st.setString(5, this.privateKey);
+ st.setString(4, publicKey != null ? publicKey : "");
+ st.setString(5, privateKey);
st.setString(6, this.author);
st.setInt(7, 0);
@@ -208,28 +192,13 @@
Connection c = this.db.getConnection();
PreparedStatement st;
- //if(privateKey == null) {
- st = c.prepareStatement("UPDATE indexes SET
displayName = ? WHERE id = ?");
- st.setString(1, name);
- st.setInt(2, this.id);
- /*
- } else {
- st = c.prepareStatement("UPDATE indexes SET
displayName = ?, originalName = ? WHERE id = ?");
- st.setString(1, name);
- st.setString(2, name);
- st.setInt(3, this.id);
- }
- */
-
+ st = c.prepareStatement("UPDATE indexes SET displayName
= ? WHERE id = ?");
+ st.setString(1, name);
+ st.setInt(2, this.id);
st.execute();
this.displayName = name;
- /*
- if(privateKey != null)
- this.realName = name;
- */
-
} catch(SQLException e) {
Logger.error(this, "Unable to rename the index
'"+this.displayName+"' in '"+name+"', because: "+e.toString());
}
@@ -329,6 +298,11 @@
public void updateFromFreenet(int rev) {
FCPClientGet clientGet;
+ if (publicKey == null) {
+ Logger.error(this, "No public key !! Can't get the
index !");
+ return;
+ }
+
Logger.info(this, "Getting lastest version ...");
String key;
@@ -470,9 +444,9 @@
st.setString(1, this.realName);
st.setString(2, this.displayName);
- st.setString(3, this.publicKey);
+ st.setString(3, publicKey != null ? publicKey : "");
if(this.privateKey != null)
- st.setString(4, this.privateKey);
+ st.setString(4, privateKey);
else
st.setNull(4, Types.VARCHAR);
@@ -515,12 +489,38 @@
return publicKey;
}
+ /**
+ * Always set the privateKey first
+ */
+ public void setPublicKey(String key) {
+ if (key != null && !isDumbKey(key))
+ this.publicKey = key.trim();
+ else
+ this.publicKey = null;
+
+
+ if (privateKey != null && publicKey != null &&
publicKey.startsWith("USK@")) {
+ String[] split =
FreenetURIHelper.convertUSKtoSSK(publicKey).split("/");
+ publicKey = split[0];
+ }
+
+ if (publicKey != null && publicKey.startsWith("USK@"))
+ this.revision =
FreenetURIHelper.getUSKRevision(publicKey);
+ }
+
public String getPrivateKey() {
if (privateKey == null || isDumbKey(privateKey))
return null;
return privateKey;
}
+ public void setPrivateKey(String key) {
+ if (key != null && !isDumbKey(key))
+ privateKey = key.trim();
+ else
+ privateKey = null;
+ }
+
public String toString() {
String toDisp;
@@ -550,10 +550,16 @@
Logger.debug(this, "Index public key: " +publicKey);
Logger.debug(this, "Index private key: "+privateKey);
+ revision = 0;
+
if (updateWhenKeyAreAvailable) {
updateWhenKeyAreAvailable = false;
update();
}
+
+ setChanged();
+ notifyObservers();
+ return;
}
if(o == this.transfer) {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-02 19:27:37 UTC (rev 11197)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-02 19:43:20 UTC (rev 11198)
@@ -131,9 +131,8 @@
Index index = new Index(db, queueManager, -1, target, name,
name, null, null, 0, null);
index.generateKeys();
+ index.create();
- index.create(); /* TODO : To Check: can it be create without
publicKey ? */
-
tree.addToIndexCategory(target, index);
}
@@ -183,29 +182,41 @@
- public static class IndexReuser extends BasicIndexAction implements
Runnable {
+ public static class KeyAsker implements ActionListener {
private JButton okButton;
private JButton cancelButton;
private int formState;
- public IndexReuser(Hsqldb db, FCPQueueManager queueManager,
IndexTree tree, AbstractButton actionSource) {
- super(db, queueManager, tree, actionSource);
+ public KeyAsker() {
}
- public void setTarget(IndexTreeNode node) {
- super.setTarget(node);
- getActionSource().setEnabled(node == null || node
instanceof IndexCategory);
+
+ /**
+ * @return String[0] == publicKey ; String[1] == privateKey ;
public or private are null if unchanged
+ */
+ public static String[] askKeys(boolean askPrivateKey,
+ String defaultPublicKey,
+ String defaultPrivateKey) {
+ return ((new KeyAsker()).askKeysBis(askPrivateKey,
defaultPublicKey, defaultPrivateKey));
}
- protected String[] askKeys(boolean askPrivateKey) {
+ public String[] askKeysBis(boolean askPrivateKey,
+ String defaultPublicKey,
+ String defaultPrivateKey) {
formState = 0;
+ if (defaultPublicKey == null)
+ defaultPublicKey = "USK@";
+
+ if (defaultPrivateKey == null)
+ defaultPrivateKey = "SSK@";
+
JFrame frame = new
JFrame(I18n.getMessage("thaw.plugin.index.indexKey"));
frame.getContentPane().setLayout(new BorderLayout());
- JTextField publicKeyField = new JTextField("USK@");
- JTextField privateKeyField = new JTextField("SSK@");
+ JTextField publicKeyField = new
JTextField(defaultPublicKey);
+ JTextField privateKeyField = new
JTextField(defaultPrivateKey);
JPanel subPanelA = new JPanel(); /* left => labels */
JPanel subPanelB = new JPanel(); /* right => textfield
*/
@@ -262,21 +273,73 @@
else
keys[1] = null;
- if (keys[0].equals("USK@"))
+ if (keys[0] == null || keys[0].length() < 20)
return null;
- if (keys[1].equals("SSK@"))
+ if (keys[1] == null || keys[1].length() < 20)
keys[1] = null;
return keys;
}
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == okButton) {
+ formState = 1;
+ }
+
+ if (e.getSource() == cancelButton) {
+ formState = 2;
+ }
+ }
+ }
+
+ public static class IndexKeyModifier extends BasicIndexAction
implements Runnable {
+ public IndexKeyModifier(AbstractButton actionSource) {
+ super(null, null, null, actionSource);
+ }
+
+ public void setTarget(IndexTreeNode node) {
+ super.setTarget(node);
+ getActionSource().setEnabled(node != null || node
instanceof Index);
+ }
+
public void run() {
+ Index index = ((Index)getTarget());
+
+ String[] keys = KeyAsker.askKeys(true,
index.getPublicKey(), index.getPrivateKey());
+
+ if (keys == null)
+ return;
+
+ index.setPrivateKey(keys[1]);
+ index.setPublicKey(keys[0]);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == getActionSource()) {
+ Thread th = new Thread(this);
+ th.start();
+ }
+ }
+ }
+
+
+ public static class IndexReuser extends BasicIndexAction implements
Runnable {
+ public IndexReuser(Hsqldb db, FCPQueueManager queueManager,
IndexTree tree, AbstractButton actionSource) {
+ super(db, queueManager, tree, actionSource);
+ }
+
+ public void setTarget(IndexTreeNode node) {
+ super.setTarget(node);
+ getActionSource().setEnabled(node == null || node
instanceof IndexCategory);
+ }
+
+ public void run() {
String keys[];
String publicKey = null;
String privateKey = null;
- keys = askKeys(true);
+ keys = KeyAsker.askKeys(true, "USK@", "SSK@");
if (keys == null)
return;
@@ -292,14 +355,6 @@
Thread newThread = new Thread(this);
newThread.start();
}
-
- if (e.getSource() == okButton) {
- formState = 1;
- }
-
- if (e.getSource() == cancelButton) {
- formState = 2;
- }
}
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-12-02
19:27:37 UTC (rev 11197)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-12-02
19:43:20 UTC (rev 11198)
@@ -207,6 +207,10 @@
indexMenu.add(item);
indexAndFileActions.add(new
IndexManagementHelper.IndexDeleter(this, item));
+ item = new
JMenuItem(I18n.getMessage("thaw.plugin.index.changeIndexKeys"));
+ indexMenu.add(item);
+ indexAndFileActions.add(new
IndexManagementHelper.IndexKeyModifier(item));
+
item = new
JMenuItem(I18n.getMessage("thaw.plugin.index.copyPrivateKey"));
indexMenu.add(item);
indexAndFileActions.add(new
IndexManagementHelper.PrivateKeyCopier(item));