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