FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jinjava/src/main/java/com/hubspot/jinjava/JinjavaConfig.java at master · liarfu/jinjava · GitHub
liarfu
/
jinjava
Public
forked from
HubSpot/jinjava
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
jinjava
/
src
/
main
/
java
/
com
/
hubspot
/
jinjava
/
JinjavaConfig.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
561 lines (465 loc) · 16.6 KB
Breadcrumbs
jinjava
/
src
/
main
/
java
/
com
/
hubspot
/
jinjava
/
JinjavaConfig.java
Copy path
File metadata and controls
561 lines (465 loc) · 16.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**********************************************************************
* Copyright (c) 2014 HubSpot Inc.
*
* 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.
**********************************************************************/
package
com
.
hubspot
.
jinjava
;
import
static
com
.
hubspot
.
jinjava
.
lib
.
fn
.
Functions
.
DEFAULT_RANGE_LIMIT
;
import
com
.
fasterxml
.
jackson
.
databind
.
ObjectMapper
;
import
com
.
fasterxml
.
jackson
.
databind
.
PropertyNamingStrategies
;
import
com
.
google
.
common
.
collect
.
ImmutableSet
;
import
com
.
hubspot
.
jinjava
.
el
.
JinjavaInterpreterResolver
;
import
com
.
hubspot
.
jinjava
.
el
.
JinjavaObjectUnwrapper
;
import
com
.
hubspot
.
jinjava
.
el
.
JinjavaProcessors
;
import
com
.
hubspot
.
jinjava
.
el
.
ObjectUnwrapper
;
import
com
.
hubspot
.
jinjava
.
features
.
FeatureConfig
;
import
com
.
hubspot
.
jinjava
.
features
.
Features
;
import
com
.
hubspot
.
jinjava
.
interpret
.
Context
;
import
com
.
hubspot
.
jinjava
.
interpret
.
Context
.
Library
;
import
com
.
hubspot
.
jinjava
.
interpret
.
InterpreterFactory
;
import
com
.
hubspot
.
jinjava
.
interpret
.
JinjavaInterpreter
;
import
com
.
hubspot
.
jinjava
.
interpret
.
JinjavaInterpreterFactory
;
import
com
.
hubspot
.
jinjava
.
mode
.
DefaultExecutionMode
;
import
com
.
hubspot
.
jinjava
.
mode
.
ExecutionMode
;
import
com
.
hubspot
.
jinjava
.
objects
.
date
.
CurrentDateTimeProvider
;
import
com
.
hubspot
.
jinjava
.
objects
.
date
.
DateTimeProvider
;
import
com
.
hubspot
.
jinjava
.
random
.
RandomNumberGeneratorStrategy
;
import
com
.
hubspot
.
jinjava
.
tree
.
Node
;
import
com
.
hubspot
.
jinjava
.
tree
.
parse
.
DefaultTokenScannerSymbols
;
import
com
.
hubspot
.
jinjava
.
tree
.
parse
.
TokenScannerSymbols
;
import
java
.
nio
.
charset
.
Charset
;
import
java
.
nio
.
charset
.
StandardCharsets
;
import
java
.
time
.
ZoneId
;
import
java
.
time
.
ZoneOffset
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Locale
;
import
java
.
util
.
Map
;
import
java
.
util
.
Set
;
import
java
.
util
.
function
.
BiConsumer
;
import
javax
.
annotation
.
Nullable
;
import
javax
.
el
.
ELResolver
;
public
class
JinjavaConfig
{
private
final
Charset
charset
;
private
final
Locale
locale
;
private
final
ZoneId
timeZone
;
private
final
int
maxRenderDepth
;
private
final
long
maxOutputSize
;
private
final
boolean
trimBlocks
;
private
final
boolean
lstripBlocks
;
private
final
boolean
enableRecursiveMacroCalls
;
private
final
int
maxMacroRecursionDepth
;
private
final
Map
<
Library
,
Set
<
String
>>
disabled
;
private
final
Set
<
String
>
restrictedMethods
;
private
final
Set
<
String
>
restrictedProperties
;
private
final
boolean
failOnUnknownTokens
;
private
final
boolean
nestedInterpretationEnabled
;
private
final
RandomNumberGeneratorStrategy
randomNumberGenerator
;
private
final
boolean
validationMode
;
private
final
long
maxStringLength
;
private
final
int
maxListSize
;
private
final
int
maxMapSize
;
private
final
int
rangeLimit
;
private
final
int
maxNumDeferredTokens
;
private
final
InterpreterFactory
interpreterFactory
;
private
final
DateTimeProvider
dateTimeProvider
;
private
TokenScannerSymbols
tokenScannerSymbols
;
private
final
ELResolver
elResolver
;
private
final
ExecutionMode
executionMode
;
private
final
LegacyOverrides
legacyOverrides
;
private
final
boolean
enablePreciseDivideFilter
;
private
final
ObjectMapper
objectMapper
;
private
final
Features
features
;
private
final
ObjectUnwrapper
objectUnwrapper
;
private
final
JinjavaProcessors
processors
;
public
static
Builder
newBuilder
() {
return
new
Builder
();
}
public
JinjavaConfig
() {
this
(
newBuilder
());
}
public
JinjavaConfig
(
InterpreterFactory
interpreterFactory
) {
this
(
newBuilder
().
withInterperterFactory
(
interpreterFactory
));
}
public
JinjavaConfig
(
Charset
charset
,
Locale
locale
,
ZoneId
timeZone
,
int
maxRenderDepth
) {
this
(
newBuilder
()
.
withCharset
(
charset
)
.
withLocale
(
locale
)
.
withTimeZone
(
timeZone
)
.
withMaxRenderDepth
(
maxRenderDepth
)
);
}
private
JinjavaConfig
(
Builder
builder
) {
charset
=
builder
.
charset
;
locale
=
builder
.
locale
;
timeZone
=
builder
.
timeZone
;
maxRenderDepth
=
builder
.
maxRenderDepth
;
disabled
=
builder
.
disabled
;
restrictedMethods
=
builder
.
restrictedMethods
;
restrictedProperties
=
builder
.
restrictedProperties
;
trimBlocks
=
builder
.
trimBlocks
;
lstripBlocks
=
builder
.
lstripBlocks
;
enableRecursiveMacroCalls
=
builder
.
enableRecursiveMacroCalls
;
maxMacroRecursionDepth
=
builder
.
maxMacroRecursionDepth
;
failOnUnknownTokens
=
builder
.
failOnUnknownTokens
;
maxOutputSize
=
builder
.
maxOutputSize
;
nestedInterpretationEnabled
=
builder
.
nestedInterpretationEnabled
;
randomNumberGenerator
=
builder
.
randomNumberGeneratorStrategy
;
validationMode
=
builder
.
validationMode
;
maxStringLength
=
builder
.
maxStringLength
;
maxListSize
=
builder
.
maxListSize
;
maxMapSize
=
builder
.
maxMapSize
;
rangeLimit
=
builder
.
rangeLimit
;
maxNumDeferredTokens
=
builder
.
maxNumDeferredTokens
;
interpreterFactory
=
builder
.
interpreterFactory
;
tokenScannerSymbols
=
builder
.
tokenScannerSymbols
;
elResolver
=
builder
.
elResolver
;
executionMode
=
builder
.
executionMode
;
legacyOverrides
=
builder
.
legacyOverrides
;
dateTimeProvider
=
builder
.
dateTimeProvider
;
enablePreciseDivideFilter
=
builder
.
enablePreciseDivideFilter
;
objectMapper
=
setupObjectMapper
(
builder
.
objectMapper
);
objectUnwrapper
=
builder
.
objectUnwrapper
;
processors
=
builder
.
processors
;
features
=
new
Features
(
builder
.
featureConfig
);
}
private
ObjectMapper
setupObjectMapper
(
@
Nullable
ObjectMapper
objectMapper
) {
if
(
objectMapper
==
null
) {
objectMapper
=
new
ObjectMapper
();
if
(
legacyOverrides
.
isUseSnakeCasePropertyNaming
()) {
objectMapper
.
setPropertyNamingStrategy
(
PropertyNamingStrategies
.
SNAKE_CASE
);
}
}
return
objectMapper
;
}
public
Charset
getCharset
() {
return
charset
;
}
public
Locale
getLocale
() {
return
locale
;
}
public
ZoneId
getTimeZone
() {
return
timeZone
;
}
public
int
getMaxRenderDepth
() {
return
maxRenderDepth
;
}
public
long
getMaxOutputSize
() {
return
maxOutputSize
;
}
public
int
getMaxListSize
() {
return
maxListSize
;
}
public
int
getMaxMapSize
() {
return
maxMapSize
;
}
public
int
getRangeLimit
() {
return
rangeLimit
;
}
public
int
getMaxNumDeferredTokens
() {
return
maxNumDeferredTokens
;
}
public
RandomNumberGeneratorStrategy
getRandomNumberGeneratorStrategy
() {
return
randomNumberGenerator
;
}
public
boolean
isTrimBlocks
() {
return
trimBlocks
;
}
public
boolean
isLstripBlocks
() {
return
lstripBlocks
;
}
public
boolean
isEnableRecursiveMacroCalls
() {
return
enableRecursiveMacroCalls
;
}
public
int
getMaxMacroRecursionDepth
() {
return
maxMacroRecursionDepth
;
}
public
Map
<
Library
,
Set
<
String
>>
getDisabled
() {
return
disabled
;
}
public
Set
<
String
>
getRestrictedMethods
() {
return
restrictedMethods
;
}
public
Set
<
String
>
getRestrictedProperties
() {
return
restrictedProperties
;
}
public
boolean
isFailOnUnknownTokens
() {
return
failOnUnknownTokens
;
}
public
boolean
isNestedInterpretationEnabled
() {
return
nestedInterpretationEnabled
;
}
public
boolean
isValidationMode
() {
return
validationMode
;
}
public
long
getMaxStringLength
() {
return
maxStringLength
==
0
?
getMaxOutputSize
() :
maxStringLength
;
}
public
InterpreterFactory
getInterpreterFactory
() {
return
interpreterFactory
;
}
public
TokenScannerSymbols
getTokenScannerSymbols
() {
return
tokenScannerSymbols
;
}
public
void
setTokenScannerSymbols
(
TokenScannerSymbols
tokenScannerSymbols
) {
this
.
tokenScannerSymbols
=
tokenScannerSymbols
;
}
public
ELResolver
getElResolver
() {
return
elResolver
;
}
public
ObjectMapper
getObjectMapper
() {
return
objectMapper
;
}
public
ObjectUnwrapper
getObjectUnwrapper
() {
return
objectUnwrapper
;
}
/**
* @deprecated Use {@link #getProcessors()} and {@link JinjavaProcessors#getNodePreProcessor()}
*/
@
Deprecated
public
BiConsumer
<
Node
,
JinjavaInterpreter
>
getNodePreProcessor
() {
return
processors
.
getNodePreProcessor
();
}
public
JinjavaProcessors
getProcessors
() {
return
processors
;
}
/**
* @deprecated Replaced by {@link LegacyOverrides#isIterateOverMapKeys()}
*/
@
Deprecated
public
boolean
isIterateOverMapKeys
() {
return
legacyOverrides
.
isIterateOverMapKeys
();
}
public
ExecutionMode
getExecutionMode
() {
return
executionMode
;
}
public
LegacyOverrides
getLegacyOverrides
() {
return
legacyOverrides
;
}
public
boolean
getEnablePreciseDivideFilter
() {
return
enablePreciseDivideFilter
;
}
public
DateTimeProvider
getDateTimeProvider
() {
return
dateTimeProvider
;
}
public
Features
getFeatures
() {
return
features
;
}
public
static
class
Builder
{
private
Charset
charset
=
StandardCharsets
.
UTF_8
;
private
Locale
locale
=
Locale
.
ENGLISH
;
private
ZoneId
timeZone
=
ZoneOffset
.
UTC
;
private
int
maxRenderDepth
=
10
;
private
long
maxOutputSize
=
0
;
// in bytes
private
Map
<
Context
.
Library
,
Set
<
String
>>
disabled
=
new
HashMap
<>();
private
Set
<
String
>
restrictedMethods
=
ImmutableSet
.
of
();
private
Set
<
String
>
restrictedProperties
=
ImmutableSet
.
of
();
private
boolean
trimBlocks
;
private
boolean
lstripBlocks
;
private
boolean
enableRecursiveMacroCalls
;
private
int
maxMacroRecursionDepth
;
private
boolean
failOnUnknownTokens
;
private
boolean
nestedInterpretationEnabled
=
true
;
private
RandomNumberGeneratorStrategy
randomNumberGeneratorStrategy
=
RandomNumberGeneratorStrategy
.
THREAD_LOCAL
;
private
DateTimeProvider
dateTimeProvider
=
new
CurrentDateTimeProvider
();
private
boolean
validationMode
=
false
;
private
long
maxStringLength
=
0
;
private
int
rangeLimit
=
DEFAULT_RANGE_LIMIT
;
private
int
maxNumDeferredTokens
=
1000
;
private
InterpreterFactory
interpreterFactory
=
new
JinjavaInterpreterFactory
();
private
TokenScannerSymbols
tokenScannerSymbols
=
new
DefaultTokenScannerSymbols
();
private
ELResolver
elResolver
=
JinjavaInterpreterResolver
.
DEFAULT_RESOLVER_READ_ONLY
;
private
int
maxListSize
=
Integer
.
MAX_VALUE
;
private
int
maxMapSize
=
Integer
.
MAX_VALUE
;
private
ExecutionMode
executionMode
=
DefaultExecutionMode
.
instance
();
private
LegacyOverrides
legacyOverrides
=
LegacyOverrides
.
NONE
;
private
boolean
enablePreciseDivideFilter
=
false
;
private
ObjectMapper
objectMapper
=
null
;
private
ObjectUnwrapper
objectUnwrapper
=
new
JinjavaObjectUnwrapper
();
private
JinjavaProcessors
processors
=
JinjavaProcessors
.
newBuilder
().
build
();
private
FeatureConfig
featureConfig
=
FeatureConfig
.
newBuilder
().
build
();
private
Builder
() {}
public
Builder
withCharset
(
Charset
charset
) {
this
.
charset
=
charset
;
return
this
;
}
public
Builder
withLocale
(
Locale
locale
) {
this
.
locale
=
locale
;
return
this
;
}
public
Builder
withTimeZone
(
ZoneId
timeZone
) {
this
.
timeZone
=
timeZone
;
return
this
;
}
public
Builder
withDisabled
(
Map
<
Context
.
Library
,
Set
<
String
>>
disabled
) {
this
.
disabled
=
disabled
;
return
this
;
}
public
Builder
withRestrictedMethods
(
Set
<
String
>
restrictedMethods
) {
this
.
restrictedMethods
=
ImmutableSet
.
copyOf
(
restrictedMethods
);
return
this
;
}
public
Builder
withRestrictedProperties
(
Set
<
String
>
restrictedProperties
) {
this
.
restrictedProperties
=
ImmutableSet
.
copyOf
(
restrictedProperties
);
return
this
;
}
public
Builder
withMaxRenderDepth
(
int
maxRenderDepth
) {
this
.
maxRenderDepth
=
maxRenderDepth
;
return
this
;
}
public
Builder
withRandomNumberGeneratorStrategy
(
RandomNumberGeneratorStrategy
randomNumberGeneratorStrategy
) {
this
.
randomNumberGeneratorStrategy
=
randomNumberGeneratorStrategy
;
return
this
;
}
public
Builder
withDateTimeProvider
(
DateTimeProvider
dateTimeProvider
) {
this
.
dateTimeProvider
=
dateTimeProvider
;
return
this
;
}
public
Builder
withTrimBlocks
(
boolean
trimBlocks
) {
this
.
trimBlocks
=
trimBlocks
;
return
this
;
}
public
Builder
withLstripBlocks
(
boolean
lstripBlocks
) {
this
.
lstripBlocks
=
lstripBlocks
;
return
this
;
}
public
Builder
withEnableRecursiveMacroCalls
(
boolean
enableRecursiveMacroCalls
) {
this
.
enableRecursiveMacroCalls
=
enableRecursiveMacroCalls
;
return
this
;
}
public
Builder
withMaxMacroRecursionDepth
(
int
maxMacroRecursionDepth
) {
this
.
maxMacroRecursionDepth
=
maxMacroRecursionDepth
;
return
this
;
}
public
Builder
withReadOnlyResolver
(
boolean
readOnlyResolver
) {
this
.
elResolver
=
readOnlyResolver
?
JinjavaInterpreterResolver
.
DEFAULT_RESOLVER_READ_ONLY
:
JinjavaInterpreterResolver
.
DEFAULT_RESOLVER_READ_WRITE
;
return
this
;
}
public
Builder
withElResolver
(
ELResolver
elResolver
) {
this
.
elResolver
=
elResolver
;
return
this
;
}
public
Builder
withFailOnUnknownTokens
(
boolean
failOnUnknownTokens
) {
this
.
failOnUnknownTokens
=
failOnUnknownTokens
;
return
this
;
}
public
Builder
withMaxOutputSize
(
long
maxOutputSize
) {
this
.
maxOutputSize
=
maxOutputSize
;
return
this
;
}
public
Builder
withNestedInterpretationEnabled
(
boolean
nestedInterpretationEnabled
) {
this
.
nestedInterpretationEnabled
=
nestedInterpretationEnabled
;
return
this
;
}
public
Builder
withValidationMode
(
boolean
validationMode
) {
this
.
validationMode
=
validationMode
;
return
this
;
}
public
Builder
withMaxStringLength
(
long
maxStringLength
) {
this
.
maxStringLength
=
maxStringLength
;
return
this
;
}
public
Builder
withMaxListSize
(
int
maxListSize
) {
this
.
maxListSize
=
maxListSize
;
return
this
;
}
public
Builder
withMaxMapSize
(
int
maxMapSize
) {
this
.
maxMapSize
=
maxMapSize
;
return
this
;
}
public
Builder
withRangeLimit
(
int
rangeLimit
) {
this
.
rangeLimit
=
rangeLimit
;
return
this
;
}
public
Builder
withMaxNumDeferredTokens
(
int
maxNumDeferredTokens
) {
this
.
maxNumDeferredTokens
=
maxNumDeferredTokens
;
return
this
;
}
public
Builder
withInterperterFactory
(
InterpreterFactory
interperterFactory
) {
this
.
interpreterFactory
=
interperterFactory
;
return
this
;
}
public
Builder
withTokenScannerSymbols
(
TokenScannerSymbols
tokenScannerSymbols
) {
this
.
tokenScannerSymbols
=
tokenScannerSymbols
;
return
this
;
}
/**
* @deprecated Replaced by {@link LegacyOverrides.Builder#withIterateOverMapKeys(boolean)}}
*/
@
Deprecated
public
Builder
withIterateOverMapKeys
(
boolean
iterateOverMapKeys
) {
return
withLegacyOverrides
(
LegacyOverrides
.
Builder
.
from
(
legacyOverrides
)
.
withIterateOverMapKeys
(
iterateOverMapKeys
)
.
build
()
);
}
public
Builder
withExecutionMode
(
ExecutionMode
executionMode
) {
this
.
executionMode
=
executionMode
;
return
this
;
}
public
Builder
withLegacyOverrides
(
LegacyOverrides
legacyOverrides
) {
this
.
legacyOverrides
=
legacyOverrides
;
return
this
;
}
public
Builder
withEnablePreciseDivideFilter
(
boolean
enablePreciseDivideFilter
) {
this
.
enablePreciseDivideFilter
=
enablePreciseDivideFilter
;
return
this
;
}
public
Builder
withObjectMapper
(
ObjectMapper
objectMapper
) {
this
.
objectMapper
=
objectMapper
;
return
this
;
}
public
Builder
withObjectUnwrapper
(
ObjectUnwrapper
objectUnwrapper
) {
this
.
objectUnwrapper
=
objectUnwrapper
;
return
this
;
}
@
Deprecated
/**
* @deprecated use {@link #withProcessors(JinjavaProcessors)}
*/
public
Builder
withNodePreProcessor
(
BiConsumer
<
Node
,
JinjavaInterpreter
>
nodePreProcessor
) {
this
.
processors
=
JinjavaProcessors
.
newBuilder
(
processors
)
.
withNodePreProcessor
(
nodePreProcessor
)
.
build
();
return
this
;
}
public
Builder
withProcessors
(
JinjavaProcessors
jinjavaProcessors
) {
this
.
processors
=
jinjavaProcessors
;
return
this
;
}
public
Builder
withFeatureConfig
(
FeatureConfig
featureConfig
) {
this
.
featureConfig
=
featureConfig
;
return
this
;
}
public
JinjavaConfig
build
() {
return
new
JinjavaConfig
(
this
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL