java sources
[IRC.git] / Robust / src / Benchmarks / Spider / Java / Query.java
1 public class Query {
2     private String hostname;
3     private String path;
4
5     private StringBuffer response;
6
7     public Query(String hostname, String path) {
8         this.hostname=hostname;
9         this.path=path;
10         response=new StringBuffer();
11     }
12
13     public String getHostName() {
14         return hostname;
15     }
16
17     public String getPath() {
18         return path;
19     }
20     
21     public String makewebcanonical(String page) {
22         StringBuffer b=new StringBuffer(getHostName(page));
23         b.append("/");
24         b.append(getPathName(page));
25         return b.toString();
26     }
27
28     public String getHostName(String page) {
29         String http=new String("http://");
30         if (page.indexOf(http)==-1) {
31             return getHostName();
32         } else {
33             int beginindex=page.indexOf(http)+http.length();
34             int endindex=page.indexOf('/',beginindex+1);
35             if ((beginindex==-1)) {
36                 System.printString("ERROR");
37             }
38             if (endindex==-1)
39                 endindex=page.length();
40             return page.subString(beginindex, endindex);
41         }
42     }
43
44     public String getPathName(String page) {
45         String http=new String("http://");
46         if (page.indexOf(http)==-1) {
47             String path=getPath();
48             int lastindex=path.lastindexOf('/');
49             if (lastindex==-1)
50                 return page;
51             
52             StringBuffer sb=new StringBuffer(path.subString(0,lastindex+1));
53             sb.append(page);
54             return sb.toString();
55         } else {
56             int beginindex=page.indexOf(http)+http.length();
57             int nextindex=page.indexOf('/',beginindex+1);
58             if ((beginindex==-1)||(nextindex==-1))
59                 return new String("index.html");
60             return page.subString(nextindex+1, page.length()-1);
61         }
62     }
63 }