Author: batosai
Date: 2008-08-11 05:02:03 +0000 (Mon, 11 Aug 2008)
New Revision: 21741

Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
   trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
   trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
Log:
Added handling of contexts. Clients can ask for identities that are relevant in 
their context.

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-11 03:53:41 UTC 
(rev 21740)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-11 05:02:03 UTC 
(rev 21741)
@@ -5,6 +5,7 @@
  */
 package plugins.WoT;

+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;

@@ -24,6 +25,7 @@
        FreenetURI requestURI;
        Date lastChange;
        HashMap<String, String> props;
+       ArrayList<String> contexts;

        /**
         * Create an identity with the given parameters
@@ -37,6 +39,7 @@
                setRequestURI(requestURI);
                setLastChange(lastChange);
                props = new HashMap<String, String>();
+               contexts = new ArrayList<String>();
        }

        /**
@@ -100,7 +103,22 @@
                return props.get(key);
        }

-       public String removeProp(String key) {
-               return props.remove(key);
+       public void removeProp(String key, ObjectContainer db) {
+               props.remove(key);
+               db.store(props);
        }
+       
+       public void addContext(String context, ObjectContainer db) {
+               if(!contexts.contains(context)) contexts.add(context);
+               db.store(contexts);
+       }
+       
+       public boolean hasContext(String context) {
+               return contexts.contains(context);
+       }
+       
+       public void removeContext(String context, ObjectContainer db) {
+               contexts.remove(context);
+               db.store(contexts);
+       }
 }

Modified: trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityParser.java  2008-08-11 03:53:41 UTC 
(rev 21740)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityParser.java  2008-08-11 05:02:03 UTC 
(rev 21741)
@@ -74,6 +74,9 @@
                        if (elt_name.equals("prop")) {
                                identity.setProp(attrs.getValue("key"), 
attrs.getValue("value"), db);
                        }
+                       else if(elt_name.equals("context")) {
+                               identity.addContext(attrs.getValue("value"), 
db);
+                       }
                        else if (elt_name.equals("trust")) {
                                try {
                                        Identity trustee = 
wot.getIdentityByURI(new FreenetURI(attrs.getValue("uri")));

Modified: trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java     2008-08-11 03:53:41 UTC 
(rev 21740)
+++ trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java     2008-08-11 05:02:03 UTC 
(rev 21741)
@@ -89,9 +89,9 @@
                // Create the content
                Element identity = xmlDoc.createElement("identity");

+               // Properties
                Set set = props.entrySet();
                Iterator i = set.iterator();
-
                while(i.hasNext()){
                        Map.Entry<String,String> prop = (Map.Entry)i.next();
                        Element propTag = xmlDoc.createElement("prop");
@@ -100,6 +100,15 @@
                        identity.appendChild(propTag);
                }

+               // Contexts
+               Iterator i2 = contexts.iterator();
+               while(i2.hasNext()) {
+                       String context = (String)i2.next();
+                       Element contextTag = xmlDoc.createElement("context");
+                       contextTag.setAttribute("value", context);
+                       identity.appendChild(contextTag);                       
+               }
+               
                rootElement.appendChild(identity);

                if(getProp("publishTrustList").equals("true")) {


Reply via email to