-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResource.java
More file actions
executable file
·87 lines (75 loc) · 1.72 KB
/
Resource.java
File metadata and controls
executable file
·87 lines (75 loc) · 1.72 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
import java.io.IOException;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.File;
public class Resource{
private String uri;
public HttpdConf httpdConf;
public Boolean isScript;
public Resource(String uri, HttpdConf httpdConf){
this.uri = uri;
this.httpdConf = httpdConf;
if(uriScriptAliased()){
isScript = true;
}else{
isScript = false;
}
}
public String absolutePath(){
String absolutePath;
if(uriAliased()){
absolutePath = httpdConf.alias.get(uri);
}else if(isScript == true){
absolutePath = httpdConf.scriptAlias.get(uri);
}else{
absolutePath = resolvePath();
}
if( isFile(absolutePath) == false && fileExists(absolutePath) == true ){
absolutePath = appendDirIndex(absolutePath);
}
return absolutePath;
}
public String appendDirIndex(String path){
String filePath = "";
for(int i=0; i<httpdConf.directoryIndex.size();i++){
filePath = path + "/" + httpdConf.directoryIndex.get(i).replace("\"", "");
if(fileExists(filePath) == true){
break;
}
}
return filePath;
}
public boolean isFile(String path){
File file = new File(path);
return file.isFile();
}
public boolean fileExists(String path){
File file = new File(path);
return file.exists();
}
public boolean isScript(){
return isScript;
}
public boolean isProtected(){
return true;
}
public String resolvePath(){
return httpdConf.documentRoot.replace("\"", "") + uri;
}
public boolean uriAliased(){
String alias = httpdConf.alias.get(uri);
if(alias == null){
return false;
}else{
return true;
}
}
public boolean uriScriptAliased(){
String alias = httpdConf.scriptAlias.get(uri);
if(alias == null){
return false;
}else{
return true;
}
}
}