Author: jflesch
Date: 2008-02-06 23:05:55 +0000 (Wed, 06 Feb 2008)
New Revision: 17619
Modified:
trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
Log:
Signatures : allow import/export of the trust list (not compatible with frost !)
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java 2008-02-06
22:57:10 UTC (rev 17618)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java 2008-02-06
23:05:55 UTC (rev 17619)
@@ -127,7 +127,7 @@
}
- public Element getXMLHeader(final Document xmlDoc) {
+ private Element getXMLHeader(final Document xmlDoc) {
final Element header = xmlDoc.createElement("header");
final Element title = xmlDoc.createElement("title");
@@ -182,7 +182,7 @@
}
- public Element getXMLLinks(final Document xmlDoc) {
+ private Element getXMLLinks(final Document xmlDoc) {
final Element linksEl = xmlDoc.createElement("indexes");
LinkContainer[] links = index.getLinkList();
@@ -203,7 +203,7 @@
}
- public Element getXMLFileList(final Document xmlDoc) {
+ private Element getXMLFileList(final Document xmlDoc) {
final Element filesEl = xmlDoc.createElement("files");
FileContainer[] files = index.getFileList();
@@ -242,7 +242,7 @@
}
- public Element getXMLCommentInfos(final Document xmlDoc) {
+ private Element getXMLCommentInfos(final Document xmlDoc) {
final Element infos = xmlDoc.createElement("comments");
infos.setAttribute("publicKey", index.getCommentPublicKey());
@@ -264,7 +264,7 @@
}
- /*********** INDEX LOADING **************/
+ /**************************** INDEX LOADING
*******************************/
public void loadXML(final String filePath) {
@@ -273,7 +273,7 @@
/**
- * @param clean if set to false, will do a merge
+ * @param clean if set to false, will do a merge (won't call
purgeIndex())
*/
public void loadXML(final String filePath, boolean clean) {
try {
@@ -289,7 +289,7 @@
}
- public class IndexHandler extends DefaultHandler {
+ protected class IndexHandler extends DefaultHandler {
private boolean clean = true;
public IndexHandler() {
@@ -301,12 +301,6 @@
}
/**
- * @see
org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
- */
- public void setDocumentLocator(Locator value) {
- }
-
- /**
* Called when parsing is started
* @see org.xml.sax.ContentHandler#startDocument()
*/
@@ -315,26 +309,6 @@
index.purgeIndex();
}
- /**
- * Called when starting to parse in a specific name space
- * @param prefix name space prefix
- * @param URI name space URI
- * @see
org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
java.lang.String)
- */
- public void startPrefixMapping(String prefix, String URI)
throws SAXException {
- /* \_o< */
- }
-
- /**
- * @param prefix name space prefix
- * @see
org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
- */
- public void endPrefixMapping(String prefix) throws SAXException
{
- /* \_o< */
- }
-
-
-
private boolean ownerTag = false;
private boolean privateKeyTag = false;
private boolean dateTag = false;
@@ -538,23 +512,7 @@
}
- public void ignorableWhitespace(char[] ch, int start, int end)
throws SAXException {
-
- }
-
- public void processingInstruction(String target, String data)
throws SAXException {
-
- }
-
/**
- * @see
org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
- */
- public void skippedEntity(String arg0) throws SAXException {
-
- }
-
-
- /**
* Called when parsing is finished
* @see org.xml.sax.ContentHandler#endDocument()
*/
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2008-02-06
22:57:10 UTC (rev 17618)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2008-02-06
23:05:55 UTC (rev 17619)
@@ -124,7 +124,14 @@
hash = frostCrypt.digest(publicKey);
}
+
+ protected void setDb(Hsqldb db) {
+ this.db = db;
+ }
+ protected void setId(int id) {
+ this.id = id;
+ }
private static void initFrostCrypt() {
if (frostCrypt == null)
@@ -611,7 +618,11 @@
return current;
}
-
+ /**
+ * Frost format
+ * @param file
+ * @return
+ */
public boolean exportIdentity(File file) {
Document doc = XMLTools.createDomDocument();
@@ -621,7 +632,9 @@
identityEl.appendChild(makeCDATA(doc, "name", toString()));
identityEl.appendChild(makeCDATA(doc, "key", publicKey));
- identityEl.appendChild(makeCDATA(doc, "privKey", privateKey));
+
+ if (privateKey != null)
+ identityEl.appendChild(makeCDATA(doc, "privKey",
privateKey));
root.appendChild(identityEl);
doc.appendChild(root);
@@ -656,19 +669,26 @@
return null;
}
-
- public static Identity importIdentity(Hsqldb db, File file) {
+ /**
+ * Frost format
+ * @param db
+ * @param file
+ * @return Vector<Identity>
+ */
+ public static Vector importIdentity(Hsqldb db, File file) {
+ Vector ids = new Vector();
+
try {
Document doc = null;
try {
doc = XMLTools.parseXmlFile(file, false);
} catch(Exception ex) { // xml format error
- Logger.warning(ex, "Invalid Xml");
+ Logger.error(ex, "Invalid Xml");
return null;
}
if( doc == null ) {
- Logger.warning(null,
+ Logger.error(null,
"Error: couldn't parse XML
Document - " +
"File name: '" + file.getName()
+ "'");
return null;
@@ -680,7 +700,7 @@
if (l == null) {
Logger.error(null, "No identity to import");
- return null;
+ return ids;
}
for (Iterator it = l.iterator();
@@ -697,6 +717,8 @@
publicKey,
privateKey, false,
10);
identity.insert();
+
+ ids.add(identity);
}
} catch(Exception e) {
@@ -706,7 +728,7 @@
return null;
}
- return null;
+ return ids;
}
public boolean equals(Object o) {
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2008-02-06 22:57:10 UTC (rev 17618)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2008-02-06 23:05:55 UTC (rev 17619)
@@ -400,6 +400,10 @@
final TableModelEvent event = new TableModelEvent(this);
fireTableChanged(event);
}
+
+ public Vector getIdentities() {
+ return identities;
+ }
public int getRowCount() {
if (identities == null)
@@ -470,7 +474,7 @@
}
- protected class OtherIdentitiesPanel implements ActionListener {
+ protected class OtherIdentitiesPanel implements ActionListener,
TrustListParser.TrustListContainer {
private JDialog dialog;
private IdentityModel model;
@@ -566,9 +570,37 @@
public void actionPerformed(ActionEvent e) {
if (e.getSource() == close) {
+
dialog.setVisible(false);
dialog.dispose();
return;
+
+ } else if (e.getSource() == exportButton) {
+
+ FileChooser chooser = new
FileChooser(I18n.getMessage("thaw.plugin.signature.trustList.export.long"));
+ chooser.setDirectoryOnly(false);
+
chooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
+
+ File file = chooser.askOneFile();
+
+
TrustListParser.exportTrustList(model.getIdentities(), file);
+
+ return;
+
+ } else if (e.getSource() == importButton) {
+
+ FileChooser chooser = new
FileChooser(I18n.getMessage("thaw.plugin.signature.trustList.import.long"));
+ chooser.setDirectoryOnly(false);
+
chooser.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
+
+ File file = chooser.askOneFile();
+
+ synchronized(db.dbLock) {
+ TrustListParser.importTrustList(this,
file);
+ updateList();
+ }
+
+ return;
}
int[] rows = table.getSelectedRows();
@@ -590,10 +622,6 @@
updateList();
- } else if (e.getSource() == exportButton) {
-
- } else if (e.getSource() == importButton) {
-
} else if (e.getSource() instanceof JButton) {
JButton bt = (JButton)e.getSource();
@@ -603,6 +631,14 @@
}
}
}
+
+ /**
+ * called back by the trust list parser when importing
+ */
+ public void updateIdentity(Identity importedId) {
+ Identity id = Identity.getIdentity(db,
importedId.getNick(), importedId.getPublicKey(), true /* create if doesn't
exist */);
+ id.setTrustLevel(importedId.getTrustLevel());
+ }
}