cz/vutbr/fit/dudka/SGVis/Lookup/Lookup.java

Go to the documentation of this file.
00001 package cz.vutbr.fit.dudka.SGVis.Lookup;
00002 
00009 import java.io.IOException;
00010 import java.net.MalformedURLException;
00011 import java.net.URL;
00012 
00018 public class Lookup {
00019   private SimpleDownloader downloader = new SimpleDownloader();
00020   private String urlBase;
00021   
00026   public Lookup(String urlBase) {
00027     this.urlBase = urlBase;
00028   }
00029   
00033   public String getUrlBase() {
00034     return urlBase;
00035   }
00036   
00041   public void setUrlBase(String urlBase) {
00042     this.urlBase = urlBase;
00043   }
00044   
00052   public String lookup(Request rq) throws MalformedURLException, IOException {
00053     URL rqUrl = this.buildUrl(rq);
00054     return downloader.download(rqUrl);
00055   }
00056   
00057   private URL buildUrl(Request rq) throws MalformedURLException {
00058     String[] q = rq.getQ();
00059     if (q.length==0)
00060       throw new RuntimeException("Empty lookup");
00061     
00062     // TODO: handle URL strings containing query
00063     // (encode/decode URL)
00064     StringBuffer urlString =
00065       new StringBuffer(this.urlBase+"?q=");
00066     for (int i=0; i<q.length; i++)
00067       urlString.append((i+1>=q.length)?
00068         q[i]:
00069         q[i]+",");
00070     urlString.append("&edo="+(rq.edo?1:0));
00071     urlString.append("&edi="+(rq.edi?1:0));
00072     urlString.append("&fme="+(rq.fme?1:0));
00073     return new URL(urlString.toString());
00074   }
00075 }

Generated on Sat May 3 22:56:09 2008 for SGVis by  doxygen 1.5.4