-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyopenbox.cfc
2079 lines (1741 loc) · 83 KB
/
myopenbox.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<cfcomponent displayname="MyOpenbox"
hint="I am the core file for the MyOpenbox framework.">
<!---
/////////////////////////////////// MYOPENBOX LICENSE (BETA) //////////////////////////////////
// MyOpenbox authored by Tyler Silcox.
// Please send all questions, comments, and suggestions to [email protected].
// Made in the U.S.A.
///////////////////////////////////////////////////////////////////////////////////////////////
--->
<cffunction name="Init"
access="public"
hint="I initialize this component."
output="false"
returntype="struct">
<cfargument name="Configuration" type="struct" default="#StructNew()#" />
<cfscript>
// i set the Version information
this.Version.Number="0";
this.Version.BuildNumber="071";
this.Version.BuildDate="2022.04.14";
this.Configuration=arguments.Configuration;
this.Logs=StructNew();
this.Logs.Actions=QueryNew("timestamp,action,type,time,info", "timestamp,varchar,varchar,integer,varchar");
this.Cache=StructNew();
this.Cache.Agents=StructNew();
this.System=CreateObject( "java", "java.lang.System" );
this.Environment=this.System.GetEnv();
this.FileExistsCache=StructNew();
</cfscript>
<cfset this.LogAction("CFC Init()", "FW") />
<cfparam name="this.Configuration.ApplicationRootPath" default="#GetDirectoryFromPath(GetCurrentTemplatePath())#../" />
<cfparam name="this.Configuration.ApplicationConfigurationPath" default="#GetDirectoryFromPath(GetCurrentTemplatePath())#../" />
<cfparam name="this.Configuration.ApplicationConfigurationFile" default="#this.Configuration.ApplicationConfigurationPath#cfg.myopenbox.cfm" />
<cfparam name="this.Configuration.SetupConfigurationPath" default="#GetDirectoryFromPath(GetCurrentTemplatePath())#" />
<cfparam name="this.Configuration.SetupConfigurationFile" default="#this.Configuration.SetupConfigurationPath#config.cfm" />
<cfreturn this>
</cffunction>
<cffunction name="AddCacheAgent" access="public" output="false">
<cfargument name="name" default="Default" />
<cfargument name="agent" default="#NewCacheAgent().init(AgentName=arguments.Name, Context='application')#" />
<cfset this.Cache.Agents[arguments.Name]=arguments.agent />
</cffunction>
<cffunction name="NewCacheAgent" access="public" output="false">
<cfreturn CreateObject('component', 'cachebox.cacheboxagent') />
</cffunction>
<cffunction name="GetCacheAgent" access="public" output="false">
<cfargument name="name" default="" />
<cfreturn this.Cache.Agents[arguments.name] />
</cffunction>
<cffunction name="IsFWReinit"
access="public"
output="false"
returntype="boolean">
<cfparam name="form" default="#StructNew()#">
<cfparam name="url" default="#StructNew()#">
<cfreturn NOT IsDefined("application.Myopenbox.Parameters.FWReinit") OR (StructKeyExists(url, "FWReinit") AND IsDefined("application.Myopenbox.Parameters.FWReinit") AND url.FWReinit EQ application.Myopenbox.Parameters.FWReinit) OR (StructKeyExists(form, "FWReinit") AND IsDefined("application.Myopenbox.Parameters.FWReinit") AND form.FWReinit EQ application.Myopenbox.Parameters.FWReinit) />
</cffunction>
<cffunction name="IsFWReparse"
access="public"
output="false"
returntype="boolean">
<cfparam name="form" default="#StructNew()#">
<cfparam name="url" default="#StructNew()#">
<cfreturn (StructKeyExists(url, "FWReparse") AND IsDefined("application.Myopenbox.Parameters.FWReparse") AND url.FWReparse EQ application.Myopenbox.Parameters.FWReparse) OR (StructKeyExists(form, "FWReparse") AND IsDefined("application.Myopenbox.Parameters.FWReparse") AND form.FWReparse EQ application.Myopenbox.Parameters.FWReparse) />
</cffunction>
<cffunction name="IsFWAction"
access="public"
output="false"
returntype="boolean">
<cfparam name="form" default="#StructNew()#">
<cfparam name="url" default="#StructNew()#">
<cfreturn (StructKeyExists(url, "FWAction") AND IsDefined("application.Myopenbox.Parameters.FWReparse") AND url.FWAction EQ application.Myopenbox.Parameters.FWReparse) OR (StructKeyExists(form, "FWAction") AND IsDefined("application.Myopenbox.Parameters.FWReparse") AND form.FWAction EQ application.Myopenbox.Parameters.FWReparse) />
</cffunction>
<!--- cffunction name="RUNMYOPENBOX METHODS" --->
<cffunction name="RunMyOpenbox"
access="public"
hint="I parse and create the MyOpenbox memory variables from the XML configuration files."
output="false"
returntype="void">
<cfargument name="ApplicationConfigurationFile" type="string" default="#this.Configuration.ApplicationConfigurationFile#">
<cfscript>
// i initialize the local vars
local.RawXML=Read(arguments.ApplicationConfigurationFile);
local.HashKey=Hash(local.RawXML);
</cfscript>
<!--- i determine if i should parse the MyOpenbox --->
<cfif NOT StructKeyExists(this, "Parameters")
OR this.Parameters.ProcessingMode EQ "Development"
OR NOT StructKeyExists(this, "ApplicationConfigurationFileHashKey")
OR this.ApplicationConfigurationFileHashKey NEQ local.HashKey
OR this.IsFWReparse()>
<!--- i lock the parsing of the MyOpenbox --->
<cflock name="#Hash(GetCurrentTemplatePath() & "_RunMyOpenbox")#" timeout="10">
<!--- i (re)determine if i should parse the MyOpenbox --->
<cfif NOT StructKeyExists(this, "Parameters")
OR this.Parameters.ProcessingMode EQ "Development"
OR NOT StructKeyExists(this, "ApplicationConfigurationFileHashKey")
OR this.ApplicationConfigurationFileHashKey NEQ local.HashKey
OR this.IsFWReparse()>
<cfscript>
// i create a TimeStamp
this.TimeStamp=Now();
// request.OpenboxReparseInitiated = true;
// i parse the XML MyOpenbox configuration file(s)
ParseApplicationConfigurationFiles(XMLParse(RawXML));
// i create a Hash reference in this for checks against the MyOpenbox configuration file
this.ApplicationConfigurationFileHashKey=local.HashKey;
this.LogAction(action="MOBX Parsed", type="FW", info=local.HashKey);
</cfscript>
<!---
<cfif this.Parameters.ProcessingMode EQ "Deployment" AND (this.IsFWReparse() OR this.IsFWReinit())>
<cfset CreateAllCircuitAndFuseactionFiles() />
</cfif>
--->
</cfif>
</cflock>
</cfif>
<cfscript>
// i set the Log values
if(this.Parameters.EnableLogs){
this.Logs.MyOpenboxElapsedTime=Now() - this.TimeStamp;
this.Logs.Requests.Total=this.Logs.Requests.Total + 1;
this.Logs.Requests.LastRequested=Now();
}
</cfscript>
</cffunction>
<cffunction name="ParseApplicationConfigurationFiles"
access="private"
hint="I parse the MyOpenbox application and default setup configuration files."
output="true"
returntype="void">
<cfargument name="ApplicationDeclarations" type="any">
<cfargument name="SetupConfigurationFile" type="string" default="#this.Configuration.SetupConfigurationFile#">
<cfscript>
// i initialize the local vars
var SetupDeclarations=XMLParse(Read(arguments.SetupConfigurationFile));
var TickCount=GetTickCount();
var i="";
var CircuitRootArray=ArrayNew(1);
</cfscript>
<cfscript>
// i set default Log values
this.Logs.ProcessingTime=StructNew();
// i set Parameters
this.Parameters=ParseParameters(SetupDeclarations.XMLRoot.parameters, true);
if(StructKeyExists(arguments.ApplicationDeclarations.XMLRoot, "parameters")){
StructAppend(this.Parameters, ParseParameters(arguments.ApplicationDeclarations.XMLRoot.parameters));
}
// i check the EnableLogs Parameter
if(this.Parameters.EnableLogs){
this.Logs.Inventory.Circuits=0;
this.Logs.Inventory.FuseActions=0;
this.Logs.Requests.Total=0;
this.Logs.Requests.FileBuilds=0;
} else {
StructDelete(this, "Logs");
}
// i set Verbs
this.Verbs=ParseVerbs(SetupDeclarations.XMLRoot.verbs, true);
if(StructKeyExists(arguments.ApplicationDeclarations.XMLRoot, "verbs")){
StructAppend(this.Verbs, ParseVerbs(arguments.ApplicationDeclarations.XMLRoot.verbs));
}
// i set Phases
if(StructKeyExists(arguments.ApplicationDeclarations.XMLRoot, "phases")){
this.Phases=ParsePhases(arguments.ApplicationDeclarations.XMLRoot.phases);
} else {
this.Phases=StructNew();
}
this.CustomPhases=ArrayNew(1);
for(i in this.Phases) {
if(NOT ListFindNoCase(this.Parameters.ApplicationPhases, i)){
ArrayAppend(this.CustomPhases, i);
}
}
this.Circuits=StructNew();
// i set Circuits
CircuitRootArray=ListToArray(this.Parameters.CircuitRootPaths, ",");
for(i=1; i LTE ArrayLen(CircuitRootArray); i=i+1){
StructAppend(this.Circuits, ParseCircuits(this.Configuration.ApplicationRootPath & CircuitRootArray[i], CircuitRootArray[i]), true);
}
//this.Circuits=ParseCircuits();
// i create the application level Phases' files
CreatePhaseFiles(this.Parameters.ApplicationPhases);
// i create the Settings file
if(StructKeyExists(arguments.ApplicationDeclarations.XMLRoot, "settings")){
// i create an empty Settings struct for checking existence
this.Settings=StructNew();
// i create the file
CreateSettingsFile(type="MyOpenbox", currentNode=arguments.ApplicationDeclarations.XMLRoot.settings, filePath=this.Configuration.ApplicationConfigurationPath);
}
// i create the Routes file
this.Routes=CreateObject("component", "SES");
this.Routes.configure();
if(StructKeyExists(arguments.ApplicationDeclarations.XMLRoot, "routes")){
// i create the file
CreateRoutesFile("MyOpenbox", arguments.ApplicationDeclarations.XMLRoot.routes);
}
// i store the parsed Configuration XML
if(this.Parameters.StoreXML){
this.ConfigurationFile.XML=arguments.ApplicationDeclarations;
}
// i set a total ProcessingTime
if(this.Parameters.EnableLogs){
this.Logs.ProcessingTime.ParseConfigurationFiles=GetTickCount() - TickCount;
}
</cfscript>
</cffunction>
<cffunction name="ParseParameters"
access="private"
hint="I parse out the MyOpenbox Parameters."
output="false"
returntype="struct">
<cfargument name="CurrentNode" type="any">
<cfargument name="IsConfiguration" type="boolean" default="false">
<cfscript>
// i initialize the local vars
var Parameters=StructNew();
var ParameterName="";
var i=0;
var ThrowError=0;
var TickCount=GetTickCount();
</cfscript>
<cfscript>
// i parse Parameter elements
for(i=1; i LTE ArrayLen(arguments.CurrentNode.XMLChildren); i=i + 1){
// i run any necessary checks or provide a lookout for aliases
switch(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["name"]){
case "ProcessingMode" :
ParameterName="ProcessingMode";
if(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"] EQ "Development" OR arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"] EQ "1"){
arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"]="Development";
} else if(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"] EQ "Production" OR arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"] EQ "0"){
arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"]="Production";
} else if(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"] EQ "Deployment" OR arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"] EQ "-1"){
arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"]="Deployment";
} else {
// i throw an error if you pass in a crappy value
ThrowError=True;
}
break;
case "DirectoryDelimiters" :
ParameterName="Delimiters.Directory";
break;
case "NewLineDelimiters" :
ParameterName="Delimiters.NewLine";
break;
case "TabDelimiters" :
ParameterName="Delimiters.Tab";
break;
case "DefaultFileExtensionDelimiters" : case "ScriptFileDelimiter" :
ParameterName="Delimiters.DefaultFileExtension";
break;
case "MaskedFileExtensionsDelimiters" : case "MaskedFileDelimiters" :
ParameterName="Delimiters.MaskedFileExtensions";
break;
case "SelfFolder" :
ParameterName="Self.Folder";
break;
case "SelfPath" :
ParameterName="Self.Path";
break;
case "SelfRootPath" :
ParameterName="Self.RootPath";
break;
case "CacheFolder" :
ParameterName="Cache.Folder";
break;
case "CachePath" :
ParameterName="Cache.Path";
break;
case "CachePathExpandPath" :
ParameterName="Cache.PathExpandPath";
break;
case "CacheRootPath" :
ParameterName="Cache.RootPath";
break;
case "DictionaryFolder" :
ParameterName="Dictionary.Folder";
break;
case "DictionaryPath" :
ParameterName="Dictionary.Path";
break;
case "DictionaryRootPath" :
ParameterName="Dictionary.RootPath";
break;
case "ParseWithComments" :
if(IsBoolean(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"])){
ParameterName="ParseWithComments";
} else {
// i throw an error if you pass in a crappy value
ThrowError=True;
}
break;
case "PrecedenceFormOrURL" :
if(ListFindNoCase("form,url", arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"])){
ParameterName="PrecedenceFormOrURL";
} else {
// i throw an error if you pass in a crappy value
ThrowError=True;
}
break;
case "StoreXML" :
if(IsBoolean(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"])){
ParameterName="StoreXML";
} else {
// i throw an error if you pass in a crappy value
ThrowError=True;
}
break;
case "DashboardEnable" :
ParameterName="Dashboard.Enable";
break;
default :
ParameterName=arguments.CurrentNode.Parameter[i]["XMLAttributes"]["name"];
break;
}
// i check for any errors
if(ThrowError){
Throw("MyOpenbox", "Error while processing MyOpenbox configuration parameter """ & arguments.CurrentNode.Parameter[i]["XMLAttributes"]["Name"] & """.", "Please make sure all required attributes are included and valid in each parameter in the MyOpenbox configuration file.");
}
// i set the Parameter
if(
StructKeyExists(arguments.CurrentNode.Parameter[i]["XMLAttributes"], "evaluate")
AND arguments.CurrentNode.Parameter[i]["XMLAttributes"]["evaluate"]
){
SetVariable("Parameters." & ParameterName, Evaluate(arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"]));
} else {
SetVariable("Parameters." & ParameterName, arguments.CurrentNode.Parameter[i]["XMLAttributes"]["value"]);
}
}
// LOGS: i set a Logs.ProcessingTime value
if(arguments.IsConfiguration){
this.Logs.ProcessingTime.ParseParameters=GetTickCount() - TickCount;
} else if(this.Parameters.EnableLogs){
this.Logs.ProcessingTime.ParseParameters=GetTickCount() - TickCount + this.Logs.ProcessingTime.ParseParameters;
}
</cfscript>
<cfreturn Parameters>
</cffunction>
<cffunction name="ParseVerbs"
access="private"
hint="I parse out the MyOpenbox configuration XML Verbs."
output="false"
returntype="struct">
<cfargument name="CurrentNode" type="any">
<cfargument name="IsConfiguration" type="boolean" default="false">
<cfscript>
// i initialize the local vars
var Verbs=StructNew();
var i=0;
var TickCount=GetTickCount();
</cfscript>
<cfscript>
// i loop through the children elements
for(i=1; i LTE ArrayLen(arguments.CurrentNode.XMLChildren); i=i + 1){
StructAppend(Verbs, ParseVerb(arguments.CurrentNode.XMLChildren[i], arguments.IsConfiguration));
}
// LOGS: i set a Logs.ProcessingTime value
if(this.Parameters.EnableLogs){
if(arguments.IsConfiguration){
this.Logs.ProcessingTime.ParseVerbs=GetTickCount() - TickCount;
} else {
this.Logs.ProcessingTime.ParseVerbs=GetTickCount() - TickCount + this.Logs.ProcessingTime.ParseVerbs;
}
}
</cfscript>
<cfreturn Verbs>
</cffunction>
<cffunction name="ParseVerb"
access="private"
hint="."
output="false"
returntype="struct">
<cfargument name="CurrentNode" type="any" default="">
<cfargument name="IsConfiguration" type="boolean" default="false">
<cfscript>
// i initialize the local vars
var Verb=StructNew();
var VerbName="";
</cfscript>
<cfscript>
if(arguments.CurrentNode.XMLName NEQ "verb"){
// THROW ERROR - invalid element in Verbs assignment
}
VerbName=arguments.CurrentNode.XMLAttributes.name;
if(StructKeyExists(arguments.CurrentNode.XMLAttributes, "template")){
Verb[VerbName]["Template"]=LCase(arguments.CurrentNode.XMLAttributes.template);
} else {
Verb[VerbName]["Template"]=LCase(VerbName);
}
if(StructKeyExists(arguments.CurrentNode.XMLAttributes, "path")){
Verb[VerbName]["Path"]=arguments.CurrentNode.XMLAttributes.path;
}
if(NOT arguments.IsConfiguration){
Verb[VerbName]["IsCustom"]=true;
}
</cfscript>
<cfreturn Verb>
</cffunction>
<cffunction name="ParsePhases"
access="private"
hint="I parse out the MyOpenbox configuration XML Phases."
output="false"
returntype="struct">
<cfargument name="CurrentNode" type="any">
<cfscript>
// i initialize the local vars
var Phases=StructNew();
var PhaseName="";
var i=0;
var TickCount=GetTickCount();
</cfscript>
<cfscript>
// i loop through the XMLChilden
for(i=1; i LTE ArrayLen(arguments.CurrentNode.XMLChildren); i=i + 1){
// i set PhaseName
if(StructKeyExists(arguments.CurrentNode.XMLChildren[i].XMLAttributes, "title") AND NOT StructKeyExists(arguments.CurrentNode.XMLChildren[i].XMLAttributes, "name")){
PhaseName=FilterString(arguments.CurrentNode.XMLChildren[i].XMLAttributes.title);
} else {
PhaseName=arguments.CurrentNode.XMLChildren[i].XMLAttributes.name;
}
Phases[PhaseName]=ArrayNew(1);
Phases[PhaseName][1]["Commands"]=Duplicate(arguments.CurrentNode.XMLChildren[i]["XMLChildren"]);
}
// LOGS: i set a Logs.ProcessingTime value
if(this.Parameters.EnableLogs){
this.Logs.ProcessingTime.ParsePhases=GetTickCount() - TickCount;
}
</cfscript>
<cfreturn Phases>
</cffunction>
<cffunction name="ParseCircuits"
access="private"
hint="I parse out the MyOpenbox circuits."
output="false"
returntype="struct">
<cfargument name="TargetDirectory" default="#GetDirectoryFromPath(GetBaseTemplatePath())#" type="string">
<cfargument name="DirectoryPath" default="" type="string">
<cfargument name="ParentName" default="" type="string">
<cfscript>
// i initialize the local vars
var Circuits=StructNew();
var Circuit="";
var CircuitName="";
var GetDirectorys="";
var ConfigFileName="";
var XML=StructNew();
var IsContinue=True;
var IsParseCircuit=True;
var TickCount=GetTickCount();
</cfscript>
<cfdirectory name="GetDirectorys"
action="list"
sort="name ASC"
type="dir"
directory="#arguments.TargetDirectory#">
<cfloop query="GetDirectorys">
<cfif GetDirectorys.Type EQ "Dir"
AND Left(GetDirectorys.Name, 1) NEQ "_">
<cfset ConfigFileName=GetDirectorys.Name & this.Parameters.Delimiters.Directory & "cfg.circuit.cfm">
<!--- if this is a directory that doesn't start with a "_" and contains a cfg.circuit file --->
<cfif FileExists(arguments.TargetDirectory & ConfigFileName)>
<!--- i read the configuration file --->
<cfset XML.Raw=Read(arguments.TargetDirectory & ConfigFileName)>
<!--- i attempt to parse the configuration file --->
<cftry>
<cfset XML.Parsed=XMLParse(XML.Raw)>
<cfcatch type="any">
<cfset IsContinue=False>
<cfset Throw("MyOpenbox", "Error occured while parsing Circuit configuration file.", "The configuration file : " & ConfigFileName & " contains invalid XML. " & CFCatch.Detail, "Your configuration file must conform to XML specifications. Please make sure all tags and attribute values are closed and that you are using entities where necessary. For example, you must use ""&"" for Ampersand characters.")>
</cfcatch>
</cftry>
<cfscript>
// i parse the Circuit
if(IsContinue){
// i call ParseCircuit()
Circuit=ParseCircuit(XML.Parsed.Circuit);
// i check for Name and make CF recognize Circuit.Name (it seems CFMX 6.1 has a issue with keys named "Name")
if(StructKeyExists(Circuit, "Name")){
CircuitName=Circuit.Name;
} else {
Throw("MyOpenbox", "Error while parsing Circuit XML file.", "The configuration file located at : " & arguments.TargetDirectory & ConfigFileName & " does not contain a Name or Title definition.", "You must set either Name or Title in the Circuit configuration file.");
}
// i make sure there are not any duplicate Circuit Names in this directory
if(StructKeyExists(Circuits, CircuitName)){
Throw("MyOpenbox", "Error while parsing Circuit XML file.", "The configuration file located at : " & arguments.TargetDirectory & ConfigFileName & " contains a Circuit Name and/or Title that are already in use.", "Duplicate Circuit Name: " & CircuitName);
} else {
// i set the parsed Circuit info
Circuits[CircuitName]=Circuit;
}
// i set ParentName (if it is not already set in ParseCircuit)
if(Len(arguments.ParentName) AND NOT StructKeyExists(Circuits[CircuitName], "ParentName")){
Circuits[CircuitName]["ParentName"]=arguments.ParentName;
}
Circuits[CircuitName]["DateLastModified"]=GetDirectorys.DateLastModified;
Circuits[CircuitName]["DirectoryPath"]=arguments.DirectoryPath & GetDirectorys.Name & "/";
Circuits[CircuitName]["RootPath"]=RepeatString("../", ListLen(Circuits[CircuitName]["DirectoryPath"], "/"));
Circuits[CircuitName]["ConfigFileName"]=ConfigFileName;
// i set Inventory.Circuits + 1
if(this.Parameters.EnableLogs){
this.Logs.Inventory.Circuits=this.Logs.Inventory.Circuits + 1;
}
// i recurse the directory
StructAppend(Circuits, ParseCircuits(arguments.TargetDirectory & GetDirectorys.Name & this.Parameters.Delimiters.Directory, arguments.DirectoryPath & GetDirectorys.Name & "/", CircuitName), "No");
}
</cfscript>
</cfif>
</cfif>
</cfloop>
<cfscript>
// LOGS: i set a Logs.ProcessingTime value
if(this.Parameters.EnableLogs){
this.Logs.ProcessingTime.ParseCircuits=GetTickCount() - TickCount;
}
</cfscript>
<cfreturn Circuits>
</cffunction>
<cffunction name="ParseCircuit"
access="private"
hint="I parse out each circuit's components."
output="false"
returntype="struct">
<cfargument name="CircuitNode" type="any">
<cfscript>
// i initialize the local vars
var Circuit=StructNew();
var Attribute="";
var CurrentNode="";
var CurrentFuseAction="";
var Phases="";
var i=0;
var j=0;
</cfscript>
<cfscript>
// i set this Circuit's attributes
Circuit["Access"]="Public";
if(StructKeyExists(arguments.CircuitNode.XMLAttributes, "Access") AND ListFindNoCase(this.Parameters.AccessList, arguments.CircuitNode.XMLAttributes["Access"])){
Circuit.Access=arguments.CircuitNode.XMLAttributes["Access"];
}
// i set Name and Title
if(StructKeyExists(arguments.CircuitNode.XMLAttributes, "name") AND StructKeyExists(arguments.CircuitNode.XMLAttributes, "title")){
Circuit["Name"]=arguments.CircuitNode.XMLAttributes["name"];
Circuit["Title"]=arguments.CircuitNode.XMLAttributes["title"];
} else if(StructKeyExists(arguments.CircuitNode.XMLAttributes, "title")){
Circuit["Name"]=FilterString(arguments.CircuitNode.XMLAttributes["title"]);
Circuit["Title"]=arguments.CircuitNode.XMLAttributes["title"];
} else if(StructKeyExists(arguments.CircuitNode.XMLAttributes, "name")){
Circuit["Name"]=arguments.CircuitNode.XMLAttributes["name"];
} else {
// [!]ERROR HANDLING[!] Throw("MyOpenbox", "Error while processing Circuit configuration file.", "The Title and/or Name attributes need to be declared in the root element of ???.", "I dunno?");
}
// i set Parent
if(StructKeyExists(arguments.CircuitNode.XMLAttributes, "parent")){
Circuit["ParentName"]=arguments.CircuitNode.XMLAttributes["parent"];
}
// i set any other attributes
for(Attribute IN arguments.CircuitNode.XMLAttributes){
// i prevent any attributes from overwriting the Reserved Circuit Attributes
if(NOT ListFindNoCase(this.Parameters.ReservedCircuitAttributes, Attribute)){
Circuit[Attribute]=arguments.CircuitNode.XMLAttributes[Attribute];
}
}
// i set the XML into the Circuit
if(this.Parameters.StoreXML) Circuit.XML=arguments.CircuitNode;
// i check/set a empty struct for FuseActions and Phases
Circuit["FuseActions"]=StructNew();
// i set this Circuit's sub-elements defined values
for(i=1; i LTE ArrayLen(arguments.CircuitNode.XMLChildren); i=i + 1){
// i route the child elements of this Circuit
switch(arguments.CircuitNode.XMLChildren[i]["XMLName"]){
// i parse FuseAction elements
case "fuseaction" :
StructAppend(Circuit.FuseActions, ParseFuseAction(arguments.CircuitNode.XMLChildren[i], Circuit));
break;
// i parse the FuseActions element
case "fuseactions" :
// i loop through the child elements
for(j=1; j LTE ArrayLen(arguments.CircuitNode.XMLChildren[i].XMLChildren); j=j + 1){
// i route the child elements
switch(arguments.CircuitNode.XMLChildren[i].XMLChildren[j]["XMLName"]){
case "fuseaction" :
// i parse the FuseAction
StructAppend(Circuit.FuseActions, ParseFuseAction(arguments.CircuitNode.XMLChildren[i].XMLChildren[j], Circuit));
break;
}
}
break;
// i parse the Phases element
case "phases" :
Circuit["Phases"]=ParseCircuitPhases(arguments.CircuitNode.XMLChildren[i], Circuit.Name);
break;
// i save the Settings element
case "settings" :
// i create an empty Settings struct for checking existence
Circuit["Settings"]=StructNew();
// i save the XML for parsing during Circuit calls
Circuit["SettingsXML"]=arguments.CircuitNode.XMLChildren[i];
break;
}
}
</cfscript>
<cfreturn Circuit>
</cffunction>
<cffunction name="ParseFuseAction"
access="private"
hint="I parse out the MyOpenbox configuration XML Phases."
output="false"
returntype="struct">
<cfargument name="CurrentNode" type="any">
<cfargument name="Circuit" type="any">
<cfscript>
// i initialize the local vars
var FuseAction=StructNew();
var FuseActionName="";
var Attribute="";
</cfscript>
<cfscript>
// i set Name and Title
if(StructKeyExists(arguments.CurrentNode.XMLAttributes, "title")){
if(StructKeyExists(arguments.CurrentNode.XMLAttributes, "name")){
FuseActionName=arguments.CurrentNode.XMLAttributes["name"];
} else {
FuseActionName=FilterString(arguments.CurrentNode.XMLAttributes["title"]);
}
FuseAction[FuseActionName]["Name"]=FuseActionName;
FuseAction[FuseActionName]["Title"]=arguments.CurrentNode.XMLAttributes["title"];
} else if(StructKeyExists(arguments.CurrentNode.XMLAttributes, "name")){
FuseActionName=arguments.CurrentNode.XMLAttributes["name"];
FuseAction[FuseActionName]["Name"]=FuseActionName;
} else {
// [!]ERROR HANDLING[!] Throw("MyOpenbox", "Error while processing Circuit configuration file.", "The Title and/or Name attributes need to be declared in the each FuseAction element of ???.", "I dunno?");
}
// i set this element's XML Commands
FuseAction[FuseActionName]["Commands"]=arguments.CurrentNode["XMLChildren"];
// i loop through this element's attributes
for(Attribute IN arguments.CurrentNode.XMLAttributes){
// i prevent any attributes from overwriting the Reserved FuseAction Attributes
if(NOT ListFindNoCase(this.Parameters.ReservedFuseActionAttributes, Attribute)){
FuseAction[FuseActionName][Attribute]=arguments.CurrentNode["XMLAttributes"][Attribute];
}
}
// i set this element's Access to inherit this Circuit's Access if not defined or is an illegal value
if(NOT StructKeyExists(FuseAction[FuseActionName], "Access") OR NOT ListFindNoCase(this.Parameters.AccessList, FuseAction[FuseActionName]["Access"])){
FuseAction[FuseActionName]["Access"]=arguments.Circuit.Access;
}
// i set FuseActions
if(this.Parameters.EnableLogs){
this.Logs.Inventory.FuseActions=this.Logs.Inventory.FuseActions + 1;
}
</cfscript>
<cfreturn FuseAction>
</cffunction>
<cffunction name="ParseCircuitPhases"
access="private"
hint="I parse out the MyOpenbox configuration XML Phases."
output="false"
returntype="struct">
<cfargument name="PhaseDeclarations" type="any">
<cfargument name="CircuitName" type="string">
<cfscript>
// i initialize the local vars
var CurrentNode="";
var CurrentPhase=StructNew();
var Phases=StructNew();
var PhaseName="";
var i=0;
var Attribute="";
</cfscript>
<cfscript>
// i loop through the XMLChilden
for(i=1; i LTE ArrayLen(arguments.PhaseDeclarations.XMLChildren); i=i + 1){
// i set a reference for the current node
CurrentNode=arguments.PhaseDeclarations.XMLChildren[i];
// i set PhaseName
if(StructKeyExists(CurrentNode.XMLAttributes, "title") AND NOT StructKeyExists(CurrentNode.XMLAttributes, "name")){
PhaseName=FilterString(CurrentNode.XMLAttributes.title);
} else {
PhaseName=CurrentNode.XMLAttributes.name;
}
// i set a reference to the Phase into the return Circuit Phases structure
if(ListFindNoCase(this.Parameters.CircuitPhases, PhaseName)){
Phases[PhaseName]["Attributes"]=CurrentNode["XMLAttributes"];
Phases[PhaseName]["Commands"]=CurrentNode["XMLChildren"];
} else {
// if the target Phase does not exist yet
if(NOT StructKeyExists(this.Phases, PhaseName) OR NOT IsArray(this.Phases[PhaseName])){
// ...i create the empty array
this.Phases[PhaseName]=ArrayNew(1);
ArrayAppend(this.CustomPhases, PhaseName);
}
// i set the CircuitName
this.Phases[PhaseName][ArrayLen(this.Phases[PhaseName]) + 1]["CircuitName"]=arguments.CircuitName;
// i set the Commands
this.Phases[PhaseName][ArrayLen(this.Phases[PhaseName])]["Commands"]=CurrentNode["XMLChildren"];
}
}
</cfscript>
<cfreturn Phases>
</cffunction>
<cffunction name="CreateAllCircuitAndFuseactionFiles"
access="public"
output="false"
returnType="void">
<cfscript>
var CircuitValue="";
var FuseValue="";
</cfscript>
<cfloop collection="#this.Circuits#" item="CircuitValue">
<cfset CreateCircuitFiles(this.Circuits[CircuitValue]) />
<cfloop collection="#this.Circuits[CircuitValue]["Fuseactions"]#" item="FuseValue">
<cfset CreateFuseActionFile(this.Circuits[CircuitValue], this.Circuits[CircuitValue]["Fuseactions"][FuseValue]) />
</cfloop>
</cfloop>
<cfset CreatePhaseFiles(ArrayToList(this.CustomPhases, ",")) />
</cffunction>
<cffunction name="CreateCircuitFiles"
access="private"
hint="."
output="false"
returntype="void">
<cfargument name="Circuit" type="struct">
<cfscript>
// i create the Settings file
if(StructKeyExists(arguments.Circuit, "SettingsXML")){
CreateSettingsFile("Circuit", arguments.Circuit.SettingsXML, arguments.Circuit.Name);
StructDelete(arguments.Circuit, "SettingsXML");
}
// i create the Phase files
if(StructKeyExists(arguments.Circuit, "Phases")){
CreateCircuitPhaseFiles(arguments.Circuit);
}
// i set a TimeStamp to keep this Circuit current with MyOpenbox and to prevent duplicate/extra file writes
arguments.Circuit["TimeStamp"]=this.TimeStamp;
</cfscript>
</cffunction>
<cffunction name="ParseSettingValue"
access="private"
hint="."
output="false"
returntype="struct">
<cfargument name="CurrentNode" type="any">
<cfscript>
var Setting=StructNew();
var ThrowError=False;
</cfscript>
<cfscript>
// i clear out the name/value holder Setting
Setting=StructNew();
// i check for Name
if(StructKeyExists(arguments.CurrentNode["XMLAttributes"], "name")){
Setting.Name=arguments.CurrentNode["XMLAttributes"]["name"];
} else {
ThrowError=True;
}
// i check for a Value
if(StructKeyExists(arguments.CurrentNode["XMLAttributes"], "value")){
Setting.Value=arguments.CurrentNode["XMLAttributes"]["value"];
} else if(Len(arguments.CurrentNode["XMLText"])){
Setting.Value=arguments.CurrentNode["XMLText"];
} else {
ThrowError=True;
}
if(StructKeyExists(arguments.CurrentNode["XMLAttributes"], "env")){
Setting.Env=arguments.CurrentNode["XMLAttributes"]["env"];
}
// ERROR: i throw an error if necessary
if(ThrowError){
Throw("MyOpenbox", "Error while processing Settings.", "Please make sure all required attributes are included and valid in each Setting definition in the MyOpenbox configuration file.");
}
</cfscript>
<cfreturn Setting>
</cffunction>
<cffunction name="CreateSettingsFile"
access="private"
hint="."
output="false"
returntype="void">
<cfargument name="Type" type="string">
<cfargument name="CurrentNode" type="any" default="">
<cfargument name="CircuitName" type="string" default="">
<cfargument name="FilePath" type="string" default="#GetDirectoryFromPath(GetBaseTemplatePath())#">
<cfscript>
// i initialize the local vars
var GeneratedContent=CreateObject("java", "java.lang.StringBuffer").init();
var ContainerVariable="";
var FileName="";
var Include=StructNew();
var Setting=StructNew();
var i=0;
var ii=0;
var NewLine=this.Parameters.Delimiters.NewLine;
var TickCount=GetTickCount();
</cfscript>
<cfif this.Parameters.ProcessingMode NEQ "Deployment" OR (this.IsFWreparse() OR this.IsFWReinit())>
<cfscript>
if(arguments.Type EQ "MyOpenbox"){
ContainerVariable=this.Parameters.MyOpenboxObjectVariable;
FileName="settings";
} else if(arguments.Type EQ "Circuit"){
ContainerVariable=this.Parameters.MyOpenboxObjectVariable & ".Circuits." & arguments.CircuitName;
FileName="settings." & arguments.CircuitName;
}
GeneratedContent.append(JavaCast("string", "<" & "cfsilent>" & NewLine));
GeneratedContent.append(JavaCast("string", "<" & "cfif StructIsEmpty(" & ContainerVariable & ".Settings)>" & NewLine));
GeneratedContent.append(JavaCast("string", Indent() & "<" & "cflock name=""##Hash(GetCurrentTemplatePath())##_SetSettings"" timeout=""10"">" & NewLine));
GeneratedContent.append(JavaCast("string", Indent(2) & "<" & "cfscript>" & NewLine));
GeneratedContent.append(JavaCast("string", Indent(2) & "if(StructIsEmpty(" & ContainerVariable & ".Settings)){" & NewLine));
GeneratedContent.append(JavaCast("string", Indent(3) & "// i create the designated Circuit's Settings" & NewLine));
// i determine if arguments.CurrentNode is available
if(IsXMLElem(arguments.CurrentNode) AND StructKeyExists(arguments.CurrentNode, "XMLChildren")){
for(i=1; i LTE ArrayLen(arguments.CurrentNode.XMLChildren); i=i + 1){
// if this is a Setting command
if(arguments.CurrentNode.XMLChildren[i]["XMLName"] EQ "setting"){
if(StructKeyExists(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"], "include")){
// i read and parse the settings file
Include.Prefix = "";
Include.Suffix = "";
Include.FileName = arguments.CurrentNode.XMLChildren[i]["XMLAttributes"]["include"];
if (StructKeyExists(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"], "env")) {
Include.FileName = this.GetEnv(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"]['env'], Include.FileName);
}
if (StructKeyExists(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"], "prefix") AND Len(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"]["prefix"]) GT 0) {
Include.Prefix = arguments.CurrentNode.XMLChildren[i]["XMLAttributes"]["prefix"];
}
if (StructKeyExists(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"], "suffix") AND Len(arguments.CurrentNode.XMLChildren[i]["XMLAttributes"]["suffix"]) GT 0) {
Include.Suffix = arguments.CurrentNode.XMLChildren[i]["XMLAttributes"]["suffix"];
}
Include.FileName = arguments.FilePath & Include.Prefix & Include.FileName & Include.Suffix & ".cfm";
Include.Raw = Read(Include.FileName);
if(Len(Include.Raw)){
Include.Parsed = XMLParse(Include.Raw);
for(ii=1; ii LTE ArrayLen(Include.Parsed.XmlRoot.XMLChildren); ii=ii + 1){
GeneratedContent.append(JavaCast("string", CreateSetting(ContainerVariable, Include.Parsed.XmlRoot.XMLChildren[ii], 3)));
}
}
} else {
GeneratedContent.append(JavaCast("string", CreateSetting(ContainerVariable, arguments.CurrentNode.XMLChildren[i], 3)));
}
} else {
// ERROR: i throw an error if necessary
Throw("MyOpenbox", "Error while processing Settings.", "Please make sure only <setting .../> verbs are used in each Setting definition in the MyOpenbox configuration file.");
}
}
}
GeneratedContent.append(JavaCast("string", Indent(2) & "}" & NewLine));
GeneratedContent.append(JavaCast("string", Indent(2) & "<" & "/cfscript>" & NewLine));
GeneratedContent.append(JavaCast("string", Indent() & "<" & "/cflock>" & NewLine));
GeneratedContent.append(JavaCast("string", "<" & "/cfif>" & NewLine));
GeneratedContent.append(JavaCast("string", "<" & "/cfsilent>" & NewLine));