Author: batosai
Date: 2008-08-11 00:47:51 +0000 (Mon, 11 Aug 2008)
New Revision: 21728
Modified:
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Form refactor.
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-11 00:21:02 UTC
(rev 21727)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-11 00:47:51 UTC
(rev 21728)
@@ -169,15 +169,7 @@
private String makeKnownIdentitiesPage(String owner) {
Identity treeOwner = null;
- if(!owner.equals("")) {
- try {
- treeOwner = wot.getIdentityByURI(new
FreenetURI(owner));
- if(treeOwner == null) return "Unknown URI";
- } catch (MalformedURLException e) {
- return e.getLocalizedMessage();
- }
- }
-
+
HTMLNode pageNode = getPageNode();
HTMLNode contentNode = pm.getContentNode(pageNode);
@@ -195,79 +187,96 @@
HTMLNode listBox = pm.getInfobox("Known Identities");
HTMLNode listBoxContent = pm.getContentNode(listBox);
- // Form to select the tree owner (if selected, give the ability
to set trusts and display score)
- HTMLNode selectForm = pr.addFormChild(listBoxContent, SELF_URI
+ "/viewTree", "selectForm");
- HTMLNode selectBox = selectForm.addChild("select", "name",
"ownerURI");
+ int nbOwnIdentities = wot.getNbOwnIdentities();
- ObjectSet<OwnIdentity> ownIdentities =
db.queryByExample(OwnIdentity.class);
- while(ownIdentities.hasNext()) {
- OwnIdentity ownIdentity = ownIdentities.next();
- if(ownIdentity == treeOwner) {
- selectBox.addChild("option", new String []
{"value", "selected"}, new String [] {ownIdentity.getRequestURI().toString(),
"selected"}, ownIdentity.getProp("nickName"));
+ if (nbOwnIdentities == 0) {
+ listBoxContent.addChild("p", "You should create an
identity first...");
+ contentNode.addChild(listBox);
+ return pageNode.generate();
+ }
+ else if (nbOwnIdentities == 1) {
+ treeOwner = (OwnIdentity)
db.queryByExample(OwnIdentity.class).next();
+ }
+ else {
+ // Get the identity the user asked for, or the first
one if he didn't
+ if(owner.equals("")) {
+ treeOwner = (OwnIdentity)
db.queryByExample(OwnIdentity.class).next();
}
else {
- selectBox.addChild("option", "value",
ownIdentity.getRequestURI().toString(), ownIdentity.getProp("nickName"));
+ try {
+ treeOwner = wot.getIdentityByURI(new
FreenetURI(owner));
+ if(treeOwner == null) return "Unknown
URI";
+ } catch (MalformedURLException e) {
+ return e.getLocalizedMessage();
+ }
}
+
+ // Display a form to select the tree owner
+ HTMLNode selectForm = pr.addFormChild(listBoxContent,
SELF_URI + "/viewTree", "selectForm");
+ HTMLNode selectBox = selectForm.addChild("select",
"name", "ownerURI");
+
+ ObjectSet<OwnIdentity> ownIdentities =
db.queryByExample(OwnIdentity.class);
+ while(ownIdentities.hasNext()) {
+ OwnIdentity ownIdentity = ownIdentities.next();
+ if(ownIdentity == treeOwner) {
+ selectBox.addChild("option", new String
[] {"value", "selected"}, new String []
{ownIdentity.getRequestURI().toString(), "selected"},
ownIdentity.getProp("nickName"));
+ }
+ else {
+ selectBox.addChild("option", "value",
ownIdentity.getRequestURI().toString(), ownIdentity.getProp("nickName"));
+ }
+ }
+ selectForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "submit", "select", "View this identity's Web
of Trust" });
}
- selectForm.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "select", "View this identity's Web of
Trust" });
+
// Display the list of known identities
- if(wot.getNbIdentities() == 0) { // Should never happen
- listBoxContent.addChild("p", "You know no other
identites yet, we are fetching the seedfile that contains a first set of
identities (Freenet developpers).");
- }
- else {
- HTMLNode identitiesTable =
listBoxContent.addChild("table", "border", "0");
- HTMLNode row=identitiesTable.addChild("tr");
- row.addChild("th", "NickName");
- row.addChild("th", "Last update");
- row.addChild("th", "Publish TrustList ?");
- if(treeOwner != null) {
- row.addChild("th", "Score (Rank)");
- row.addChild("th", "Trust/Comment");
- }
+ HTMLNode identitiesTable = listBoxContent.addChild("table",
"border", "0");
+ HTMLNode row=identitiesTable.addChild("tr");
+ row.addChild("th", "NickName");
+ row.addChild("th", "Last update");
+ row.addChild("th", "Publish TrustList ?");
+ row.addChild("th", "Score (Rank)");
+ row.addChild("th", "Trust/Comment");
+
+ ObjectSet<Identity> identities =
db.queryByExample(Identity.class);
+ while(identities.hasNext()) {
+ Identity id = identities.next();
- ObjectSet<Identity> identities =
db.queryByExample(Identity.class);
- while(identities.hasNext()) {
- Identity id = identities.next();
-
- if(id instanceof OwnIdentity) continue;
-
- row=identitiesTable.addChild("tr");
-
- // NickName
- row.addChild("td", new String[] {"title",
"style"}, new String[] {id.getRequestURI().toString(), "cursor: help;"},
id.getProp("nickName"));
-
- // Last Change
- row.addChild("td",
id.getLastChange().toString());
-
- // Publish TrustList
- boolean publishTrustList =
id.getProp("publishTrustList") != null &&
id.getProp("publishTrustList").equals("true");
- row.addChild("td", publishTrustList ? "Yes" :
"No");
-
- if(treeOwner != null) {
- //Score
- row.addChild("td",
String.valueOf(id.getScore((OwnIdentity)treeOwner, db).getScore())+"
("+id.getScore((OwnIdentity)treeOwner, db).getRank()+")");
-
- // Trust
- int trustValue = 0;
- String trustComment = "";
- ObjectSet<Trust> trusts =
db.queryByExample(new Trust(treeOwner, id, 0, null));
- if(trusts.hasNext()) {
- Trust trust = trusts.next();
- trustValue = trust.getValue();
- trustComment =
trust.getComment();
- }
-
- HTMLNode cell = row.addChild("td");
- HTMLNode trustForm =
pr.addFormChild(cell, SELF_URI + "/setTrust", "setTrustForm");
- trustForm.addChild("input", new
String[] { "type", "name", "value" }, new String[] { "hidden", "truster",
treeOwner.getRequestURI().toString() });
- trustForm.addChild("input", new
String[] { "type", "name", "value" }, new String[] { "hidden", "trustee",
id.getRequestURI().toString() });
- trustForm.addChild("input", new
String[] { "type", "name", "size", "value" }, new String[] { "text", "value",
"2", String.valueOf(trustValue) });
- trustForm.addChild("input", new
String[] { "type", "name", "size", "value" }, new String[] { "text", "comment",
"20", trustComment });
- trustForm.addChild("input", new
String[] { "type", "name", "value" }, new String[] { "submit", "update",
"Update !" });
- }
+ if(id instanceof OwnIdentity) continue;
+
+ row=identitiesTable.addChild("tr");
+
+ // NickName
+ row.addChild("td", new String[] {"title", "style"}, new
String[] {id.getRequestURI().toString(), "cursor: help;"},
id.getProp("nickName"));
+
+ // Last Change
+ row.addChild("td", id.getLastChange().toString());
+
+ // Publish TrustList
+ boolean publishTrustList =
id.getProp("publishTrustList") != null &&
id.getProp("publishTrustList").equals("true");
+ row.addChild("td", publishTrustList ? "Yes" : "No");
+
+ //Score
+ row.addChild("td",
String.valueOf(id.getScore((OwnIdentity)treeOwner, db).getScore())+"
("+id.getScore((OwnIdentity)treeOwner, db).getRank()+")");
+
+ // Trust
+ int trustValue = 0;
+ String trustComment = "";
+ ObjectSet<Trust> trusts = db.queryByExample(new
Trust(treeOwner, id, 0, null));
+ if(trusts.hasNext()) {
+ Trust trust = trusts.next();
+ trustValue = trust.getValue();
+ trustComment = trust.getComment();
}
- }
+
+ HTMLNode cell = row.addChild("td");
+ HTMLNode trustForm = pr.addFormChild(cell, SELF_URI +
"/setTrust", "setTrustForm");
+ trustForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "hidden", "truster",
treeOwner.getRequestURI().toString() });
+ trustForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "hidden", "trustee",
id.getRequestURI().toString() });
+ trustForm.addChild("input", new String[] { "type",
"name", "size", "value" }, new String[] { "text", "value", "2",
String.valueOf(trustValue) });
+ trustForm.addChild("input", new String[] { "type",
"name", "size", "value" }, new String[] { "text", "comment", "20", trustComment
});
+ trustForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "submit", "update", "Update !" });
+ }
contentNode.addChild(addBox);
contentNode.addChild(listBox);
return pageNode.generate();
@@ -343,19 +352,8 @@
wot.setTrust(new Trust(truster, trustee, value,
comment));
db.commit();
- String out = "";
- ObjectSet<Trust> trusts =
db.queryByExample(Trust.class);
- while (trusts.hasNext()) {
- out += trusts.next().toString() + "<br>";
- }
+ return
makeKnownIdentitiesPage(request.getPartAsString("truster", 1024));
- ObjectSet<Score> scores =
db.queryByExample(Score.class);
- while (scores.hasNext()) {
- out += scores.next().toString() + "<br>";
- }
-
- return out;
- //return
makeKnownIdentitiesPage(request.getPartAsString("truster", 1024));*/
} catch (MalformedURLException e) {
return e.getLocalizedMessage();
}
@@ -365,8 +363,6 @@
try {
FreenetURI uri = new
FreenetURI(request.getPartAsString("identityURI", 1024));
-
- // FIXME For some reason, the result is always null. So
we re-create existing identities :(
Identity identity = wot.getIdentityByURI(uri);
if(identity == null) {