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