bug fix: the loop entrance node of DOWHILELOOP is the begin node, not the condition...
[IRC.git] / GlobalQuery.java
1 public class GlobalQuery {
2   GlobalString hostname;
3   GlobalString path;
4         int depth;
5   
6         public GlobalQuery(GlobalString hostname) {
7                 this.hostname = global new GlobalString(hostname);
8                 this.path = global new GlobalString("");
9                 this.depth = 0;
10         }
11
12   public GlobalQuery(GlobalString hostname, GlobalString path, int depth) {
13     this.hostname = global new GlobalString(hostname);
14     this.path = global new GlobalString(path);
15                 this.depth = depth;
16   }
17
18         public int getDepth() {
19                 return depth;
20         }
21         
22   public GlobalString getHostName() {
23     return hostname;
24   }
25  
26   public GlobalString getPath() {
27     return path;
28   }
29
30   public GlobalString makewebcanonical(GlobalString page) {
31     GlobalStringBuffer b = global new GlobalStringBuffer(getHostName(page));
32     b.append("/");
33                 b.append(getPathName(page));
34     return b.toGlobalString();
35         }
36
37   public GlobalString getHostName(GlobalString page) {
38     GlobalString http = global new GlobalString("http://");
39     GlobalString https = global new GlobalString("https://");
40                 int beginindex;
41                 int endindex;
42
43                 if ((page.indexOf(http) == -1) && (page.indexOf(https) == -1)) {
44                         return getHostName();
45                 } 
46                 else if (page.indexOf(https) != -1) {
47                         beginindex = page.indexOf(https) + https.length();
48                 }
49                 else {
50                         beginindex = page.indexOf(http) + http.length();
51                 }
52           endindex = page.indexOf('/',beginindex+1);
53
54                 if ((beginindex == -1)) {       
55                         System.printString("ERROR");
56                 }
57                 if (endindex == -1)
58                         endindex = page.length();
59
60                 return page.subString(beginindex, endindex);
61   }
62
63   
64         public GlobalString getPathName(GlobalString page) {
65     GlobalString http = global new GlobalString("http://");
66     GlobalString https = global new GlobalString("https://");
67                 int beginindex;
68                 int nextindex;
69
70                 if ((page.indexOf(http) == -1) && (page.indexOf(https) == -1)) {
71       GlobalString path = getPath();
72             int lastindex = path.lastindexOf('/');
73             if (lastindex == -1)
74         return page;
75             
76       GlobalStringBuffer sb = global new GlobalStringBuffer(path.subString(0,lastindex+1));
77             sb.append(page);
78       return sb.toGlobalString();
79     } 
80                 else if (page.indexOf(https) != -1) {
81                         beginindex = page.indexOf(https) + https.length();
82                 }
83                 else {
84                         beginindex = page.indexOf(http) + http.length();
85                 }
86                 nextindex = page.indexOf('/',beginindex+1);
87
88                 if ((beginindex == -1) || (nextindex == -1))
89                         return global new GlobalString("index.html");
90                 return page.subString(nextindex+1, page.length());
91   }
92 }