/
IKStorageScopeSupport.java
701 lines (600 loc) · 21.1 KB
/
IKStorageScopeSupport.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
/**
* Copyright (c) 2017, 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.type.scope.storage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lucee.commons.collection.MapFactory;
import lucee.commons.io.log.Log;
import lucee.commons.lang.StringUtil;
import lucee.runtime.PageContext;
import lucee.runtime.cache.CacheUtil;
import lucee.runtime.config.Config;
import lucee.runtime.db.DataSource;
import lucee.runtime.dump.DumpData;
import lucee.runtime.dump.DumpProperties;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.exp.ExpressionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.listener.ApplicationContext;
import lucee.runtime.op.Caster;
import lucee.runtime.op.Decision;
import lucee.runtime.type.Collection;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.dt.DateTime;
import lucee.runtime.type.dt.DateTimeImpl;
import lucee.runtime.type.dt.TimeSpan;
import lucee.runtime.type.it.EntryIterator;
import lucee.runtime.type.it.ValueIterator;
import lucee.runtime.type.scope.CSRFTokenSupport;
import lucee.runtime.type.scope.Scope;
import lucee.runtime.type.scope.Session;
import lucee.runtime.type.scope.client.IKStorageScopeClient;
import lucee.runtime.type.scope.session.IKStorageScopeSession;
import lucee.runtime.type.scope.util.ScopeUtil;
import lucee.runtime.type.util.CollectionUtil;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.type.util.StructSupport;
import lucee.runtime.type.util.StructUtil;
public abstract class IKStorageScopeSupport extends StructSupport implements StorageScope, CSRFTokenSupport {
protected static final IKStorageScopeItem ONE = new IKStorageScopeItem("1");
private static int _id = 0;
private int id = 0;
private static final long serialVersionUID = 7874930250042576053L;
private static final IKStorageScopeItem NULL = new IKStorageScopeItem("null");
private static Set<Collection.Key> FIX_KEYS = new HashSet<Collection.Key>();
static {
FIX_KEYS.add(KeyConstants._cfid);
FIX_KEYS.add(KeyConstants._cftoken);
FIX_KEYS.add(KeyConstants._urltoken);
FIX_KEYS.add(KeyConstants._lastvisit);
FIX_KEYS.add(KeyConstants._hitcount);
FIX_KEYS.add(KeyConstants._timecreated);
FIX_KEYS.add(KeyConstants._csrf_token);
}
protected static Set<Collection.Key> ignoreSet = new HashSet<Collection.Key>();
static {
ignoreSet.add(KeyConstants._cfid);
ignoreSet.add(KeyConstants._cftoken);
ignoreSet.add(KeyConstants._urltoken);
}
protected boolean isinit = true;
protected Map<Collection.Key, IKStorageScopeItem> data0;
protected long lastvisit;
protected DateTime _lastvisit;
protected int hitcount = 0;
protected DateTime timecreated;
private boolean hasChanges = false;
protected String strType;
protected int type;
private long timeSpan = -1;
private String storage;
private Struct tokens = new StructImpl();
private long lastModified;
private IKHandler handler;
private String appName;
private String name;
public IKStorageScopeSupport(PageContext pc, IKHandler handler, String appName, String name, String strType, int type, Map<Collection.Key, IKStorageScopeItem> data,
long lastModified, long timeSpan) {
// !!! do not store the pagecontext or config object, this object is Serializable !!!
Config config = ThreadLocalPageContext.getConfig(pc);
this.data0 = data;
timecreated = doNowIfNull(config, Caster.toDate(data.getOrDefault(KeyConstants._timecreated, null), false, pc.getTimeZone(), null));
_lastvisit = doNowIfNull(config, Caster.toDate(data.getOrDefault(KeyConstants._lastvisit, null), false, pc.getTimeZone(), null));
if (_lastvisit == null) _lastvisit = timecreated;
lastvisit = _lastvisit == null ? 0 : _lastvisit.getTime();
ApplicationContext ac = pc.getApplicationContext();
if (ac != null && ac.getSessionCluster() && isSessionStorage(pc)) {
IKStorageScopeItem csrfTokens = data.getOrDefault(KeyConstants._csrf_token, null);
Object val = csrfTokens == null ? null : csrfTokens.getValue();
if (Decision.isStruct(val)) {
this.tokens = Caster.toStruct(val, null);
}
}
this.hitcount = (type == SCOPE_CLIENT) ? Caster.toIntValue(data.getOrDefault(KeyConstants._hitcount, ONE), 1) : 1;
this.strType = strType;
this.type = type;
this.lastModified = lastModified;
this.handler = handler;
this.appName = appName;
this.name = name;
id = ++_id;
this.timeSpan = timeSpan;
}
public static Scope getInstance(int scope, IKHandler handler, String appName, String name, PageContext pc, Scope existing, Log log) throws PageException {
IKStorageValue sv = null;
if (Scope.SCOPE_SESSION == scope) sv = handler.loadData(pc, appName, name, "session", Scope.SCOPE_SESSION, log);
else if (Scope.SCOPE_CLIENT == scope) sv = handler.loadData(pc, appName, name, "client", Scope.SCOPE_CLIENT, log);
if (sv != null) {
long time = sv.lastModified();
if (existing instanceof IKStorageScopeSupport) {
IKStorageScopeSupport tmp = ((IKStorageScopeSupport) existing);
if (tmp.lastModified() >= time && name.equalsIgnoreCase(tmp.getStorage())) {
return existing;
}
}
if (Scope.SCOPE_SESSION == scope) return new IKStorageScopeSession(pc, handler, appName, name, sv.getValue(), time, getSessionTimeout(pc));
else if (Scope.SCOPE_CLIENT == scope) return new IKStorageScopeClient(pc, handler, appName, name, sv.getValue(), time, getClientTimeout(pc));
}
else if (existing instanceof IKStorageScopeSupport) {
IKStorageScopeSupport tmp = ((IKStorageScopeSupport) existing);
if (name.equalsIgnoreCase(tmp.getStorage())) {
return existing;
}
}
IKStorageScopeSupport rtn = null;
Map<Key, IKStorageScopeItem> map = MapFactory.getConcurrentMap();
if (Scope.SCOPE_SESSION == scope) rtn = new IKStorageScopeSession(pc, handler, appName, name, map, 0, getSessionTimeout(pc));
else if (Scope.SCOPE_CLIENT == scope) rtn = new IKStorageScopeClient(pc, handler, appName, name, map, 0, getClientTimeout(pc));
rtn.store(pc);
return rtn;
}
private static long getClientTimeout(PageContext pc) {
pc = ThreadLocalPageContext.get(pc);
ApplicationContext ac = pc == null ? null : pc.getApplicationContext();
TimeSpan timeout = ac == null ? null : ac.getClientTimeout();
return timeout == null ? 0 : timeout.getMillis();
}
private static long getSessionTimeout(PageContext pc) {
pc = ThreadLocalPageContext.get(pc);
ApplicationContext ac = pc == null ? null : pc.getApplicationContext();
TimeSpan timeout = ac == null ? null : ac.getSessionTimeout();
return timeout == null ? 0 : timeout.getMillis();
}
public static Scope getInstance(int scope, IKHandler handler, String appName, String name, PageContext pc, Session existing, Log log, Session defaultValue) {
try {
return getInstance(scope, handler, appName, name, pc, existing, log);
}
catch (PageException e) {
}
return defaultValue;
}
public static boolean hasInstance(int scope, IKHandler handler, String appName, String name, PageContext pc) {
try {
Log log = ThreadLocalPageContext.getLog(pc, "scope");
if (Scope.SCOPE_SESSION == scope) return handler.loadData(pc, appName, name, "session", Scope.SCOPE_SESSION, log) != null;
else if (Scope.SCOPE_CLIENT == scope) return handler.loadData(pc, appName, name, "client", Scope.SCOPE_CLIENT, log) != null;
return false;
}
catch (PageException e) {
return false;
}
}
@Override
public void touchBeforeRequest(PageContext pc) {
hasChanges = false;
setTimeSpan(pc);
// lastvisit=System.currentTimeMillis();
if (data0 == null) data0 = MapFactory.getConcurrentMap();
data0.put(KeyConstants._cfid, new IKStorageScopeItem(pc.getCFID()));
data0.put(KeyConstants._cftoken, new IKStorageScopeItem(pc.getCFToken()));
data0.put(KeyConstants._urltoken, new IKStorageScopeItem(pc.getURLToken()));
data0.put(KeyConstants._lastvisit, new IKStorageScopeItem(_lastvisit));
_lastvisit = new DateTimeImpl(pc.getConfig());
lastvisit = System.currentTimeMillis();
if (type == SCOPE_CLIENT) {
data0.put(KeyConstants._hitcount, new IKStorageScopeItem(new Double(hitcount++)));
}
else {
data0.put(KeyConstants._sessionid, new IKStorageScopeItem(pc.getApplicationContext().getName() + "_" + pc.getCFID() + "_" + pc.getCFToken()));
}
ApplicationContext ac = pc.getApplicationContext();
if (ac != null && ac.getSessionCluster() && isSessionStorage(pc)) {
data0.put(KeyConstants._csrf_token, new IKStorageScopeItem(this.tokens));
}
data0.put(KeyConstants._timecreated, new IKStorageScopeItem(timecreated));
}
public void resetEnv(PageContext pc) {
_lastvisit = new DateTimeImpl(pc.getConfig());
timecreated = new DateTimeImpl(pc.getConfig());
touchBeforeRequest(pc);
}
void setTimeSpan(PageContext pc) {
ApplicationContext ac = pc.getApplicationContext();
this.timeSpan = getType() == SCOPE_SESSION ? ac.getSessionTimeout().getMillis() : ac.getClientTimeout().getMillis();
}
@Override
public void setMaxInactiveInterval(int interval) {
this.timeSpan = interval * 1000L;
}
@Override
public int getMaxInactiveInterval() {
return (int) (this.timeSpan / 1000L);
}
@Override
public final boolean isInitalized() {
return isinit;
}
public long lastModified() {
return lastModified;
}
@Override
public final void initialize(PageContext pc) {
// StorageScopes need only request initialisation no global init, they are not reused;
}
@Override
public void touchAfterRequest(PageContext pc) {
setTimeSpan(pc);
data0.put(KeyConstants._lastvisit, new IKStorageScopeItem(_lastvisit));
data0.put(KeyConstants._timecreated, new IKStorageScopeItem(timecreated));
if (type == SCOPE_CLIENT) {
data0.put(KeyConstants._hitcount, new IKStorageScopeItem(new Double(hitcount)));
}
ApplicationContext ac = pc.getApplicationContext();
if (ac != null && (this.tokens == null || this.tokens.isEmpty()) && ac.getSessionCluster() && isSessionStorage(pc)) {
data0.remove(KeyConstants._csrf_token);
}
store(pc);
}
@Override
public final void release(PageContext pc) {
clear();
isinit = false;
}
/**
* @return returns if the scope is empty or not, this method ignore the "constant" entries of the
* scope (cfid,cftoken,urltoken)
*/
public boolean hasContent() {
int size = size();
if (size == 0) return false;
if (size > 7) return true;
if (size == 7 && !containsKey(KeyConstants._csrf_token)) return true;
return !(containsKey(KeyConstants._cfid) && containsKey(KeyConstants._cftoken) && containsKey(KeyConstants._urltoken) && containsKey(KeyConstants._timecreated)
&& containsKey(KeyConstants._lastvisit) && (type == SCOPE_CLIENT ? containsKey(KeyConstants._hitcount) : containsKey(KeyConstants._sessionid)));
}
@Override
public void clear() {
Iterator<Key> it = data0.keySet().iterator();
Key k;
while (it.hasNext()) {
k = it.next();
removeEL(k);
}
}
@Override
public final boolean containsKey(Key key) {
IKStorageScopeItem v = data0.getOrDefault(key, NULL);
return v != NULL && !v.removed();
}
@Override
public final boolean containsKey(PageContext pc, Key key) {
IKStorageScopeItem v = data0.getOrDefault(key, NULL);
return v != NULL && !v.removed();
}
@Override
public final Object get(Key key) throws PageException {
return get((PageContext) null, key);
}
@Override
public final Object get(PageContext pc, Key key) throws PageException {
IKStorageScopeItem v = data0.getOrDefault(key, null);
if (v == null) throw StructSupport.invalidKey(data0, key, false);
if (v.removed()) {
StringBuilder sb = new StringBuilder();
Iterator<?> it = keySet().iterator();
Object k;
while (it.hasNext()) {
k = it.next();
if (sb.length() > 0) sb.append(", ");
sb.append(k.toString());
}
return new ExpressionException("key [" + key + "] doesn't exist (existing keys: [" + sb.toString() + "])");
}
return v.getValue();
}
@Override
public final Object get(Key key, Object defaultValue) {
return get((PageContext) null, key, defaultValue);
}
@Override
public final Object get(PageContext pc, Key key, Object defaultValue) {
IKStorageScopeItem v = data0.getOrDefault(key, NULL);
if (v == NULL || v.removed()) return defaultValue;
return v.getValue();
}
@Override
public Iterator<Collection.Key> keyIterator() {
return keySet().iterator();
}
@Override
public Set<Collection.Key> keySet() {
Set<Collection.Key> keys = new HashSet<Collection.Key>();
Iterator<Entry<Key, IKStorageScopeItem>> it = data0.entrySet().iterator();
Entry<Key, IKStorageScopeItem> e;
IKStorageScopeItem v;
while (it.hasNext()) {
e = it.next();
v = e.getValue();
if (v != NULL && !v.removed()) keys.add(e.getKey());
}
return keys;
}
@Override
public Iterator<Entry<Key, Object>> entryIterator() {
return new EntryIterator(this, keys());
}
@Override
public Iterator<Object> valueIterator() {
return new ValueIterator(this, keys()); // TODO use or make a faster iterator
}
@Override
public lucee.runtime.type.Collection.Key[] keys() {
return CollectionUtil.keys(this);
}
@Override
public Object remove(Key key) throws PageException {
hasChanges = true;
IKStorageScopeItem existing = data0.get(key);
if (existing != null) {
return existing.remove();
}
throw new ExpressionException("can't remove key [" + key.getString() + "] from map, key doesn't exist");
}
@Override
public Object removeEL(Key key) {
hasChanges = true;
IKStorageScopeItem existing = data0.get(key);
if (existing != null) {
return existing.remove();
}
return null;
}
@Override
public Object set(Key key, Object value) throws PageException {
hasChanges = true;
return data0.put(key, new IKStorageScopeItem(value));
}
@Override
public Object setEL(Key key, Object value) {
hasChanges = true;
return data0.put(key, new IKStorageScopeItem(value));
}
@Override
public long lastVisit() {
return lastvisit;
}
public Collection.Key[] pureKeys() {
List<Collection.Key> keys = new ArrayList<Collection.Key>();
Iterator<Key> it = keyIterator();
Collection.Key key;
while (it.hasNext()) {
key = it.next();
if (!FIX_KEYS.contains(key)) keys.add(key);
}
return keys.toArray(new Collection.Key[keys.size()]);
}
@Override
public int size() {
int size = 0;
Iterator<Entry<Key, IKStorageScopeItem>> it = data0.entrySet().iterator();
Entry<Key, IKStorageScopeItem> e;
IKStorageScopeItem v;
while (it.hasNext()) {
e = it.next();
v = e.getValue();
if (v != NULL && !v.removed()) size++;
}
return size;
}
public void store(PageContext pc) { // FUTURE add to interface
handler.store(this, pc, appName, name, data0, ThreadLocalPageContext.getLog(pc, "scope"));
}
public void unstore(PageContext pc) {
handler.unstore(this, pc, appName, name, ThreadLocalPageContext.getLog(pc, "scope"));
}
@Override
public void store(Config config) {
store(ThreadLocalPageContext.get());
}
@Override
public void unstore(Config config) {
unstore(ThreadLocalPageContext.get());
}
/**
* @return the hasChanges
*/
public boolean hasChanges() {
return hasChanges;
}
@Override
public boolean containsValue(Object value) {
Iterator<?> it = values().iterator();
while (it.hasNext()) {
if (it.next().equals(value)) return true;
}
return false;
}
@Override
public java.util.Collection values() {
java.util.Collection<Object> res = new ArrayList<Object>();
Iterator<IKStorageScopeItem> it = data0.values().iterator();
IKStorageScopeItem v;
while (it.hasNext()) {
v = it.next();
if (v != NULL && !v.removed()) res.add(v.getValue());
}
return res;
}
@Override
public final int getType() {
return type;
}
@Override
public final String getTypeAsString() {
return strType;
}
@Override
public final DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
return StructUtil.toDumpTable(this, StringUtil.ucFirst(getTypeAsString()) + " Scope (" + getStorageType() + ")", pageContext, maxlevel, dp);
}
@Override
public long getLastAccess() {
return lastvisit;
}
@Override
public long getTimeSpan() {
return timeSpan;
}
@Override
public void touch() {
lastvisit = System.currentTimeMillis();
_lastvisit = new DateTimeImpl(ThreadLocalPageContext.getConfig());
}
@Override
public boolean isExpired() {
return (getLastAccess() + getTimeSpan()) < System.currentTimeMillis();
}
@Override
public void setStorage(String storage) {
this.storage = storage;
}
@Override
public String getStorage() {
return storage;
}
public static String encode(String input) {
int len = input.length();
StringBuilder sb = new StringBuilder();
char c;
for (int i = 0; i < len; i++) {
c = input.charAt(i);
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '-') sb.append(c);
else {
sb.append('$');
sb.append(Integer.toString((c), Character.MAX_RADIX));
sb.append('$');
}
}
return sb.toString();
}
public static String decode(String input) {
int len = input.length();
StringBuilder sb = new StringBuilder();
char c;
int ni;
for (int i = 0; i < len; i++) {
c = input.charAt(i);
if (c == '$') {
ni = input.indexOf('$', i + 1);
sb.append((char) Integer.parseInt(input.substring(i + 1, ni), Character.MAX_RADIX));
i = ni;
}
else {
sb.append(c);
}
}
return sb.toString();
}
public int _getId() {
return id;
}
@Override
public long getCreated() {
return timecreated == null ? 0 : timecreated.getTime();
}
@Override
public String generateToken(String key, boolean forceNew) {
return ScopeUtil.generateCsrfToken(tokens, key, forceNew);
}
@Override
public boolean verifyToken(String token, String key) {
return ScopeUtil.verifyCsrfToken(tokens, token, key);
}
public static void merge(Map<Key, IKStorageScopeItem> local, Map<Key, IKStorageScopeItem> storage) {
Iterator<Entry<Key, IKStorageScopeItem>> it = local.entrySet().iterator();
Entry<Key, IKStorageScopeItem> e;
IKStorageScopeItem storageItem;
while (it.hasNext()) {
e = it.next();
storageItem = storage.get(e.getKey());
// this entry not exist in the storage
if (storageItem == null) {
if (!e.getValue().removed()) storage.put(e.getKey(), e.getValue());
}
// local is newer than storage
else if (e.getValue().lastModified() > storageItem.lastModified()) {
if (e.getValue().removed()) storage.remove(e.getKey());
else {
storage.put(e.getKey(), e.getValue());
}
}
// local is older than storage is ignored?
}
}
public static Map<Key, IKStorageScopeItem> cleanRemoved(Map<Key, IKStorageScopeItem> local) {
Iterator<Entry<Key, IKStorageScopeItem>> it = local.entrySet().iterator();
Entry<Key, IKStorageScopeItem> e;
while (it.hasNext()) {
e = it.next();
if (e.getValue().removed()) local.remove(e.getKey());
}
return local;
}
public static Map<Key, IKStorageScopeItem> prepareToStore(Map<Key, IKStorageScopeItem> local, Object oStorage, long lastModified) throws PageException {
// cached data changed in meantime
if (oStorage instanceof IKStorageValue) {
IKStorageValue storage = (IKStorageValue) oStorage;
if (storage.lastModified() > lastModified) {
Map<Key, IKStorageScopeItem> trg = storage.getValue();
IKStorageScopeSupport.merge(local, trg);
return trg;
}
else {
return IKStorageScopeSupport.cleanRemoved(local);
}
}
else if (oStorage instanceof byte[][]) {
byte[][] barrr = (byte[][]) oStorage;
if (IKStorageValue.toLong(barrr[1]) > lastModified) {
if (barrr[0] == null || barrr[0].length == 0) return local;
Map<Key, IKStorageScopeItem> trg = IKStorageValue.deserialize(barrr[0]);
IKStorageScopeSupport.merge(local, trg);
return trg;
}
else {
return IKStorageScopeSupport.cleanRemoved(local);
}
}
return local;
}
@Override
public final String getStorageType() {
return handler.getType();
}
protected static DateTime doNowIfNull(Config config, DateTime dt) {
if (dt == null) return new DateTimeImpl(config);
return dt;
}
private boolean isSessionStorage(PageContext pc) {
ApplicationContext ac = pc.getApplicationContext();
String storage = ac == null ? null : ac.getSessionstorage();
if (StringUtil.isEmpty(storage)) return false;
// datasource?
DataSource ds = pc.getDataSource(storage, null);
if (ds != null && ds.isStorage()) return true;
// cache
return CacheUtil.getCache(pc, storage, null) != null;
}
// protected abstract IKStorageValue loadData(PageContext pc, String appName, String name,String
// strType,int type, Log log) throws PageException;
}