gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] storm/org/nongnu/storm/util HTTPProxy.java


From: Tuukka Hastrup
Subject: [Gzz-commits] storm/org/nongnu/storm/util HTTPProxy.java
Date: Thu, 08 May 2003 11:29:32 -0400

CVSROOT:        /cvsroot/storm
Module name:    storm
Changes by:     Tuukka Hastrup <address@hidden> 03/05/08 11:29:32

Modified files:
        org/nongnu/storm/util: HTTPProxy.java 

Log message:
        rewriteURIs and insertBacklinks separate methods

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/util/HTTPProxy.java.diff?tr1=1.25&tr2=1.26&r1=text&r2=text

Patches:
Index: storm/org/nongnu/storm/util/HTTPProxy.java
diff -u storm/org/nongnu/storm/util/HTTPProxy.java:1.25 
storm/org/nongnu/storm/util/HTTPProxy.java:1.26
--- storm/org/nongnu/storm/util/HTTPProxy.java:1.25     Thu May  8 11:12:36 2003
+++ storm/org/nongnu/storm/util/HTTPProxy.java  Thu May  8 11:29:32 2003
@@ -126,64 +126,16 @@
                String s = CopyUtil.readString(block.getInputStream());
 
                String prefix = "";
+               if(rewrite) prefix = ROOTURL+REWRITE+"/";
+               if(backlinks) prefix += BACKLINKS+"/";
 
-               if(rewrite) {
-                   prefix = ROOTURL+REWRITE+"/";
-                   if(backlinks) prefix += BACKLINKS+"/";
-                   
-                   String l = s.toLowerCase(); // XXX Why this?
-                   int i = -1;
-                   while((i=l.indexOf("urn:x-storm:1.0:", i)) >= 0) {
-                       s = s.substring(0, i) + prefix + s.substring(i);
-                       l = s.toLowerCase(); // XXX and this?
-                       i += prefix.length() + 1;
-                   }
-               }
+               if(rewrite)
+                   s = rewriteURIs(s, prefix);
+
+               /* XXX If no rewrite, should the links be URNs or backlinks/ */
+               if(backlinks)
+                   s = insertBacklinks(s, prefix, id);
 
-               if(backlinks) {
-                   if(HTTPProxy.dbg) p("Getting HtmlLinkIndex.");
-                   
-                   HtmlLinkIndex idx = null;
-                   try {
-                       idx = (HtmlLinkIndex)pool.getIndex(HtmlLinkIndex.uri);
-                   } catch(NoSuchElementException _) {}
-                   
-                   if(HTTPProxy.dbg) p("HtmlLinkIndex = "+idx);
-                   
-                   if(idx != null) {
-                       if(HTTPProxy.dbg) p("Looking for links");
-                       Collector links = idx.getLinksTo(id);
-                       
-                       try {
-                           // XXX Are we trying to wait for indexing?
-                           Thread.sleep(2000);
-                       } catch(InterruptedException _) {}
-                       
-                       if(HTTPProxy.dbg) p("Iter thru links");
-                       String t = "";
-                       synchronized(links) {
-                           for(Iterator iter=links.iterator(); 
-                               iter.hasNext();) {
-                               HtmlLinkIndex.Link link = 
-                                   (HtmlLinkIndex.Link)iter.next();
-                               if(HTTPProxy.dbg) p("Link: "+link.linkText);
-                               t += "[<a 
href=\""+prefix+link.linkFrom.getURI()+
-                                   "\">"+link.linkText+"</a>]<br>";
-                           }
-                       }
-                       if(!t.equals("")) {
-                           int i = s.indexOf("<body");
-                           i = s.indexOf(">", i);
-                           if(i < 0) i = 0;
-                           else i++;
-                           s = s.substring(0, i) 
-                               + "\n<p><small>Backlinks:<br>"
-                               + t
-                               + "</small></p>\n" 
-                               + s.substring(i);
-                       }
-                   }
-               }
                        
                byte[] bytes = s.getBytes("US-ASCII");
                resp.getOutputStream().write(bytes);
@@ -269,6 +221,64 @@
                int blocksize = CopyUtil.copy(block.getInputStream(),
                                              resp.getOutputStream());
                return resp;
+       }
+
+       protected String rewriteURIs(String s, String prefix) {
+           String l = s.toLowerCase(); // XXX Why this?
+           int i = -1;
+           while((i=l.indexOf("urn:x-storm:1.0:", i)) >= 0) {
+               s = s.substring(0, i) + prefix + s.substring(i);
+               l = s.toLowerCase(); // XXX and this?
+               i += prefix.length() + 1;
+           }
+           return s;
+       }
+
+       protected String insertBacklinks(String s, String prefix, BlockId id) 
+           throws IOException {
+           if(HTTPProxy.dbg) p("Getting HtmlLinkIndex.");
+                   
+           HtmlLinkIndex idx = null;
+           try {
+               idx = (HtmlLinkIndex)pool.getIndex(HtmlLinkIndex.uri);
+           } catch(NoSuchElementException _) {}
+                   
+           if(HTTPProxy.dbg) p("HtmlLinkIndex = "+idx);
+                   
+           if(idx != null) {
+               if(HTTPProxy.dbg) p("Looking for links");
+               Collector links = idx.getLinksTo(id);
+               
+               try {
+                   // XXX Are we trying to wait for indexing?
+                   Thread.sleep(2000);
+               } catch(InterruptedException _) {}
+               
+               if(HTTPProxy.dbg) p("Iter thru links");
+               String t = "";
+               synchronized(links) {
+                   for(Iterator iter=links.iterator(); 
+                       iter.hasNext();) {
+                       HtmlLinkIndex.Link link = 
+                           (HtmlLinkIndex.Link)iter.next();
+                       if(HTTPProxy.dbg) p("Link: "+link.linkText);
+                       t += "[<a href=\""+prefix+link.linkFrom.getURI()+
+                           "\">"+link.linkText+"</a>]<br>";
+                   }
+               }
+               if(!t.equals("")) {
+                   int i = s.indexOf("<body");
+                   i = s.indexOf(">", i);
+                   if(i < 0) i = 0;
+                   else i++;
+                   s = s.substring(0, i) 
+                       + "\n<p><small>Backlinks:<br>"
+                       + t
+                       + "</small></p>\n" 
+                       + s.substring(i);
+               }
+           }
+           return s;
        }
 
        protected HTTPResponse makePAC(HTTPRequest req, 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]