changes + annotation generation
[IRC.git] / 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                 String https = new String("https://");
44                 int beginindex;
45                 int endindex;
46
47                 if ((page.indexOf(http) == -1) && (page.indexOf(https) == -1)) {
48                         return getHostName();
49                 } 
50                 else if (page.indexOf(https) != -1) {
51                         beginindex = page.indexOf(https) + https.length();
52                 }
53                 else {
54                         beginindex = page.indexOf(http) + http.length();
55                 }
56                 endindex = page.indexOf('/',beginindex+1);
57
58                 if ((beginindex == -1)) {
59                         System.printString("ERROR");
60                 }
61                 if (endindex == -1)
62                         endindex = page.length();
63
64                 return page.subString(beginindex, endindex);
65         }
66
67         public String getPathName(String page) {
68                 String http = new String("http://");
69                 String https = new String("https://");
70                 int beginindex;
71                 int nextindex;
72
73                 if ((page.indexOf(http) == -1) && (page.indexOf(https) == -1)) {
74                         String path = getPath();
75                         int lastindex = path.lastindexOf('/');
76                         if (lastindex == -1)
77                                 return page;
78             
79                         StringBuffer sb = new StringBuffer(path.subString(0,lastindex+1));
80                         sb.append(page);
81                         return sb.toString();
82                 }
83                 else if (page.indexOf(https) != -1) {
84                         beginindex = page.indexOf(https) + https.length();
85                 }
86                 else {
87                         beginindex = page.indexOf(http) + http.length();
88                 }
89                 nextindex = page.indexOf('/',beginindex+1);
90
91                 if ((beginindex==-1) || (nextindex==-1))
92                         return new String("index.html");
93                 return page.subString(nextindex+1, page.length());
94         }
95 }