[freenet-cvs] r17002 - in branches/legacy/stable/src/freenet/node/http: . infolets

jolantern at freenetproject.org jolantern at freenetproject.org
Thu Jan 10 21:52:30 UTC 2008


Author: jolantern
Date: 2008-01-10 21:52:29 +0000 (Thu, 10 Jan 2008)
New Revision: 17002

Modified:
   branches/legacy/stable/src/freenet/node/http/BookmarkManagerServlet.java
   branches/legacy/stable/src/freenet/node/http/infolets/DefaultInfolet.java
Log:
* src/freenet/node/http/infolets/DefaultInfolet.java,
  src/freenet/node/http/BookmarkManagerServlet.java:
- bookmarks: got rid of null pointers, default entries for title and
  descriptions, more user-friendly diagnostics.


Modified: branches/legacy/stable/src/freenet/node/http/BookmarkManagerServlet.java
===================================================================
--- branches/legacy/stable/src/freenet/node/http/BookmarkManagerServlet.java	2008-01-10 21:19:19 UTC (rev 17001)
+++ branches/legacy/stable/src/freenet/node/http/BookmarkManagerServlet.java	2008-01-10 21:52:29 UTC (rev 17002)
@@ -642,7 +642,7 @@
 				String description = bookmark.getDescription();
 			
 				String activelink = null;
-				if (activelinkFile != null) { 
+				if (!activelinkFile.equals("")) {
 					if (key.endsWith("/"))
 						activelink = key + activelinkFile;
 					else if (key.indexOf('/') > 0) 
@@ -812,8 +812,8 @@
 		String activelinkFile = bookmark.getActivelinkFile();
 		String description = bookmark.getDescription();
 			
-		String activelink = null;
-		if (activelinkFile != null) { 
+		String activelink = "";
+		if (!activelinkFile.equals("")) { 
 			if (key.endsWith("/"))
 				activelink = key + activelinkFile;
 			else if (key.indexOf('/') > 0) 
@@ -821,12 +821,15 @@
 		}
 		
 		StringBuffer buf = new StringBuffer();
-		buf
-			.append("<a href=\"/")
-			.append(key)
-			.append("\">");
-		if (activelink != null)
+		if (!key.equals(""))
 			buf
+				.append("<a href=\"/")
+				.append(key)
+				.append("\">");
+		else
+			buf.append("key missing");
+		if (!activelink.equals(""))
+			buf
 				.append("<img src=\"/")
 				.append(activelink)
 				.append("\" alt=\"")
@@ -1001,7 +1004,7 @@
 	}
 	
 	protected boolean safeLink(String s) {
-		return (s == null) || ((s.indexOf('\n') < 0) && (s.indexOf('\r') < 0) && (s.indexOf(':') < 0) && (s.indexOf('<') < 0));
+		return (s.indexOf('\n') < 0) && (s.indexOf('\r') < 0) && (s.indexOf(':') < 0) && (s.indexOf('<') < 0);
 	}
 
 	/**
@@ -1030,8 +1033,6 @@
 
 		public void setKey(String key) {
 			this.key = clean(key);
-			if (this.key.equals(""))
-				this.key = "key missing";
 		}
 
 		public String getTitle() {
@@ -1046,7 +1047,7 @@
 
 		/**
 		 * Obtain path to active link picture relative to site.
-		 * When this method returns null, no link should be displayed.
+		 * When this method returns an empty string, no link should be displayed.
 		 */
 
 		public String getActivelinkFile() {
@@ -1055,8 +1056,6 @@
 
 		public void setActivelinkFile(String file) {
 			activelink = clean(file);
-			if (activelink.equals(""))
-				activelink = null;
 		}
 
 		public String getDescription() {
@@ -1074,6 +1073,8 @@
 				string = string.replace('\n', ' ');
 				string = string.replace('=', ' ');
 			}
+			else
+				string = "";
 			return string;
 		}
 

Modified: branches/legacy/stable/src/freenet/node/http/infolets/DefaultInfolet.java
===================================================================
--- branches/legacy/stable/src/freenet/node/http/infolets/DefaultInfolet.java	2008-01-10 21:19:19 UTC (rev 17001)
+++ branches/legacy/stable/src/freenet/node/http/infolets/DefaultInfolet.java	2008-01-10 21:52:29 UTC (rev 17002)
@@ -261,8 +261,8 @@
 				String activelinkFile = bookmark.getString("activelinkFile");
 				String description = bookmark.getString("description");
 
-				String activelink = null;
-				if ((activelinkFile != null) && (activelinkFile.trim().length() > 0)) {
+				String activelink = "";
+				if (activelinkFile.trim().length() > 0) {
 					if (key.endsWith("/"))
 						activelink = key + activelinkFile;
 					else if (key.indexOf('/') > 0)
@@ -273,31 +273,38 @@
 					Core.logger.log(DefaultInfolet.class, "Found full bookmark [" + i + "]: " + key + "/" + title + "/" + activelink + "/" + description, Logger.DEBUG);
 				}
 
-				link
-					.append("<tr><td><a href=\"/")
-					.append(key)
-					.append("\">\n");
-				if (activelink != null)
+				link.append("<tr><td>");
+				if (!key.equals("")) {
 					link
-						.append("<img src=\"/")
-						.append(activelink)
-						.append("\" alt=\"")
+						.append("<a href=\"/")
+						.append(key)
+						.append("\">\n");
+					if (!activelink.equals(""))
+						link
+							.append("<img src=\"/")
+							.append(activelink)
+							.append("\" alt=\"")
+							.append(title)
+							.append("\" width=\"95\" height=\"32\" />");
+					else if (key.indexOf('/') <= 0)
+						link.append("invalid key");
+					else
+						link.append("no active link");
+					link.append("</a>");
+				}
+				link.append("</td>\n<td>");
+				if (!key.equals(""))
+					link
+						.append("<a href=\"/")
+						.append(key)
+						.append("\">")
 						.append(title)
-						.append("\" width=\"95\" height=\"32\" />");
-				link.append("</a></td>\n");
-				link
-					.append("<td><a href=\"/")
-					.append(key)
-					.append("\">")
-					.append(title)
-					.append("</a></td>\n");
-				if (description != null) {
-					link
-						.append("<td>")
-						.append(description)
-						.append("</td>\n");
-				}
-				link.append("</tr>\n");
+						.append("</a>");
+				else
+					link.append("key missing");
+				link.append("</td>\n<td>");
+				link.append(description);
+				link.append("</td></tr>\n");
 				i++;
 			}
 		}




More information about the cvs mailing list