Author: batosai
Date: 2008-08-12 16:08:12 +0000 (Tue, 12 Aug 2008)
New Revision: 21767

Modified:
   trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
   trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
   trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
Make the identity finding method throw if it doesn't exist.

Modified: trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-08-12 15:54:31 UTC 
(rev 21766)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-08-12 16:08:12 UTC 
(rev 21767)
@@ -62,13 +62,14 @@
        public void onFailure(FetchException e, ClientGetter state) {

                if(e.newURI != null) { // Handle redirection to a new edition
-                       Identity identity = 
wot.getIdentityByURI(state.getURI());
-                       // We just take the redirection number to avoid a nasty 
redirect loop by an attacker 
-                       
identity.setRequestURI(identity.getRequestURI().setSuggestedEdition(e.newURI.getSuggestedEdition()));
-                       db.store(identity);
                        try {
+                               Identity identity = 
wot.getIdentityByURI(state.getURI());
+                               // We just take the redirection number to avoid 
a nasty redirect loop by an attacker 
+                               
identity.setRequestURI(identity.getRequestURI().setSuggestedEdition(e.newURI.getSuggestedEdition()));
+                               db.store(identity);
+
                                fetch(identity);
-                       } catch (FetchException e2) {
+                       } catch (Exception e2) {
                                System.out.print(e2.getLocalizedMessage());
                        }
                }
@@ -102,9 +103,11 @@
        public void onSuccess(FetchResult result, ClientGetter state) {

                // Find the identity we just fetched
-               Identity identity = wot.getIdentityByURI(state.getURI());
-               if (identity == null) { // This should never happen but...
-                       System.out.println("Error, identity not found");
+               Identity identity;
+               try {
+                       identity = wot.getIdentityByURI(state.getURI());
+               } catch (Exception e) {
+                       e.printStackTrace();
                        return;
                }


Modified: trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityParser.java  2008-08-12 15:54:31 UTC 
(rev 21766)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityParser.java  2008-08-12 16:08:12 UTC 
(rev 21767)
@@ -89,10 +89,8 @@
                                        String comment = 
attrs.getValue("comment");

                                        wot.setTrust(new Trust(identity, 
trustee, value, comment));                                     
-                               } catch (MalformedURLException e) {
+                               } catch (Exception e) {
                                        
System.out.println(e.getLocalizedMessage());
-                               } catch (FetchException e) {
-                                       
System.out.println(e.getLocalizedMessage());
                                }
                        }
                }

Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-08-12 15:54:31 UTC (rev 
21766)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-08-12 16:08:12 UTC (rev 
21767)
@@ -169,7 +169,7 @@
                return identities.size() - getNbOwnIdentities();
        }

-       public Identity getIdentityByURI(FreenetURI uri) {
+       public Identity getIdentityByURI(FreenetURI uri) throws Exception {

                String searched = uri.toString().substring(0, 
uri.toString().indexOf("/"));
                Identity identity = null;
@@ -184,6 +184,8 @@
                                break;
                        }
                }
+               if(identity==null) throw new Exception("Identity doesn't exist 
: "+uri.toString());
+               
                return identity;
        }
 }


Reply via email to