-
Notifications
You must be signed in to change notification settings - Fork 9
/
framework.cfc
1560 lines (1301 loc) · 53.8 KB
/
framework.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><cfscript>
/*
Copyright (c) 2009-2010, Sean Corfield, Ryan Cogswell
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
this.name = hash( getCurrentTemplatePath() );
function actionSpecifiesSubsystem( action ) {
if ( not usingSubsystems() ) {
return false;
}
return listLen( action, variables.framework.subsystemDelimiter ) gt 1 or right( action, 1 ) eq variables.framework.subsystemDelimiter;
}
</cfscript><cfsilent>
<!---
buildURL() should be used from views to construct urls when using subsystems or
in order to provide a simpler transition to using subsystems in the future
--->
<cffunction name="buildURL" access="public" output="false">
<cfargument name="action" type="string" />
<cfargument name="path" type="string" default="#variables.framework.baseURL#" />
<cfargument name="queryString" type="string" default="" />
<cfset var initialDelim = '?' />
<cfset var varDelim = '&' />
<cfset var equalDelim = '=' />
<cfset var basePath = '' />
<cfset var extraArgs = '' />
<cfset var queryPart = '' />
<cfset var anchor = '' />
<cfset var ses = false />
<cfset var omitIndex = false />
<cfif arguments.path eq "useCgiScriptName">
<cfset arguments.path = CGI.SCRIPT_NAME />
<cfif variables.framework.SESOmitIndex>
<cfset arguments.path = getDirectoryFromPath( arguments.path ) />
<cfset omitIndex = true />
</cfif>
<cfelseif arguments.path eq "useRequestURI">
<cfset arguments.path = getPageContext().getRequest().getRequestURI() />
<cfif variables.framework.SESOmitIndex>
<cfset arguments.path = getDirectoryFromPath( arguments.path ) />
<cfset omitIndex = true />
</cfif>
</cfif>
<cfif find( '?', arguments.action ) and arguments.queryString is ''>
<!--- shorthand for action/queryString pairing --->
<cfset arguments.queryString = REReplace( arguments.action, '[^\?]*\?', '') />
<cfset arguments.action = REReplace( arguments.action, '([^\?\##]*).*', '\1') />
</cfif>
<cfif find( '?', arguments.path ) gt 0>
<cfif right( arguments.path, 1 ) eq '?' or right( arguments.path, 1 ) eq '&'>
<cfset initialDelim = '' />
<cfelse>
<cfset initialDelim = '&' />
</cfif>
<cfelseif structKeyExists( request, 'generateSES' ) and request.generateSES>
<cfif omitIndex>
<cfset initialDelim = '' />
<cfelse>
<cfset initialDelim = '/' />
</cfif>
<cfset varDelim = '/' />
<cfset equalDelim = '/' />
<cfset ses = true />
</cfif>
<cfif ses>
<cfset basePath = arguments.path & initialDelim & replace( getFullyQualifiedAction( arguments.action ), '.', '/' ) />
<cfelse>
<cfset basePath = arguments.path & initialDelim & variables.framework.action & equalDelim & getFullyQualifiedAction(arguments.action) />
</cfif>
<cfif len( arguments.queryString )>
<cfset extraArgs = REReplace( arguments.queryString, '([^\?\##]*).*', '\1') />
<cfif find( '?', arguments.queryString )>
<cfset queryPart = REReplace( arguments.queryString, '[^\?]*\?([^\##]*).*', '\1') />
</cfif>
<cfif find( '##', arguments.queryString )>
<cfset anchor = REReplace( arguments.queryString, '[^\##]*\##(.*)', '\1' ) />
</cfif>
<cfif ses>
<cfset extraArgs = listChangeDelims( extraArgs, '/', '&=' ) />
</cfif>
<cfif extraArgs is not ''>
<cfset basePath = basePath & varDelim & extraArgs />
</cfif>
<cfif queryPart is not ''>
<cfif ses>
<cfset basePath = basePath & '?' & queryPart />
<cfelse>
<cfset basePath = basePath & '&' & queryPart />
</cfif>
</cfif>
<cfif anchor is not ''>
<cfset basePath = basePath & '##' & anchor />
</cfif>
</cfif>
<cfreturn basePath />
</cffunction>
</cfsilent><cfscript>
/*
* call this from your Application.cfc methods to queue up additional controller
* method calls at the start of the request
*/
function controller( action ) {
var subsystem = getSubsystem( action );
var section = getSection( action );
var item = getItem( action );
var tuple = structNew();
if ( structKeyExists( request, 'controllerExecutionStarted' ) ) {
raiseException( type="FW1.controllerExecutionStarted", message="Controller '#action#' may not be added at this point.",
detail="The controller execution phase has already started. Controllers may not be added by other controller methods." );
}
tuple.controller = getController( section = section, subsystem = subsystem );
tuple.key = subsystem & variables.framework.subsystemDelimiter & section;
tuple.item = item;
if ( structKeyExists( tuple, "controller" ) and isObject( tuple.controller ) ) {
if ( not structKeyExists( request, 'controllers' ) ) {
request.controllers = arrayNew(1);
}
arrayAppend( request.controllers, tuple );
}
}
/*
* can be overridden to customize how views and layouts are found - can be
* used to provide skinning / common views / layouts etc
*/
function customizeViewOrLayoutPath( pathInfo, type, fullPath ) {
// fullPath is: '#pathInfo.base##type#s/#pathInfo.path#.cfm'
return fullPath;
}
/*
* return the action URL variable name - allows applications to build URLs
*/
function getAction() {
return variables.framework.action;
}
</cfscript><cfsilent>
<!---
returns whatever the framework has been told is a bean factory
this will return a subsystem-specific bean factory if one
exists for the current request's subsystem (or for the specified subsystem
if passed in)
--->
<cffunction name="getBeanFactory" output="false">
<cfargument name="subsystem" required="false" default="" />
<cfscript>
if ( len(subsystem) gt 0 ) {
if ( hasSubsystemBeanFactory(subsystem) ) {
return getSubsystemBeanFactory(subsystem);
}
return getDefaultBeanFactory();
}
if ( not usingSubsystems() ) {
return getDefaultBeanFactory();
}
if ( structKeyExists( request, 'subsystem' ) and len(request.subsystem) gt 0 ) {
return getBeanFactory(request.subsystem);
}
if ( len(variables.framework.defaultSubsystem) gt 0 ) {
return getBeanFactory(variables.framework.defaultSubsystem);
}
return getDefaultBeanFactory();
</cfscript>
</cffunction>
</cfsilent><cfscript>
function getConfig()
{
// return a copy to make it read only from outside the framework:
return structCopy( framework );
}
/*
* returns the bean factory set via setBeanFactory
*/
function getDefaultBeanFactory() {
return application[ variables.framework.applicationKey ].factory;
}
/*
* returns the name of the default subsystem
*/
function getDefaultSubsystem() {
if ( not usingSubsystems() ) {
return '';
}
if ( structKeyExists( request, 'subsystem' ) ) {
return request.subsystem;
}
if ( variables.framework.defaultSubsystem eq "" ) {
raiseException( type="FW1.subsystemNotSpecified", message="No subsystem specified and no default configured.",
detail="When using subsystems, every request should specify a subsystem or variables.framework.defaultSubsystem should be configured." );
}
return variables.framework.defaultSubsystem;
}
</cfscript><cfsilent>
<!---
return an action with all applicable parts (subsystem, section, and item) specified
using defaults from the configuration or request where appropriate
--->
<cffunction name="getFullyQualifiedAction" output="false">
<cfargument name="action" default="#request.action#" />
<cfscript>
if ( usingSubsystems() ) {
return getSubsystem( action ) & variables.framework.subsystemDelimiter & getSectionAndItem( action );
}
return getSectionAndItem( action );
</cfscript>
</cffunction>
<!--- return the item part of the action --->
<cffunction name="getItem" output="false">
<cfargument name="action" default="#request.action#" />
<cfreturn listLast( getSectionAndItem( arguments.action ), '.' ) />
</cffunction>
<!--- return the section part of the action --->
<cffunction name="getSection" output="false">
<cfargument name="action" default="#request.action#" />
<cfreturn listFirst( getSectionAndItem( arguments.action ), '.' ) />
</cffunction>
<!--- return the action without the subsystem --->
<cffunction name="getSectionAndItem" output="false">
<cfargument name="action" default="#request.action#" />
<cfscript>
var sectionAndItem = '';
if ( usingSubsystems() and actionSpecifiesSubsystem( action ) ) {
if ( listLen( action, variables.framework.subsystemDelimiter ) gt 1 ) {
sectionAndItem = listLast( action, variables.framework.subsystemDelimiter );
}
} else {
sectionAndItem = action;
}
if ( len( sectionAndItem ) eq 0 ) {
sectionAndItem = variables.framework.defaultSection & '.' & variables.framework.defaultItem;
} else if ( listLen( sectionAndItem, '.' ) eq 1 ) {
if ( left( sectionAndItem, 1 ) eq '.' ) {
sectionAndItem = variables.framework.defaultSection & '.' & listLast( sectionAndItem, '.' );
} else {
sectionAndItem = listFirst( sectionAndItem, '.' ) & '.' & variables.framework.defaultItem;
}
} else {
sectionAndItem = listFirst( sectionAndItem, '.' ) & '.' & listLast( sectionAndItem, '.' );
}
return sectionAndItem;
</cfscript>
</cffunction>
</cfsilent><cfscript>
/*
* return the default service result key
* override this if you want the default service result to be
* stored under a different request context key, based on the
* requested action, e.g., return getSection( action );
*/
function getServiceKey( action ) {
return "data";
}
</cfscript><cfsilent>
<!--- return the subsystem part of the action --->
<cffunction name="getSubsystem" output="false">
<cfargument name="action" default="#request.action#" />
<cfif actionSpecifiesSubsystem( arguments.action ) >
<cfreturn listFirst( arguments.action, variables.framework.subsystemDelimiter ) />
</cfif>
<cfreturn getDefaultSubsystem() />
</cffunction>
</cfsilent><cfscript>
/*
* returns the bean factory set via setSubsystemBeanFactory
* same effect as getBeanFactory when not using subsystems
*/
function getSubsystemBeanFactory( subsystem ) {
setupSubsystemWrapper( subsystem );
return application[ variables.framework.applicationKey ].subsystemFactories[ subsystem ];
}
/*
* returns true iff a call to getBeanFactory() will successfully return a bean factory
* previously set via setBeanFactory or setSubsystemBeanFactory
*/
function hasBeanFactory() {
if ( hasDefaultBeanFactory() ) {
return true;
}
if ( not usingSubsystems() ) {
return false;
}
if ( structKeyExists( request, 'subsystem' ) ) {
return hasSubsystemBeanFactory(request.subsystem);
}
if ( len(variables.framework.defaultSubsystem) gt 0 ) {
return hasSubsystemBeanFactory(variables.framework.defaultSubsystem);
}
return false;
}
/*
* returns true iff the framework has been told about a bean factory via setBeanFactory
*/
function hasDefaultBeanFactory() {
return structKeyExists( application[ variables.framework.applicationKey ], 'factory' );
}
/*
* returns true if a subsystem specific bean factory has been set
*/
function hasSubsystemBeanFactory( subsystem ) {
ensureNewFrameworkStructsExist();
return structKeyExists( application[ variables.framework.applicationKey ].subsystemFactories, subsystem );
}
/*
* layout() may be invoked inside layouts
* returns the UI generated by the named layout and body
*/
function layout( path, body ) {
var layoutPath = parseViewOrLayoutPath( arguments.path, 'layout' );
return internalLayout( layoutPath, body );
}
/*
* it is better to set up your application configuration in
* your setupApplication() method since that is called on a
* framework reload
* if you do override onApplicationStart(), you must call
* super.onApplicationStart() first
*/
function onApplicationStart() {
setupFrameworkDefaults();
setupRequestDefaults();
setupApplicationWrapper();
}
/*
* can be overridden, calling super.onError(exception,event) is optional
* depending on what error handling behavior you want
* note: you need to rename / disable onError() on OpenBD since it does
* not seem to be passed exception or event correctly when something fails
* in the code...
*/
function onError( exception, event ) {
try {
// record details of the exception:
if ( structKeyExists( request, 'action' ) ) {
request.failedAction = request.action;
}
request.exception = exception;
request.event = event;
// reset lifecycle flags:
structDelete( request, 'controllerExecutionComplete' );
structDelete( request, 'controllerExecutionStarted' );
structDelete( request, 'serviceExecutionComplete' );
// setup the new controller action, based on the error action:
structDelete( request, 'controllers' );
request.action = variables.framework.error;
setupRequestWrapper( false );
onRequest( '' );
} catch ( any e ) {
failure( exception, event );
}
}
/*
* this can be overridden if you want to change the behavior when
* FW/1 cannot find a matching view
*/
function onMissingView( rc ) {
// unable to find a matching view - fail with a nice exception
viewNotFound();
// if we got here, we would return the string to be rendered
// but viewNotFound() throws an exception...
}
/*
* This can be overridden if you want to change the behavior when
* FW/1 encounters an error when trying to populate bean properties
* using all of the keys in the request context (rather than a
* specific list of keys). By default FW/1 silently ignores these errors.
* Available in the arguments are the bean cfc and the property that was
* being set when the error occurred as well as the request context structure.
* You can also reference the cfcatch variable for details about the error.
*/
function onPopulateError( cfc, property, rc ) {
}
/*
* not intended to be overridden, automatically deleted for CFC requests
*/
function onRequest(targetPath) {
var out = 0;
var i = 0;
var tuple = 0;
var _data_fw1 = 0;
var once = structNew();
request.controllerExecutionStarted = true;
if ( structKeyExists( request, 'controllers' ) ) {
for ( i = 1; i lte arrayLen( request.controllers ); i = i + 1 ) {
tuple = request.controllers[ i ];
// run before once per controller:
if ( not structKeyExists( once, tuple.key ) ) {
once[ tuple.key ] = i;
doController( tuple.controller, 'before' );
}
doController( tuple.controller, 'start' & tuple.item );
doController( tuple.controller, tuple.item );
}
}
for ( i = 1; i lte arrayLen( request.services ); i = i + 1 ) {
tuple = request.services[i];
if ( tuple.key is '' ) {
// throw the result away:
doService( tuple.service, tuple.item, tuple.args, tuple.enforceExistence );
} else {
_data_fw1 = doService( tuple.service, tuple.item, tuple.args, tuple.enforceExistence );
if ( isDefined('_data_fw1') ) {
request.context[ tuple.key ] = _data_fw1;
}
}
}
request.serviceExecutionComplete = true;
if ( structKeyExists( request, 'controllers' ) ) {
for ( i = arrayLen( request.controllers ); i gte 1; i = i - 1 ) {
tuple = request.controllers[ i ];
doController( tuple.controller, 'end' & tuple.item );
// run after once per controller:
if ( once[ tuple.key ] eq i ) {
doController( tuple.controller, 'after' );
}
}
}
request.controllerExecutionComplete = true;
buildViewAndLayoutQueue();
if ( structKeyExists(request, 'view') ) {
out = internalView( request.view );
} else {
out = onMissingView( request.context );
}
for ( i = 1; i lte arrayLen(request.layouts); i = i + 1 ) {
if ( structKeyExists(request, 'layout') and not request.layout ) {
break;
}
out = internalLayout( request.layouts[i], out );
}
writeOutput( out );
}
/*
* it is better to set up your request configuration in
* your setupRequest() method
* if you do override onRequestStart(), you must call
* super.onRequestStart() first
*/
function onRequestStart(targetPath) {
var pathInfo = CGI.PATH_INFO;
var sesIx = 0;
var sesN = 0;
setupFrameworkDefaults();
setupRequestDefaults();
if ( not isFrameworkInitialized() or isFrameworkReloadRequest() ) {
setupApplicationWrapper();
}
if ( not structKeyExists(request, 'context') ) {
request.context = structNew();
}
// SES URLs by popular request :)
if ( len( pathInfo ) gt len( CGI.SCRIPT_NAME ) and left( pathInfo, len( CGI.SCRIPT_NAME ) ) is CGI.SCRIPT_NAME ) {
// canonicalize for IIS:
pathInfo = right( pathInfo, len( pathInfo ) - len( CGI.SCRIPT_NAME ) );
} else if ( len( pathInfo ) gt 0 and pathInfo is left( CGI.SCRIPT_NAME, len( pathInfo ) ) ) {
// pathInfo is bogus so ignore it:
pathInfo = '';
}
try {
// we use .split() to handle empty items in pathInfo - we fallback to listToArray() on
// any system that doesn't support .split() just in case (empty items won't work there!)
if ( len( pathInfo ) gt 1 ) {
pathInfo = right( pathInfo, len( pathInfo ) - 1 ).split( '/' );
} else {
pathInfo = arrayNew( 1 );
}
} catch ( any exception ) {
pathInfo = listToArray( pathInfo, '/' );
}
sesN = arrayLen( pathInfo );
if ( ( sesN gt 0 or variables.framework.generateSES ) and variables.framework.baseURL is not 'useRequestURI' ) {
request.generateSES = true;
}
for ( sesIx = 1; sesIx lte sesN; sesIx = sesIx + 1 ) {
if ( sesIx eq 1 ) {
request.context[variables.framework.action] = pathInfo[sesIx];
} else if ( sesIx eq 2 ) {
request.context[variables.framework.action] = pathInfo[sesIx-1] & '.' & pathInfo[sesIx];
} else if ( sesIx mod 2 eq 1 ) {
request.context[ pathInfo[sesIx] ] = '';
} else {
request.context[ pathInfo[sesIx-1] ] = pathInfo[sesIx];
}
}
// certain remote calls do not have URL or form scope:
if ( isDefined('URL') ) structAppend(request.context,URL);
if ( isDefined('form') ) structAppend(request.context,form);
restoreFlashContext();
if ( not structKeyExists(request.context, variables.framework.action) ) {
request.context[variables.framework.action] = variables.framework.home;
} else {
request.context[variables.framework.action] = getFullyQualifiedAction( request.context[variables.framework.action] );
}
request.action = lCase(request.context[variables.framework.action]);
setupRequestWrapper( true );
// allow configured extensions and paths to pass through to the requested template.
// NOTE: for unhandledPaths, we make the list into an escaped regular expression so we match on subdirectories. Meaning /myexcludepath will match "/myexcludepath" and all subdirectories
if ( listFindNoCase( framework.unhandledExtensions, listLast( arguments.targetPath, "." ) ) or
REFindNoCase( "^(" & framework.unhandledPathRegex & ")", arguments.targetPath ) ) {
structDelete(this, 'onRequest');
structDelete(variables, 'onRequest');
}
}
/*
* it is better to set up your session configuration in
* your setupSession() method
* if you do override onSessionStart(), you must call
* super.onSessionStart() first
*/
function onSessionStart() {
setupFrameworkDefaults();
setupRequestDefaults();
setupSession();
}
</cfscript><cfsilent>
<!---
populate() may be invoked inside controllers
--->
<cffunction name="populate" returntype="any" access="public" output="false"
hint="Used to populate beans from the request context.">
<cfargument name="cfc" />
<cfargument name="keys" default="" />
<cfargument name="trustKeys" default="false" />
<cfargument name="trim" default="false" />
<cfset var key = 0 />
<cfset var property = 0 />
<cfset var trimProperty = 0 />
<cfset var args = 0 />
<cfif arguments.keys is "">
<cfif arguments.trustKeys>
<!--- assume everything in the request context can be set into the CFC --->
<cfloop item="property" collection="#request.context#">
<cfset key = "set" & property />
<cftry>
<cfset args = structNew() />
<cfset args[ property ] = request.context[ property ] />
<cfif arguments.trim and isSimpleValue( args[property] )><cfset args[property] = trim( args[property] ) /></cfif>
<cfinvoke component="#arguments.cfc#" method="#key#" argumentCollection="#args#" />
<cfcatch type="any">
<cfset onPopulateError( arguments.cfc, property, request.context ) />
</cfcatch>
</cftry>
</cfloop>
<cfelse>
<cfloop item="key" collection="#arguments.cfc#">
<cfif len( key ) gt 3 and left( key, 3 ) is "set">
<cfset property = right( key, len( key ) - 3 ) />
<cfif structKeyExists( request.context, property )>
<cfset args = structNew() />
<cfset args[ property ] = request.context[ property ] />
<cfif arguments.trim and isSimpleValue( args[property] )><cfset args[property] = trim( args[property] ) /></cfif>
<cfinvoke component="#arguments.cfc#" method="#key#" argumentCollection="#args#" />
</cfif>
</cfif>
</cfloop>
</cfif>
<cfelse>
<cfloop index="property" list="#arguments.keys#">
<cfset trimProperty = trim( property ) />
<cfset key = "set" & trimProperty />
<cfif structKeyExists( arguments.cfc, key ) or arguments.trustKeys>
<cfif structKeyExists( request.context, trimProperty )>
<cfset args = structNew() />
<cfset args[ trimProperty ] = request.context[ trimProperty ] />
<cfif arguments.trim and isSimpleValue( args[trimProperty] )><cfset args[trimProperty] = trim( args[trimProperty] ) /></cfif>
<cfinvoke component="#arguments.cfc#" method="#key#" argumentCollection="#args#" />
</cfif>
</cfif>
</cfloop>
</cfif>
<cfreturn arguments.cfc />
</cffunction>
<!---
redirect() may be invoked inside controllers
--->
<cffunction name="redirect" access="public" output="false"
hint="Redirect to the specified action, optionally append specified request context items - or use session.">
<cfargument name="action" type="string" />
<cfargument name="preserve" type="string" default="none" />
<cfargument name="append" type="string" default="none" />
<cfargument name="path" type="string" default="#variables.framework.baseURL#" />
<cfargument name="queryString" type="string" default="" />
<cfset var baseQueryString = "" />
<cfset var key = "" />
<cfset var preserveKey = "" />
<cfif arguments.preserve is not "none">
<cfset preserveKey = saveFlashContext( arguments.preserve ) />
<cfif variables.framework.maxNumContextsPreserved gt 1>
<cfset baseQueryString = "#variables.framework.preserveKeyURLKey#=#preserveKey#">
</cfif>
</cfif>
<cfif arguments.append is not "none">
<cfif arguments.append is "all">
<cfloop item="key" collection="#request.context#">
<cfif isSimpleValue( request.context[key] )>
<cfset baseQueryString = listAppend( baseQueryString, key & "=" & urlEncodedFormat( request.context[key] ), '&' ) />
</cfif>
</cfloop>
<cfelse>
<cfloop index="key" list="#arguments.append#">
<cfif structKeyExists( request.context, key ) and isSimpleValue( request.context[key] )>
<cfset baseQueryString = listAppend( baseQueryString, key & "=" & urlEncodedFormat( request.context[key] ), '&' ) />
</cfif>
</cfloop>
</cfif>
</cfif>
<cfif baseQueryString is not ''>
<cfif arguments.queryString is not ''>
<cfif left( arguments.queryString, 1 ) is '?' or left( arguments.queryString, 1 ) is '##'>
<cfset baseQueryString = baseQueryString & arguments.queryString />
<cfelse>
<cfset baseQueryString = baseQueryString & '&' & arguments.queryString />
</cfif>
</cfif>
<cfelse>
<cfset baseQueryString = arguments.queryString />
</cfif>
<cflocation url="#buildURL( arguments.action, arguments.path, baseQueryString )#" addtoken="false" />
</cffunction>
<!--- call this from your controller to queue up additional services --->
<cffunction name="service" output="false">
<cfargument name="action" />
<cfargument name="key" />
<cfargument name="args" default="#structNew()#" />
<cfargument name="enforceExistence" required="false" default="true" />
<cfscript>
var subsystem = getSubsystem( action );
var section = getSection( action );
var item = getItem( action );
var tuple = structNew();
if ( structKeyExists( request, "serviceExecutionComplete" ) ) {
raiseException( type="FW1.serviceExecutionComplete", message="Service '#action#' may not be added at this point.",
detail="The service execution phase is complete. Services may not be added by end*() or after() controller methods." );
}
tuple.service = getService(section=section, subsystem=subsystem);
tuple.item = item;
tuple.key = key;
tuple.args = args;
tuple.enforceExistence = enforceExistence;
if ( structKeyExists( tuple, "service" ) and isObject( tuple.service ) ) {
arrayAppend( request.services, tuple );
} else if ( enforceExistence ) {
raiseException( type="FW1.serviceCfcNotFound", message="Service '#action#' does not exist.",
detail="To have the execution of this service be conditional based upon its existence, pass in a third parameter of 'false'." );
}
</cfscript>
</cffunction>
</cfsilent><cfscript>
/*
* call this from your setupApplication() method to tell the framework
* about your bean factory - only assumption is that it supports:
* - containsBean(name) - returns true if factory contains that named bean, else false
* - getBean(name) - returns the named bean
*/
function setBeanFactory( factory ) {
application[ variables.framework.applicationKey ].factory = factory;
}
/*
* call this from your setupSubsystem() method to tell the framework
* about your subsystem-specific bean factory - only assumption is that it supports:
* - containsBean(name) - returns true if factory contains that named bean, else false
* - getBean(name) - returns the named bean
*/
function setSubsystemBeanFactory( subsystem, factory ) {
ensureNewFrameworkStructsExist();
application[ variables.framework.applicationKey ].subsystemFactories[ subsystem ] = factory;
}
/*
* override this to provide application-specific initialization
* if you want the framework to use a bean factory and autowire
* controllers and services, call setBeanFactory(factory) in your
* setupApplication() method
* you do not need to call super.setupApplication()
*/
function setupApplication() { }
/*
* override this to provide request-specific initialization
* you do not need to call super.setupRequest()
*/
function setupRequest() { }
/*
* override this to provide session-specific initialization
* you do not need to call super.setupSession()
*/
function setupSession() { }
/*
* override this to provide subsystem-specific initialization
* if you want the framework to use a bean factory and autowire
* controllers and services, call
* setSubsystemBeanFactory( subsystem, factory )
* in your setupSubsystem() method
* you do not need to call super.setupSubsystem( subsystem )
*/
function setupSubsystem( subsystem ) { }
/*
* use this to override the default view
*/
function setView( action ) {
request.overrideViewAction = action;
}
/*
* returns true if the application is configured to use subsystems
*/
function usingSubsystems() {
return variables.framework.usingSubsystems;
}
</cfscript><cfsilent>
<!---
view() may be invoked inside views and layouts
returns the UI generated by the named view
--->
<cffunction name="view" returntype="string" access="public" output="false">
<cfargument name="path" type="string" required="true" />
<cfargument name="args" type="struct" default="#structNew()#" />
<cfset var viewPath = parseViewOrLayoutPath( arguments.path, 'view' ) />
<cfreturn internalView( viewPath, arguments.args ) />
</cffunction>
<!--- THE FOLLOWING METHODS SHOULD ALL BE CONSIDERED PRIVATE / UNCALLABLE --->
</cfsilent><cfscript>
function buildViewAndLayoutQueue() { // "private"
var siteWideLayoutBase = request.base & getSubsystemDirPrefix( variables.framework.siteWideLayoutSubsystem );
var testLayout = 0;
// default behavior:
var subsystem = request.subsystem;
var section = request.section;
var item = request.item;
var subsystembase = '';
// has view been overridden?
if ( structKeyExists( request, 'overrideViewAction' ) ) {
subsystem = getSubsystem( request.overrideViewAction );
section = getSection( request.overrideViewAction );
item = getItem( request.overrideViewAction );
}
subsystembase = request.base & getSubsystemDirPrefix( subsystem );
// view and layout setup - used to be in setupRequestWrapper():
request.view = parseViewOrLayoutPath( subsystem & variables.framework.subsystemDelimiter &
section & '/' & item, 'view' );
if ( not cachedFileExists( expandPath( request.view ) ) ) {
// ensures original view not re-invoked for onError() case:
structDelete( request, 'view' );
}
request.layouts = arrayNew(1);
// look for item-specific layout:
testLayout = parseViewOrLayoutPath( subsystem & variables.framework.subsystemDelimiter &
section & '/' & item, 'layout' );
if ( cachedFileExists( expandPath( testLayout ) ) ) {
arrayAppend( request.layouts, testLayout );
}
// look for section-specific layout:
testLayout = parseViewOrLayoutPath( subsystem & variables.framework.subsystemDelimiter &
section, 'layout' );
if ( cachedFileExists( expandPath( testLayout ) ) ) {
arrayAppend( request.layouts, testLayout );
}
// look for subsystem-specific layout (site-wide layout if not using subsystems):
if ( request.section is not 'default' ) {
testLayout = parseViewOrLayoutPath( subsystem & variables.framework.subsystemDelimiter &
'default', 'layout' );
if ( cachedFileExists( expandPath( testLayout ) ) ) {
arrayAppend( request.layouts, testLayout );
}
}
// look for site-wide layout (only applicable if using subsystems)
if ( usingSubsystems() and siteWideLayoutBase is not subsystembase ) {
testLayout = parseViewOrLayoutPath( variables.framework.siteWideLayoutSubsystem & variables.framework.subsystemDelimiter &
'default', 'layout' );
if ( cachedFileExists( expandPath( testLayout ) ) ) {
arrayAppend( request.layouts, testLayout );
}
}
}
function ensureNewFrameworkStructsExist() { // "private"
var framework = application[variables.framework.applicationKey];
if ( not structKeyExists(framework, 'subsystemFactories') ) {
framework.subsystemFactories = structNew();
}
if ( not structKeyExists(framework, 'subsystems') ) {
framework.subsystems = structNew();
}
}
function failure( exception, event ) { // "private"
if ( structKeyExists(exception, 'rootCause') ) {
exception = exception.rootCause;
}
writeOutput( '<h1>Exception in #event#</h1>' );
if ( structKeyExists( request, 'failedAction' ) ) {
writeOutput( '<p>The action #request.failedAction# failed.</p>' );
}
writeOutput( '<h2>#exception.message#</h2>' );
writeOutput( '<p>#exception.detail# (#exception.type#)</p>' );
dumpException(exception);
}
function getSubsystemDirPrefix( subsystem ) { // "private"
if ( subsystem eq '' ) {
return '';
}
return subsystem & '/';
}
function isFrameworkInitialized() { // "private"
return structKeyExists( application, variables.framework.applicationKey );
}
function isFrameworkReloadRequest() { // "private"
return ( isDefined('URL') and
structKeyExists(URL, variables.framework.reload) and
URL[variables.framework.reload] is variables.framework.password ) or
variables.framework.reloadApplicationOnEveryRequest;
}
function isSubsystemInitialized( subsystem ) { // "private"
ensureNewFrameworkStructsExist();
return structKeyExists( application[ variables.framework.applicationKey ].subsystems, subsystem );
}
function parseViewOrLayoutPath( path, type ) { // "private"
var pathInfo = StructNew();
var subsystem = getSubsystem( arguments.path );
// allow for :section/action to simplify logic in setupRequestWrapper():
pathInfo.path = listLast( arguments.path, variables.framework.subsystemDelimiter );
pathInfo.base = request.base;
if ( usingSubsystems() ) {
pathInfo.base = pathInfo.base & getSubsystemDirPrefix( subsystem );
}
return customizeViewOrLayoutPath( pathInfo, type, '#pathInfo.base##type#s/#pathInfo.path#.cfm' );
}
function setCfcMethodFailureInfo( cfc, method ) { // "private"
var meta = getMetadata( arguments.cfc );
if ( structKeyExists( meta, 'fullname' ) ) {
request.failedCfcName = meta.fullname;
} else {
request.failedCfcName = meta.name;
}
request.failedMethod = arguments.method;
}
</cfscript>
<cffunction name="setupApplicationWrapper" returntype="void" access="private" output="false">