/[storm]/storm/org/nongnu/storm/util/HTTPProxy.java
ViewVC logotype

Diff of /storm/org/nongnu/storm/util/HTTPProxy.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.25 by tuukkah, Thu May 8 15:12:36 2003 UTC revision 1.26 by tuukkah, Thu May 8 15:29:32 2003 UTC
# Line 126  public class HTTPProxy implements Runnab Line 126  public class HTTPProxy implements Runnab
126                  String s = CopyUtil.readString(block.getInputStream());                  String s = CopyUtil.readString(block.getInputStream());
127    
128                  String prefix = "";                  String prefix = "";
129                    if(rewrite) prefix = ROOTURL+REWRITE+"/";
130                    if(backlinks) prefix += BACKLINKS+"/";
131    
132                  if(rewrite) {                  if(rewrite)
133                      prefix = ROOTURL+REWRITE+"/";                      s = rewriteURIs(s, prefix);
134                      if(backlinks) prefix += BACKLINKS+"/";  
135                                        /* XXX If no rewrite, should the links be URNs or backlinks/ */
136                      String l = s.toLowerCase(); // XXX Why this?                  if(backlinks)
137                      int i = -1;                      s = insertBacklinks(s, prefix, id);
                     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;  
                     }  
                 }  
138    
                 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);  
                         }  
                     }  
                 }  
139                                                    
140                  byte[] bytes = s.getBytes("US-ASCII");                  byte[] bytes = s.getBytes("US-ASCII");
141                  resp.getOutputStream().write(bytes);                  resp.getOutputStream().write(bytes);
# Line 271  public class HTTPProxy implements Runnab Line 223  public class HTTPProxy implements Runnab
223                  return resp;                  return resp;
224          }          }
225    
226            protected String rewriteURIs(String s, String prefix) {
227                String l = s.toLowerCase(); // XXX Why this?
228                int i = -1;
229                while((i=l.indexOf("urn:x-storm:1.0:", i)) >= 0) {
230                    s = s.substring(0, i) + prefix + s.substring(i);
231                    l = s.toLowerCase(); // XXX and this?
232                    i += prefix.length() + 1;
233                }
234                return s;
235            }
236    
237            protected String insertBacklinks(String s, String prefix, BlockId id)
238                throws IOException {
239                if(HTTPProxy.dbg) p("Getting HtmlLinkIndex.");
240                        
241                HtmlLinkIndex idx = null;
242                try {
243                    idx = (HtmlLinkIndex)pool.getIndex(HtmlLinkIndex.uri);
244                } catch(NoSuchElementException _) {}
245                        
246                if(HTTPProxy.dbg) p("HtmlLinkIndex = "+idx);
247                        
248                if(idx != null) {
249                    if(HTTPProxy.dbg) p("Looking for links");
250                    Collector links = idx.getLinksTo(id);
251                    
252                    try {
253                        // XXX Are we trying to wait for indexing?
254                        Thread.sleep(2000);
255                    } catch(InterruptedException _) {}
256                    
257                    if(HTTPProxy.dbg) p("Iter thru links");
258                    String t = "";
259                    synchronized(links) {
260                        for(Iterator iter=links.iterator();
261                            iter.hasNext();) {
262                            HtmlLinkIndex.Link link =
263                                (HtmlLinkIndex.Link)iter.next();
264                            if(HTTPProxy.dbg) p("Link: "+link.linkText);
265                            t += "[<a href=\""+prefix+link.linkFrom.getURI()+
266                                "\">"+link.linkText+"</a>]<br>";
267                        }
268                    }
269                    if(!t.equals("")) {
270                        int i = s.indexOf("<body");
271                        i = s.indexOf(">", i);
272                        if(i < 0) i = 0;
273                        else i++;
274                        s = s.substring(0, i)
275                            + "\n<p><small>Backlinks:<br>"
276                            + t
277                            + "</small></p>\n"
278                            + s.substring(i);
279                    }
280                }
281                return s;
282            }
283    
284          protected HTTPResponse makePAC(HTTPRequest req,          protected HTTPResponse makePAC(HTTPRequest req,
285                                         HTTPResponse.Factory resf)                                         HTTPResponse.Factory resf)
286              throws IOException {              throws IOException {

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26