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