Author: batosai
Date: 2008-08-13 10:54:51 +0000 (Wed, 13 Aug 2008)
New Revision: 21786

Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
Log:
Comments.

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-13 10:25:52 UTC 
(rev 21785)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-13 10:54:51 UTC 
(rev 21786)
@@ -16,7 +16,7 @@
 import freenet.keys.FreenetURI;

 /**
- * An identity as handled by the WoT (a SSK)
+ * An identity as handled by the WoT (a USK)
  * 
  * @author Julien Cornuwel (batosai at freenetproject.org)
  *
@@ -31,6 +31,14 @@
        HashMap<String, String> props;
        ArrayList<String> contexts;

+       /**
+        * Creates an identity from given parameters.
+        * @param requestURI A string representing a USK or a SSK
+        * @param lastChange Date of the last update
+        * @param nickName A short name representing this identity 
+        * @param publishTrustList Whether this identity publishes its 
trustList or not
+        * @throws InvalidParameterException if a parameter doesn't pass checks 
+        */
        public Identity (String requestURI, Date lastChange, String nickName, 
String publishTrustList) throws InvalidParameterException {

                setRequestURI(requestURI);
@@ -41,6 +49,12 @@
                contexts = new ArrayList<String>();
        }

+       /**
+        * Finds the score of an identity in the database.
+        * @param treeOwner
+        * @param db
+        * @return
+        */
        public Score getScore(OwnIdentity treeOwner, ObjectContainer db) {

                ObjectSet<Score> score = db.queryByExample(new Score(treeOwner, 
this, 0, 0, 0));
@@ -49,8 +63,7 @@
        }       

        /**
-        * @return A FreenetURI
-        * @throws MalformedURLException 
+        * @return The request URI to fetch this identity
         */
        public FreenetURI getRequestURI() {

@@ -58,18 +71,15 @@
                try {
                        key = new FreenetURI(requestURI+"/WoT/"+edition);
                } catch (MalformedURLException e) {
-                       // TODO Remove this as soon as the creation is checked
-                       e.printStackTrace();
+                       // Can't happen, the key is tested on creation
                        return null;
-                       // Can't happen, the key is tested on creation
                }
                return key.setMetaString(new String [] {"identity.xml"});
        }

        /**
-        * @param requestURI The RequestURI of the Identity
-        * @throws MalformedURLException 
-        * @throws InvalidParameterException 
+        * @param requestURI
+        * @throws InvalidParameterException if this isn't a valid FreenetURI
         */
        public void setRequestURI(String requestURI) throws 
InvalidParameterException {

@@ -82,6 +92,10 @@
                setRequestURI(key);
        }

+       /**
+        * @param key
+        * @throws InvalidParameterException if this isn't a SSK or a USK
+        */
        public void setRequestURI(FreenetURI key) throws 
InvalidParameterException {

                if(key.getKeyType().equals("SSK")) key = key.setKeyType("USK");
@@ -92,16 +106,22 @@
                this.requestURI = key.toString().substring(0, 
key.toString().indexOf("/"));
        }

+       /**
+        * @return Current edition of this identity
+        */
        public long getEdition() {
                return edition;
        }

+       /**
+        * @param edition
+        */
        public void setEdition(long edition) {
                this.edition = edition;
        }

        /**
-        * @return lastChange
+        * @return lastChange Date of the Identity's last update
         */
        public Date getLastChange() {
                return lastChange;
@@ -114,10 +134,18 @@
                this.lastChange = lastChange;

        }
+       
+       /**
+        * @return The nickname of this identity 
+        */
        public String getNickName() {
                return nickName;
        }

+       /**
+        * @param nickName
+        * @throws InvalidParameterException if the nickname is blank or too 
long
+        */
        public void setNickName(String nickName) throws 
InvalidParameterException {
                String nick = nickName.trim();
                if(nick.length() == 0) throw new 
InvalidParameterException("Blank nickName");
@@ -125,43 +153,87 @@
                this.nickName = nick;
        }

+       /**
+        * 
+        * @return Whether this identity publishes its trustList or not
+        */
        public boolean doesPublishTrustList() {
                return publishTrustList;
        }

+       /**
+        * Sets publishTrustList from a string (as given by forms and FCP)
+        * @param publishTrustList
+        */
        public void setPublishTrustList(String publishTrustList) {
                setPublishTrustList(publishTrustList.equals("true"));
        }

+       /**
+        * @param publishTrustList
+        */
        public void setPublishTrustList(boolean publishTrustList) {
                this.publishTrustList = publishTrustList;
        }

+       /**
+        * Creates or updates a property
+        * @param key
+        * @param value
+        * @param db
+        * @throws InvalidParameterException if the key or value is blank
+        */
        public void setProp(String key, String value, ObjectContainer db) 
throws InvalidParameterException {
-               if(key.length() == 0 || value.length() == 0) throw new 
InvalidParameterException("Blank key or value in this property");
-               props.put(key, value);
+               if(key.trim().length() == 0 || value.trim().length() == 0) 
throw new InvalidParameterException("Blank key or value in this property");
+               props.put(key.trim(), value.trim());
                db.store(props);
        }

+       /**
+        * Gets the property value or null if the property doesn't exist
+        * @param key
+        * @return
+        */
        public String getProp(String key) {
                return props.get(key);
        }

+       /**
+        * Removes a property from the list. Does nothing if it didn't exist.
+        * @param key
+        * @param db
+        */
        public void removeProp(String key, ObjectContainer db) {
-               props.remove(key);
+               props.remove(key.trim());
                db.store(props);
        }

+       /**
+        * Adds a context to this identity.
+        * @param context
+        * @param db
+        * @throws InvalidParameterException if the context is blank
+        */
        public void addContext(String context, ObjectContainer db) throws 
InvalidParameterException {
                if(context.length() == 0) throw new 
InvalidParameterException("Blank context");
                if(!contexts.contains(context)) contexts.add(context);
                db.store(contexts);
        }

+       /**
+        * Check if this identity is usable for a particular context or not.
+        * @param context
+        * @return
+        */
        public boolean hasContext(String context) {
-               return contexts.contains(context);
+               return contexts.contains(context.trim());
        }

+       /**
+        * Removes a context from this identity
+        * @param context
+        * @param db
+        */
        public void removeContext(String context, ObjectContainer db) {
                contexts.remove(context);
                db.store(contexts);


Reply via email to