Author: j16sdiz
Date: 2009-03-02 15:16:27 +0000 (Mon, 02 Mar 2009)
New Revision: 25871

Added:
   trunk/plugins/XMLLibrarian/Util.java
Modified:
   trunk/plugins/XMLLibrarian/XMLLibrarian.java
Log:
Move fetchBucket() to Util class

Added: trunk/plugins/XMLLibrarian/Util.java
===================================================================
--- trunk/plugins/XMLLibrarian/Util.java                                (rev 0)
+++ trunk/plugins/XMLLibrarian/Util.java        2009-03-02 15:16:27 UTC (rev 
25871)
@@ -0,0 +1,46 @@
+package plugins.XMLLibrarian;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import freenet.client.FetchException;
+import freenet.client.FetchResult;
+import freenet.client.HighLevelSimpleClient;
+import freenet.keys.FreenetURI;
+import freenet.pluginmanager.PluginRespirator;
+import freenet.support.api.Bucket;
+import freenet.support.io.FileBucket;
+
+/**
+ * Utility class
+ * 
+ * @author  j16sdiz (1024D/75494252)
+ */
+public class Util {
+       public static Bucket fetchBucket(String uri, PluginRespirator 
pluginRespirator) throws FetchException, MalformedURLException {
+               // try local file first
+               File file = new File(uri);
+               if (file.exists() && file.canRead()) 
+                       return new FileBucket(file, true, false, false, false, 
false);
+
+               // FreenetURI, try to fetch from freenet
+               HighLevelSimpleClient hlsc = 
pluginRespirator.getHLSimpleClient();
+               FreenetURI u = new FreenetURI(uri);
+               FetchResult res;
+               while (true) {
+                       try {
+                               res = hlsc.fetch(u);
+                               break;
+                       } catch (FetchException e) {
+                               if (e.newURI != null) {
+                                       u = e.newURI;
+                                       continue;
+                               } else
+                                       throw e;
+                       }
+               }
+
+               return res.asBucket();
+       }
+
+}


Property changes on: trunk/plugins/XMLLibrarian/Util.java
___________________________________________________________________
Added: svn:mime-type
   + text/x-java
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: trunk/plugins/XMLLibrarian/XMLLibrarian.java
===================================================================
--- trunk/plugins/XMLLibrarian/XMLLibrarian.java        2009-03-02 12:44:00 UTC 
(rev 25870)
+++ trunk/plugins/XMLLibrarian/XMLLibrarian.java        2009-03-02 15:16:27 UTC 
(rev 25871)
@@ -14,8 +14,6 @@
 import javax.xml.parsers.SAXParserFactory;
 
 import freenet.client.FetchException;
-import freenet.client.FetchResult;
-import freenet.client.HighLevelSimpleClient;
 import freenet.keys.FreenetURI;
 import freenet.pluginmanager.FredPlugin;
 import freenet.pluginmanager.FredPluginHTTP;
@@ -27,7 +25,6 @@
 import freenet.support.Logger;
 import freenet.support.api.Bucket;
 import freenet.support.api.HTTPRequest;
-import freenet.support.io.FileBucket;
 
 /**
  * XMLLibrarian is a modified version of the old librarian. It uses the Xml 
index files for
@@ -285,33 +282,7 @@
                return index;
        }
 
-       private Bucket fetchBucket(String uri) throws FetchException, 
MalformedURLException {
-               // File
-               File file = new File(uri);
-               if (file.exists() && file.canRead()) {
-                       return new FileBucket(file, true, false, false, false, 
false);
-               }
-
-               // FreenetURI
-               HighLevelSimpleClient hlsc = pr.getHLSimpleClient();
-               FreenetURI u = new FreenetURI(uri);
-               FetchResult res;
-               while (true) {
-                       try {
-                               res = hlsc.fetch(u);
-                               break;
-                       } catch (FetchException e) {
-                               if (e.newURI != null) {
-                                       u = e.newURI;
-                                       continue;
-                               } else
-                                       throw e;
-                       }
-               }
-
-               return res.asBucket();
-       }
-
+       
        /**
         * Parses through the main index file(index.xml) looking for the 
subindex containing the entry
         * for the search string.
@@ -322,7 +293,7 @@
         * @throws Exception
         */
        private String getSubindex(String indexuri, String str) throws 
Exception {
-               Bucket bucket = fetchBucket(indexuri + DEFAULT_FILE);
+               Bucket bucket = Util.fetchBucket(indexuri + DEFAULT_FILE, pr);
 
                SAXParserFactory factory = SAXParserFactory.newInstance();
                try {
@@ -355,7 +326,7 @@
                Vector<URIWrapper> fileuris = new Vector<URIWrapper>();
 
                try {
-                       Bucket bucket = fetchBucket(indexuri + "index_" + 
subIndex + ".xml");
+                       Bucket bucket = Util.fetchBucket(indexuri + "index_" + 
subIndex + ".xml", pr);
 
                        SAXParserFactory factory = 
SAXParserFactory.newInstance();
                        try {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to