-
Notifications
You must be signed in to change notification settings - Fork 0
/
varscoper.cfc
112 lines (83 loc) · 2.81 KB
/
varscoper.cfc
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
component {
public function init() {
local.paths = [
ExpandPath("lib/antlr-4.0-complete.jar"),
ExpandPath("compiled/")
];
local.classPaths = [
ExpandPath("java/")
];
local.loader = createObject("component", "javaloader.JavaLoader").init(loadPaths = local.paths, sourceDirectories = local.classPaths);
variables.processor = local.loader.create("Cfscript").init();
return this;
}
public function handle() {
param name = "url.action" default="home";
if (!StructKeyExists(variables, "handler_" & url.action) || !IsCustomFunction(variables["handler_" & url.action])) {
return "Invalid handler specified.";
}
local.method = variables["handler_" & url.action];
return local.method(url);
}
public function handler_home(struct rc) {
param name = "arguments.rc.errorMessage" default = "";
return templateResult("container.cfm", { html = templateResult("home.cfm", arguments.rc) });
}
public function handler_processRequest(struct rc) {
local.start = getTickCount();
local.pass = {};
if (ReFind("\\$", arguments.rc.path)) {
if (!DirectoryExists(arguments.rc.path)) {
return handler_home({ errorMessage = "Directory #arguments.rc.path# was not found." });
}
local.pass.data = processFolder(arguments.rc.path);
} else {
if (!FileExists(arguments.rc.path)) {
return handler_home({ errorMessage = "File #arguments.rc.path# was not found." });
}
writeOutput("file processing not written yet");
}
local.pass.duration = getTickCount() - local.start;
local.pass.path = arguments.rc.path;
return templateResult("container.cfm", { html = templateResult("results.cfm", local.pass) });
}
public function processFile(required string path) {
local.pass = {
data = [],
hasInvalid = false
};
}
public function processFolder(required string path) {
local.pass = {
data = [],
hasInvalid = false
};
local.files = directoryList(arguments.path, true, "path", "*.cfc");
for(local.i = 1; local.i <= ArrayLen(local.files); local.i++) {
local.temp = FileRead(local.files[local.i]);
if (ReFindNoCase("\s*\<cfcomponent[^>]*\>", local.temp)) {
continue;
}
local.component = processString(local.files[local.i]);
if (local.component.hasUnvarred()) {
local.pass.hasUnvarred = true;
}
ArrayAppend(local.pass.data, {
component = local.component,
path = local.files[local.i]
});
}
return local.pass;
}
public function processString(required string data) {
return variables.processor.process(arguments.data);
}
public function templateResult(required string template, struct pass = {}) {
local.pass = arguments.pass;
local.template = "templates/" & arguments.template;
savecontent variable = "local.return" {
include local.template;
}
return local.return;
}
}