Author: toad
Date: 2008-01-16 18:33:18 +0000 (Wed, 16 Jan 2008)
New Revision: 17077

Modified:
   trunk/plugins/XMLLibrarian/XMLLibrarian.java
Log:
13: Link to the sub-index if possible

Modified: trunk/plugins/XMLLibrarian/XMLLibrarian.java
===================================================================
--- trunk/plugins/XMLLibrarian/XMLLibrarian.java        2008-01-16 18:02:38 UTC 
(rev 17076)
+++ trunk/plugins/XMLLibrarian/XMLLibrarian.java        2008-01-16 18:33:18 UTC 
(rev 17077)
@@ -7,6 +7,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
@@ -78,7 +79,7 @@
         * Current configuration gets saved by default in the configfile.
         * To Save the current configuration use "Save Configuration"
         */
-       private int version = 12;
+       private int version = 13;
        private String configfile = "XMLLibrarian.xml";
        private  String DEFAULT_FILE = "index.xml";
        boolean goon = true;
@@ -561,6 +562,7 @@
                        out.append("Give a valid string to search\n");
                        return;
                }
+               String searchWord = null;
                try {
                        out.append("<p><span 
class=\"librarian-searching-for-header\">Searching: </span><span 
class=\"librarian-searching-for-target\">").append(HTMLEncoder.encode(search)).append("</span></p>\n");
                        // Get search result
@@ -577,6 +579,7 @@
                        */
                        try{
                                for(int i = 0;i<searchWords.length;i++){
+                                       searchWord = searchWords[i];
                                        keyuris = getIndex(searchWords[i]);
                                        if(i == 0){
                                                synchronized(hs){
@@ -608,7 +611,15 @@
                                        }
                                }
                        } catch (FetchException e) {
-                               out.append("<p>Could not fetch sub-index for 
"+HTMLEncoder.encode(search)+" : "+e.getMessage()+"</p>\n");
+                               FreenetURI uri = getSubIndex(searchWord);
+                               String href = "";
+                               String endHref = "";
+                               if(uri != null) {
+                                       String encoded = 
HTMLEncoder.encode(uri.toString());
+                                       href="<a href=\"/" + encoded;
+                                       endHref = "";
+                               }
+                               out.append("<p>Could not fetch 
"+href+"sub-index"+endHref+" for "+HTMLEncoder.encode(search)+" : 
"+e.getMessage()+"</p>\n");
                                Logger.normal(this, "<p>Could not fetch 
sub-index for "+HTMLEncoder.encode(search)+" in 
"+HTMLEncoder.encode(indexuri)+" : "+e.toString()+"</p>\n", e);
                        } catch(Exception e) {
                                out.append("<p>Could not complete search for 
"+HTMLEncoder.encode(search) +" : "+e.toString()+"</p>\n");
@@ -663,6 +674,17 @@
                else return false;
        }

+       private FreenetURI getSubIndex(String word) {
+               if(word == null) return null;
+               try {
+                       return new FreenetURI(DEFAULT_INDEX_SITE + 
"index_"+searchStr(word)+".xml");
+               } catch (MalformedURLException e) {
+                       return null;
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+       
        /*
         * gets the index for the given word
         */


Reply via email to