Author: batosai
Date: 2008-08-13 15:15:36 +0000 (Wed, 13 Aug 2008)
New Revision: 21814
Added:
trunk/apps/WoT/src/plugins/WoT/NotInTrustTreeException.java
Modified:
trunk/apps/WoT/src/plugins/WoT/Identity.java
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Refactor.
Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-08-13 15:00:52 UTC
(rev 21813)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-08-13 15:15:36 UTC
(rev 21814)
@@ -54,12 +54,14 @@
* @param treeOwner
* @param db
* @return
+ * @throws NotInTrustTreeException
+ * @throws
*/
- public Score getScore(OwnIdentity treeOwner, ObjectContainer db) {
+ public Score getScore(OwnIdentity treeOwner, ObjectContainer db) throws
NotInTrustTreeException {
ObjectSet<Score> score = db.queryByExample(new Score(treeOwner,
this, 0, 0, 0));
if(score.hasNext()) return score.next();
- else return new Score(treeOwner, this, 0, -1, 0);
+ else throw new
NotInTrustTreeException(this.getRequestURI().toString()+" is not in that trust
tree");
}
public Trust getTrust(Identity truster, ObjectContainer db) throws
InvalidParameterException {
Added: trunk/apps/WoT/src/plugins/WoT/NotInTrustTreeException.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/NotInTrustTreeException.java
(rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/NotInTrustTreeException.java 2008-08-13
15:15:36 UTC (rev 21814)
@@ -0,0 +1,20 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ *
+ */
+public class NotInTrustTreeException extends Exception {
+
+ private static final long serialVersionUID = -1;
+
+ public NotInTrustTreeException(String message) {
+ super(message);
+ }
+
+}
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-13 15:00:52 UTC
(rev 21813)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-13 15:15:36 UTC
(rev 21814)
@@ -168,11 +168,11 @@
return pageNode.generate();
}
- private String makeKnownIdentitiesPage() throws Db4oIOException,
DatabaseClosedException, InvalidParameterException {
+ private String makeKnownIdentitiesPage() throws Db4oIOException,
DatabaseClosedException, InvalidParameterException, NotInTrustTreeException {
return makeKnownIdentitiesPage("");
}
- private String makeKnownIdentitiesPage(String owner) throws
Db4oIOException, DatabaseClosedException, InvalidParameterException {
+ private String makeKnownIdentitiesPage(String owner) throws
Db4oIOException, DatabaseClosedException, InvalidParameterException,
NotInTrustTreeException {
Identity treeOwner = null;
@@ -541,9 +541,15 @@
sfs.putAppend("Trust", "null");
}
- Score score = identity.getScore(treeOwner, db);
- sfs.putAppend("Score", String.valueOf(score.getScore()));
- sfs.putAppend("Rank", String.valueOf(score.getRank()));
+ Score score;
+ try {
+ score = identity.getScore(treeOwner, db);
+ sfs.putAppend("Score",
String.valueOf(score.getScore()));
+ sfs.putAppend("Rank", String.valueOf(score.getRank()));
+ } catch (NotInTrustTreeException e) {
+ sfs.putAppend("Score", "null");
+ sfs.putAppend("Rank", "null");
+ }
return sfs;
}