/
PageContextImpl.java
executable file
·4142 lines (3543 loc) · 125 KB
/
PageContextImpl.java
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
/**
* Copyright (c) 2014, the Railo Company Ltd.
* Copyright (c) 2015, Lucee Assosication Switzerland
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
package lucee.runtime;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.el.ELContext;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.el.ExpressionEvaluator;
import javax.servlet.jsp.el.VariableResolver;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TryCatchFinally;
import lucee.commons.db.DBUtil;
import lucee.commons.io.BodyContentStack;
import lucee.commons.io.CharsetUtil;
import lucee.commons.io.IOUtil;
import lucee.commons.io.SystemUtil;
import lucee.commons.io.cache.exp.CacheException;
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.util.ResourceClassLoader;
import lucee.commons.lang.ClassException;
import lucee.commons.lang.ClassUtil;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.HTMLEntities;
import lucee.commons.lang.PhysicalClassLoader;
import lucee.commons.lang.StringUtil;
import lucee.commons.lang.mimetype.MimeType;
import lucee.commons.lang.types.RefBoolean;
import lucee.commons.lang.types.RefBooleanImpl;
import lucee.commons.lock.KeyLock;
import lucee.commons.lock.Lock;
import lucee.commons.net.HTTPUtil;
import lucee.intergral.fusiondebug.server.FDSignal;
import lucee.loader.engine.CFMLEngine;
import lucee.runtime.cache.CacheConnection;
import lucee.runtime.cache.CacheUtil;
import lucee.runtime.cache.tag.CacheHandler;
import lucee.runtime.cache.tag.CacheHandlerCollectionImpl;
import lucee.runtime.cache.tag.CacheHandlerPro;
import lucee.runtime.cache.tag.CacheItem;
import lucee.runtime.cache.tag.include.IncludeCacheItem;
import lucee.runtime.component.ComponentLoader;
import lucee.runtime.config.Config;
import lucee.runtime.config.ConfigPro;
import lucee.runtime.config.ConfigWeb;
import lucee.runtime.config.ConfigWebPro;
import lucee.runtime.config.Constants;
import lucee.runtime.config.NullSupportHelper;
import lucee.runtime.config.Password;
import lucee.runtime.db.DataSource;
import lucee.runtime.db.DataSourceManager;
import lucee.runtime.db.DatasourceManagerImpl;
import lucee.runtime.debug.ActiveLock;
import lucee.runtime.debug.ActiveQuery;
import lucee.runtime.debug.DebugCFMLWriter;
import lucee.runtime.debug.DebugEntryTemplate;
import lucee.runtime.debug.Debugger;
import lucee.runtime.debug.DebuggerImpl;
import lucee.runtime.dump.DumpUtil;
import lucee.runtime.dump.DumpWriter;
import lucee.runtime.engine.ExecutionLog;
import lucee.runtime.err.ErrorPage;
import lucee.runtime.err.ErrorPageImpl;
import lucee.runtime.err.ErrorPagePool;
import lucee.runtime.esapi.ESAPIUtil;
import lucee.runtime.exp.Abort;
import lucee.runtime.exp.ApplicationException;
import lucee.runtime.exp.CasterException;
import lucee.runtime.exp.DatabaseException;
import lucee.runtime.exp.ExceptionHandler;
import lucee.runtime.exp.ExpressionException;
import lucee.runtime.exp.MissingIncludeException;
import lucee.runtime.exp.NoLongerSupported;
import lucee.runtime.exp.PageException;
import lucee.runtime.exp.PageExceptionBox;
import lucee.runtime.exp.RequestTimeoutException;
import lucee.runtime.ext.tag.TagImpl;
import lucee.runtime.functions.dynamicEvaluation.Serialize;
import lucee.runtime.interpreter.CFMLExpressionInterpreter;
import lucee.runtime.interpreter.VariableInterpreter;
import lucee.runtime.listener.AppListenerSupport;
import lucee.runtime.listener.ApplicationContext;
import lucee.runtime.listener.ApplicationContextSupport;
import lucee.runtime.listener.ApplicationListener;
import lucee.runtime.listener.ClassicApplicationContext;
import lucee.runtime.listener.JavaSettingsImpl;
import lucee.runtime.listener.ModernAppListener;
import lucee.runtime.listener.ModernAppListenerException;
import lucee.runtime.listener.NoneAppListener;
import lucee.runtime.listener.SessionCookieData;
import lucee.runtime.listener.SessionCookieDataImpl;
import lucee.runtime.monitor.RequestMonitor;
import lucee.runtime.monitor.RequestMonitorPro;
import lucee.runtime.net.ftp.FTPPoolImpl;
import lucee.runtime.net.http.HTTPServletRequestWrap;
import lucee.runtime.net.http.ReqRspUtil;
import lucee.runtime.net.mail.ServerImpl;
import lucee.runtime.net.proxy.ProxyData;
import lucee.runtime.op.Caster;
import lucee.runtime.op.Decision;
import lucee.runtime.op.OpUtil;
import lucee.runtime.orm.ORMConfiguration;
import lucee.runtime.orm.ORMEngine;
import lucee.runtime.orm.ORMSession;
import lucee.runtime.regex.Regex;
import lucee.runtime.rest.RestRequestListener;
import lucee.runtime.rest.RestUtil;
import lucee.runtime.security.Credential;
import lucee.runtime.security.CredentialImpl;
import lucee.runtime.security.ScriptProtect;
import lucee.runtime.tag.Login;
import lucee.runtime.tag.TagHandlerPool;
import lucee.runtime.tag.TagUtil;
import lucee.runtime.thread.ThreadsImpl;
import lucee.runtime.type.Array;
import lucee.runtime.type.Collection;
import lucee.runtime.type.Collection.Key;
import lucee.runtime.type.Iterator;
import lucee.runtime.type.KeyImpl;
import lucee.runtime.type.LiteralValue;
import lucee.runtime.type.Query;
import lucee.runtime.type.SVArray;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.UDF;
import lucee.runtime.type.dt.TimeSpan;
import lucee.runtime.type.it.ItAsEnum;
import lucee.runtime.type.ref.Reference;
import lucee.runtime.type.ref.VariableReference;
import lucee.runtime.type.scope.Application;
import lucee.runtime.type.scope.Argument;
import lucee.runtime.type.scope.ArgumentImpl;
import lucee.runtime.type.scope.CFThread;
import lucee.runtime.type.scope.CGI;
import lucee.runtime.type.scope.CGIImpl;
import lucee.runtime.type.scope.CGIImplReadOnly;
import lucee.runtime.type.scope.Client;
import lucee.runtime.type.scope.ClosureScope;
import lucee.runtime.type.scope.Cluster;
import lucee.runtime.type.scope.Cookie;
import lucee.runtime.type.scope.CookieImpl;
import lucee.runtime.type.scope.Form;
import lucee.runtime.type.scope.FormImpl;
import lucee.runtime.type.scope.Local;
import lucee.runtime.type.scope.LocalNotSupportedScope;
import lucee.runtime.type.scope.Request;
import lucee.runtime.type.scope.RequestImpl;
import lucee.runtime.type.scope.Scope;
import lucee.runtime.type.scope.ScopeContext;
import lucee.runtime.type.scope.ScopeFactory;
import lucee.runtime.type.scope.ScopeSupport;
import lucee.runtime.type.scope.Server;
import lucee.runtime.type.scope.Session;
import lucee.runtime.type.scope.Threads;
import lucee.runtime.type.scope.URL;
import lucee.runtime.type.scope.URLForm;
import lucee.runtime.type.scope.URLImpl;
import lucee.runtime.type.scope.Undefined;
import lucee.runtime.type.scope.UndefinedImpl;
import lucee.runtime.type.scope.UrlFormImpl;
import lucee.runtime.type.scope.Variables;
import lucee.runtime.type.scope.VariablesImpl;
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.CollectionUtil;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.util.PageContextUtil;
import lucee.runtime.util.VariableUtil;
import lucee.runtime.util.VariableUtilImpl;
import lucee.runtime.writer.BodyContentUtil;
import lucee.runtime.writer.CFMLWriter;
import lucee.runtime.writer.DevNullBodyContent;
/**
* page context for every page object. the PageContext is a jsp page context expanded by CFML
* functionality. for example you have the method getSession to get jsp combatible session object
* (HTTPSession) and with sessionScope() you get CFML combatible session object (Struct,Scope).
*/
public final class PageContextImpl extends PageContext {
private static final RefBoolean DUMMY_BOOL = new RefBooleanImpl(false);
private static int counter = 0;
/**
* Field <code>pathList</code>
*/
private LinkedList<UDF> udfs = new LinkedList<UDF>();
private LinkedList<PageSource> pathList = new LinkedList<PageSource>();
private LinkedList<PageSource> includePathList = new LinkedList<PageSource>();
private Set<PageSource> includeOnce = new HashSet<PageSource>();
/**
* Field <code>executionTime</code>
*/
protected long executionTime = 0;
private HTTPServletRequestWrap req;
private HttpServletResponse rsp;
private HttpServlet servlet;
private JspWriter writer;
private JspWriter forceWriter;
private BodyContentStack bodyContentStack;
private DevNullBodyContent devNull;
private ConfigWebPro config;
// private DataSourceManager manager;
// private CFMLCompilerImpl compiler;
// Scopes
private ScopeContext scopeContext;
private Variables variablesRoot = new VariablesImpl();// ScopeSupport(false,"variables",Scope.SCOPE_VARIABLES);
private Variables variables = variablesRoot;// new ScopeSupport("variables",Scope.SCOPE_VARIABLES);
private Undefined undefined;
private URLImpl _url = new URLImpl();
private FormImpl _form = new FormImpl();
private URLForm urlForm = new UrlFormImpl(_form, _url);
private URL url;
private Form form;
private RequestImpl request = new RequestImpl();
private CGIImplReadOnly cgiR = new CGIImplReadOnly();
private CGIImpl cgiRW = new CGIImpl();
private Argument argument = new ArgumentImpl();
private static LocalNotSupportedScope localUnsupportedScope = LocalNotSupportedScope.getInstance();
private Local local = localUnsupportedScope;
private Session session;
private Server server;
private Cluster cluster;
private CookieImpl cookie = new CookieImpl();
private Client client;
private Application application;
private DebuggerImpl debugger = new DebuggerImpl();
private long requestTimeout = -1;
private short enablecfoutputonly = 0;
private int outputState;
private String cfid;
private String cftoken;
private int id;
private int requestId;
private Boolean _psq;
private Locale locale;
private TimeZone timeZone;
// Pools
private ErrorPagePool errorPagePool = new ErrorPagePool();
private TagHandlerPool tagHandlerPool;
private FTPPoolImpl ftpPool = new FTPPoolImpl();
private Component activeComponent;
private UDF activeUDF;
private Collection.Key activeUDFCalledName;
// private ComponentScope componentScope=new ComponentScope(this);
private Credential remoteUser;
protected VariableUtilImpl variableUtil = new VariableUtilImpl();
private PageException exception;
private PageSource base;
private ApplicationContextSupport applicationContext;
private final ApplicationContextSupport defaultApplicationContext;
private ScopeFactory scopeFactory = new ScopeFactory();
private Tag parentTag = null;
private Tag currentTag = null;
private Thread thread;
private long startTime;
private long startTimeNS;
private long endTimeNS;
private DatasourceManagerImpl manager;
private CFThread threads;
private Map<Key, Threads> allThreads;
private boolean hasFamily = false;
private PageContextImpl parent = null;
private PageSource caller = null;
private PageSource callerTemplate = null;
private PageContextImpl root = null;
private List<String> parentTags;
private Queue<PageContext> children = null;
private List<Statement> lazyStats;
private boolean fdEnabled;
private ExecutionLog execLog;
private boolean useSpecialMappings;
private ORMSession ormSession;
private boolean isChild;
private boolean gatewayContext;
private boolean listenerContext;
private Password serverPassword;
private PageException pe;
// private Throwable requestTimeoutException;
private int currentTemplateDialect = CFMLEngine.DIALECT_CFML;
private int requestDialect = CFMLEngine.DIALECT_CFML;
private boolean ignoreScopes = false;
private int appListenerType = ApplicationListener.TYPE_NONE;
private ThreadsImpl currentThread = null;
private StackTraceElement[] timeoutStacktrace;
private boolean fullNullSupport;
private static final boolean READ_CFID_FROM_URL = Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.read.cfid.from.url", "true"), true);
private static int _idCounter = 1;
private long lastTimeoutNoAction;
/**
* default Constructor
*
* @param scopeContext
* @param config Configuration of the CFML Container
* @param queryCache Query Cache Object
* @param id identity of the pageContext
* @param servlet
*/
public PageContextImpl(ScopeContext scopeContext, ConfigWebPro config, HttpServlet servlet, boolean jsr223) {
// must be first because is used after
tagHandlerPool = config.getTagHandlerPool();
this.servlet = servlet;
bodyContentStack = new BodyContentStack();
devNull = bodyContentStack.getDevNullBodyContent();
this.config = config;
manager = new DatasourceManagerImpl(config);
this.scopeContext = scopeContext;
undefined = new UndefinedImpl(this, getScopeCascadingType());
server = ScopeContext.getServerScope(this, jsr223);
defaultApplicationContext = new ClassicApplicationContext(config, "", true, null);
this.id = getIdCounter();
}
public boolean isInitialized() {
return rsp != null;
}
/**
* return if the PageContext is from a stopped thread, if so it should no longer be used!
*
* @return
*/
@Override
public Throwable getRequestTimeoutException() {
throw new RuntimeException("method no longer supported");
}
public StackTraceElement[] getTimeoutStackTrace() {
return timeoutStacktrace;
}
public void setTimeoutStackTrace() {
this.timeoutStacktrace = thread.getStackTrace();
}
@Override
public void initialize(Servlet servlet, ServletRequest req, ServletResponse rsp, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
throws IOException, IllegalStateException, IllegalArgumentException {
initialize((HttpServlet) servlet, (HttpServletRequest) req, (HttpServletResponse) rsp, errorPageURL, needsSession, bufferSize, autoFlush, false, false, null);
}
/**
* initialize an existing page context
*
* @param servlet
* @param req
* @param rsp
* @param errorPageURL
* @param needsSession
* @param bufferSize
* @param autoFlush
* @param tmplPC
*/
public PageContextImpl initialize(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp, String errorPageURL, boolean needsSession, int bufferSize,
boolean autoFlush, boolean isChild, boolean ignoreScopes, PageContextImpl tmplPC) {
parent = null;
caller = null;
callerTemplate = null;
root = null;
boolean clone = tmplPC != null;
requestId = counter++;
if (clone) {
appListenerType = tmplPC.appListenerType;
this.ignoreScopes = tmplPC.ignoreScopes;
}
else {
appListenerType = ApplicationListener.TYPE_NONE;
this.ignoreScopes = ignoreScopes;
}
ReqRspUtil.setContentType(rsp, "text/html; charset=" + config.getWebCharset().name());
this.isChild = isChild;
applicationContext = defaultApplicationContext;
setFullNullSupport();
startTime = System.currentTimeMillis();
startTimeNS = System.nanoTime();
endTimeNS = 0;
thread = Thread.currentThread();
if (req instanceof HTTPServletRequestWrap) this.req = (HTTPServletRequestWrap) req;
else this.req = new HTTPServletRequestWrap(req);
this.rsp = rsp;
this.servlet = servlet;
// Writers
{
PageContext tmp = clone ? tmplPC : this;
if (config.debugLogOutput()) {
CFMLWriter w = config.getCFMLWriter(tmp, req, rsp);
w.setAllowCompression(false);
DebugCFMLWriter dcw = new DebugCFMLWriter(w);
bodyContentStack.init(dcw);
debugger.setOutputLog(dcw);
}
else {
bodyContentStack.init(config.getCFMLWriter(tmp, req, rsp));
}
}
writer = bodyContentStack.getWriter();
forceWriter = writer;
// Scopes
server = ScopeContext.getServerScope(this, ignoreScopes);
if (clone) {
this.form = tmplPC.form;
this.url = tmplPC.url;
this.urlForm = tmplPC.urlForm;
this._url = tmplPC._url;
this._form = tmplPC._form;
this.variables = tmplPC.variables;
this.undefined = new UndefinedImpl(this, (short) tmplPC.undefined.getType());
hasFamily = true;
}
else {
if (hasFamily) {
variablesRoot = new VariablesImpl();
variables = variablesRoot;
request = new RequestImpl();
_url = new URLImpl();
_form = new FormImpl();
urlForm = new UrlFormImpl(_form, _url);
undefined = new UndefinedImpl(this, getScopeCascadingType());
hasFamily = false;
}
else if (variables == null) {
variablesRoot = new VariablesImpl();
variables = variablesRoot;
}
}
if (clone) {
this.request = tmplPC.request;
}
else {
request.initialize(this);
if (config.mergeFormAndURL()) {
url = urlForm;
form = urlForm;
}
else {
url = _url;
form = _form;
}
}
// scopes
if (clone) {
this._psq = tmplPC._psq;
this.gatewayContext = tmplPC.gatewayContext;
this.listenerContext = tmplPC.listenerContext;
}
else {
_psq = null;
}
fdEnabled = !config.allowRequestTimeout();
if (config.getExecutionLogEnabled()) this.execLog = config.getExecutionLogFactory().getInstance(this);
if (debugger != null) debugger.init(config);
undefined.initialize(this);
timeoutStacktrace = null;
if (clone) {
getCFID();
this.cfid = tmplPC.cfid;
this.cftoken = tmplPC.cftoken;
this.requestTimeout = tmplPC.requestTimeout;
this.locale = tmplPC.locale;
this.timeZone = tmplPC.timeZone;
this.fdEnabled = tmplPC.fdEnabled;
this.useSpecialMappings = tmplPC.useSpecialMappings;
this.serverPassword = tmplPC.serverPassword;
this.requestDialect = tmplPC.requestDialect;
this.currentTemplateDialect = tmplPC.currentTemplateDialect;
tmplPC.hasFamily = true;
this.parent = tmplPC;
this.caller = tmplPC.getCurrentPageSource();
this.callerTemplate = tmplPC.getCurrentTemplatePageSource();
this.root = tmplPC.root == null ? tmplPC : tmplPC.root;
this.tagName = tmplPC.tagName;
this.parentTags = tmplPC.parentTags == null ? null : (List) ((ArrayList) tmplPC.parentTags).clone();
if (tmplPC.children == null) {
synchronized (tmplPC) {
if (tmplPC.children == null) {
tmplPC.children = new ConcurrentLinkedQueue<PageContext>();
}
}
}
tmplPC.children.add(this);
this.applicationContext = tmplPC.applicationContext;
this.setFullNullSupport();
// path
this.base = tmplPC.base;
java.util.Iterator<PageSource> it = tmplPC.includePathList.iterator();
while (it.hasNext()) {
this.includePathList.add(it.next());
}
it = pathList.iterator();
while (it.hasNext()) {
this.pathList.add(it.next());
}
}
return this;
}
@Override
public void release() {
config.releaseCacheHandlers(this);
if (config.getExecutionLogEnabled() && execLog != null) {
execLog.release();
execLog = null;
}
if (config.debug()) {
boolean skipLogThread = isChild;
if (skipLogThread && config.hasDebugOptions(ConfigPro.DEBUG_THREAD)) skipLogThread = false;
if (!gatewayContext && !skipLogThread) config.getDebuggerPool().store(this, debugger);
debugger.reset();
}
else debugger.resetTraces(); // traces can alo be used when debugging is off
this.serverPassword = null;
// boolean isChild=parent!=null; // isChild is defined in the class outside this method
parent = null;
caller = null;
callerTemplate = null;
root = null;
// Attention have to be before close
if (client != null) {
client.touchAfterRequest(this);
client = null;
}
if (session != null) {
session.touchAfterRequest(this);
session = null;
}
// ORM
// if(ormSession!=null)releaseORM();
// Scopes
if (hasFamily) {
if (hasFamily && !isChild) {
req.disconnect(this);
}
close();
base = null;
if (children != null) children.clear();
request = null;
_url = null;
_form = null;
urlForm = null;
undefined = null;
variables = null;
variablesRoot = null;
// if(threads!=null && threads.size()>0) threads.clear();
threads = null;
allThreads = null;
currentThread = null;
}
else {
close();
base = null;
if (variables.isBind()) {
variables = null;
variablesRoot = null;
}
else {
variables = variablesRoot;
variables.release(this);
}
undefined.release(this);
urlForm.release(this);
request.release(this);
}
cgiR.release(this);
cgiRW.release(this);
argument.release(this);
local = localUnsupportedScope;
cookie.release(this);
application = null;// not needed at the moment -> application.releaseAfterRequest();
applicationContext = null;// do not release may used by child threads
// Properties
requestTimeout = -1;
outputState = 0;
cfid = null;
cftoken = null;
locale = null;
timeZone = null;
url = null;
form = null;
currentTemplateDialect = CFMLEngine.DIALECT_CFML;
requestDialect = CFMLEngine.DIALECT_CFML;
// Pools
errorPagePool.clear();
// lazy statements
if (lazyStats != null && !lazyStats.isEmpty()) {
java.util.Iterator<Statement> it = lazyStats.iterator();
while (it.hasNext()) {
DBUtil.closeEL(it.next());
}
lazyStats.clear();
lazyStats = null;
}
if (!hasFamily) {
pathList.clear();
includePathList.clear();
}
executionTime = 0;
bodyContentStack.release();
// activeComponent=null;
remoteUser = null;
exception = null;
ftpPool.clear();
parentTag = null;
currentTag = null;
// Req/Rsp
if (req instanceof HTTPServletRequestWrap) {
req.close();
}
req = null;
rsp = null;
servlet = null;
// Writer
writer = null;
forceWriter = null;
if (pagesUsed.size() > 0) pagesUsed.clear();
activeComponent = null;
activeUDF = null;
gatewayContext = false;
listenerContext = false;
manager.release();
includeOnce.clear();
pe = null;
this.literalTimestampWithTSOffset = false;
thread = null;
tagName = null;
parentTags = null;
_psq = null;
dummy = false;
listenSettings = false;
if (lastTimeoutNoAction != 0) lastTimeoutNoAction = 0L;
if (ormSession != null) {
try {
releaseORM();
}
catch (Exception e) {
}
}
}
private void releaseORM() throws PageException {
try {
// flush orm session
ORMEngine engine = ormSession.getEngine();
ORMConfiguration config = engine.getConfiguration(this);
if (config == null || (config.flushAtRequestEnd() && config.autoManageSession())) {
ormSession.flushAll(this);
}
ormSession.closeAll(this);
manager.releaseORM();
}
finally {
ormSession = null;
}
}
@Override
public void write(String str) throws IOException {
writer.write(str);
}
@Override
public void forceWrite(String str) throws IOException {
forceWriter.write(str);
}
@Override
public void writePSQ(Object o) throws IOException, PageException {
// is var usage allowed?
if (applicationContext != null && applicationContext.getQueryVarUsage() != ConfigPro.QUERY_VAR_USAGE_IGNORE) {
// Warning
if (applicationContext.getQueryVarUsage() == ConfigPro.QUERY_VAR_USAGE_WARN) {
DebuggerImpl.deprecated(this, "query.variableUsage",
"Please do not use variables within the cfquery tag, instead use the tag \"cfqueryparam\" or the attribute \"params\"");
}
// Error
else if (applicationContext.getQueryVarUsage() == ConfigPro.QUERY_VAR_USAGE_ERROR) {
throw new ApplicationException("Variables are not allowed within cfquery, please use the tag <cfqueryparam> or the attribute \"params\" instead.");
}
}
// preserve single quote
if (o instanceof Date || Decision.isDate(o, false)) {
writer.write(Caster.toString(o));
}
else {
writer.write(getPsq() ? Caster.toString(o) : StringUtil.replace(Caster.toString(o), "'", "''", false));
}
}
// FUTURE add both method to interface
public void writeEncodeFor(String value, String encodeType) throws IOException, PageException { // FUTURE keyword:encodefore add to interface
write(ESAPIUtil.esapiEncode(this, encodeType, value));
}
/*
* public void writeEncodeFor(String value, short encodeType) throws IOException, PageException { //
* FUTURE keyword:encodefore add to interface write(ESAPIUtil.esapiEncode(this,value, encodeType));
* }
*/
@Override
public void flush() {
try {
getOut().flush();
}
catch (IOException e) {
}
}
@Override
public void close() {
IOUtil.closeEL(getOut());
}
public PageSource getRelativePageSource(String realPath) {
LogUtil.log(this, Log.LEVEL_INFO, PageContextImpl.class.getName(), "method getRelativePageSource is deprecated");
if (StringUtil.startsWith(realPath, '/')) return PageSourceImpl.best(getPageSources(realPath));
if (pathList.size() == 0) return null;
return pathList.getLast().getRealPage(realPath);
}
public PageSource getRelativePageSourceExisting(String realPath) {
if (StringUtil.startsWith(realPath, '/')) return getPageSourceExisting(realPath);
if (pathList.size() == 0) return null;
PageSource ps = pathList.getLast().getRealPage(realPath);
if (PageSourceImpl.pageExist(ps)) return ps;
return null;
}
/**
*
* @param realPath
* @param previous relative not to the caller, relative to the callers caller
* @return
*/
public PageSource getRelativePageSourceExisting(String realPath, boolean previous) {
if (StringUtil.startsWith(realPath, '/')) return getPageSourceExisting(realPath);
if (pathList.size() == 0) return null;
PageSource ps = null, tmp = null;
if (previous) {
boolean valid = false;
ps = pathList.getLast();
for (int i = pathList.size() - 2; i >= 0; i--) {
tmp = pathList.get(i);
if (tmp != ps) {
ps = tmp;
valid = true;
break;
}
}
if (!valid) return null;
}
else ps = pathList.getLast();
ps = ps.getRealPage(realPath);
if (PageSourceImpl.pageExist(ps)) return ps;
return null;
}
public PageSource[] getRelativePageSources(String realPath) {
if (StringUtil.startsWith(realPath, '/')) return getPageSources(realPath);
PageSource ps = getCurrentPageSource(null);
if (ps == null) return null;
return new PageSource[] { ps.getRealPage(realPath) };
}
public PageSource getPageSource(String realPath) {
return PageSourceImpl.best(config.getPageSources(this, applicationContext.getMappings(), realPath, false, useSpecialMappings, true));
}
public PageSource[] getPageSources(String realPath) { // to not change, this is used in the flex extension
return config.getPageSources(this, applicationContext.getMappings(), realPath, false, useSpecialMappings, true, false);
}
public PageSource getPageSourceExisting(String realPath) { // do not change, this method is used in flex extension
return config.getPageSourceExisting(this, applicationContext.getMappings(), realPath, false, useSpecialMappings, true, false);
}
public boolean useSpecialMappings(boolean useTagMappings) {
boolean b = this.useSpecialMappings;
this.useSpecialMappings = useTagMappings;
return b;
}
public boolean useSpecialMappings() {
return useSpecialMappings;
}
public Resource getPhysical(String realPath, boolean alsoDefaultMapping) {
return config.getPhysical(applicationContext.getMappings(), realPath, alsoDefaultMapping);
}
@Override
public PageSource toPageSource(Resource res, PageSource defaultValue) {
return config.toPageSource(applicationContext.getMappings(), res, defaultValue);
}
@Override
public void doInclude(String realPath) throws PageException {
_doInclude(getRelativePageSources(realPath), false, getCachedWithin(ConfigWeb.CACHEDWITHIN_INCLUDE));
}
@Override
public void doInclude(String realPath, boolean runOnce) throws PageException {
_doInclude(getRelativePageSources(realPath), runOnce, getCachedWithin(ConfigWeb.CACHEDWITHIN_INCLUDE));
}
// used by the transformer
public void doInclude(String realPath, boolean runOnce, Object cachedWithin) throws PageException {
if (cachedWithin == null) cachedWithin = getCachedWithin(ConfigWeb.CACHEDWITHIN_INCLUDE);
_doInclude(getRelativePageSources(realPath), runOnce, cachedWithin);
}
@Override
public void doInclude(PageSource[] sources, boolean runOnce) throws PageException {
_doInclude(sources, runOnce, getCachedWithin(ConfigWeb.CACHEDWITHIN_INCLUDE));
}
// IMPORTANT!!! we do not getCachedWithin in this method, because Modern|ClassicAppListener is
// calling this method and in this case it should not be used
public void _doInclude(PageSource[] sources, boolean runOnce, Object cachedWithin) throws PageException {
PageContextUtil.checkRequestTimeout(this);
if (cachedWithin == null) {
_doInclude(sources, runOnce);
return;
}
// ignore call when runonce an it is not first call
if (runOnce) {
Page currentPage = PageSourceImpl.loadPage(this, sources);
if (runOnce && includeOnce.contains(currentPage.getPageSource())) return;
}
// get cached data
String cacheId = CacheHandlerCollectionImpl.createId(sources);
CacheHandler cacheHandler = config.getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null).getInstanceMatchingObject(cachedWithin, null);
if (cacheHandler instanceof CacheHandlerPro) {
CacheItem cacheItem = ((CacheHandlerPro) cacheHandler).get(this, cacheId, cachedWithin);
if (cacheItem instanceof IncludeCacheItem) {
try {
write(((IncludeCacheItem) cacheItem).getOutput());
return;
}
catch (IOException e) {
throw Caster.toPageException(e);
}
}
}
else if (cacheHandler != null) { // TODO this else block can be removed when all cache handlers implement CacheHandlerPro
CacheItem cacheItem = cacheHandler.get(this, cacheId);
if (cacheItem instanceof IncludeCacheItem) {
try {
write(((IncludeCacheItem) cacheItem).getOutput());
return;
}
catch (IOException e) {
throw Caster.toPageException(e);
}
}
}
// cached item not found, process and cache result if needed
long start = System.nanoTime();
BodyContent bc = pushBody();
try {
_doInclude(sources, runOnce);