-
Notifications
You must be signed in to change notification settings - Fork 40
/
PageInfo.java
760 lines (619 loc) · 18.4 KB
/
PageInfo.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
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
* 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 org.apache.jasper.compiler;
import java.util.*;
import org.apache.jasper.Constants;
import org.apache.jasper.JasperException;
import jakarta.servlet.jsp.tagext.TagLibraryInfo;
/**
* A repository for various info about the translation unit under compilation.
*
* @author Kin-man Chung
*/
public class PageInfo {
/**
* These classes/packages are automatically imported by the
* generated code.
*/
private static final String[] STANDARD_IMPORTS = {
"jakarta.servlet.*",
"jakarta.servlet.http.*",
"jakarta.servlet.jsp.*"
};
private List<String> imports;
private List<String> dependants;
private BeanRepository beanRepository;
private HashMap<String, TagLibraryInfo> taglibsMap;
private HashMap<String, String> jspPrefixMapper;
private HashMap<String, LinkedList<String>> xmlPrefixMapper;
private HashMap<String, Mark> nonCustomTagPrefixMap;
private String jspFile;
private String defaultLanguage = "java";
private String language;
private String defaultExtends = Constants.JSP_SERVLET_BASE;
private String xtends;
private String contentType = null;
private String session;
private boolean isSession = true;
private String bufferValue;
private int buffer = 8*1024; // XXX confirm
private String autoFlush;
private boolean isAutoFlush = true;
private String isThreadSafeValue;
private boolean isThreadSafe = true;
private String isErrorPageValue;
private boolean isErrorPage = false;
private String errorPage = null;
private String info;
private int maxTagNesting = 0;
private boolean scriptless = false;
private boolean scriptingInvalid = false;
private String isELIgnoredValue;
private boolean isELIgnored = false;
private String omitXmlDecl = null;
private String doctypeName = null;
private String doctypePublic = null;
private String doctypeSystem = null;
private String deferredSyntaxAllowedAsLiteralValue;
private boolean deferredSyntaxAllowedAsLiteral = false;
private String trimDirectiveWhitespacesValue;
private boolean trimDirectiveWhitespaces = false;
private boolean errorOnUndeclaredNamespace = false;
private boolean isJspPrefixHijacked;
// Set of all element and attribute prefixes used in this translation unit
private HashSet<String> prefixes;
private boolean hasJspRoot = false;
private List<String> includePrelude;
private List<String> includeCoda;
private List<String> pluginDcls; // Id's for tagplugin declarations
// Resource location path of the translation unit's top-level page
private String rootPath;
PageInfo(BeanRepository beanRepository, String jspFile) {
this.jspFile = jspFile;
this.beanRepository = beanRepository;
this.taglibsMap = new HashMap<String, TagLibraryInfo>();
this.jspPrefixMapper = new HashMap<String, String>();
this.xmlPrefixMapper = new HashMap<String, LinkedList<String>>();
this.nonCustomTagPrefixMap = new HashMap<String, Mark>();
this.imports = new ArrayList<String>();
this.dependants = new ArrayList<String>();
this.includePrelude = new ArrayList<String>();
this.includeCoda = new ArrayList<String>();
this.pluginDcls = new ArrayList<String>();
this.prefixes = new HashSet<String>();
// Enter standard imports
for(int i = 0; i < STANDARD_IMPORTS.length; i++)
imports.add(STANDARD_IMPORTS[i]);
}
/**
* Check if the plugin ID has been previously declared. Make a not
* that this Id is now declared.
* @return true if Id has been declared.
*/
public boolean isPluginDeclared(String id) {
if (pluginDcls.contains(id))
return true;
pluginDcls.add(id);
return false;
}
public void addImports(List<String> imports) {
this.imports.addAll(imports);
}
public void addImport(String imp) {
this.imports.add(imp);
}
public List<String> getImports() {
return imports;
}
public String getJspFile() {
return jspFile;
}
public void addDependant(String d) {
if (!dependants.contains(d) && !jspFile.equals(d))
dependants.add(d);
}
public List<String> getDependants() {
return dependants;
}
public BeanRepository getBeanRepository() {
return beanRepository;
}
public int getMaxTagNesting() {
return maxTagNesting;
}
public void setMaxTagNesting(int maxTagNesting) {
this.maxTagNesting = maxTagNesting;
}
public void setScriptless(boolean s) {
scriptless = s;
}
public boolean isScriptless() {
return scriptless;
}
public void setScriptingInvalid(boolean s) {
scriptingInvalid = s;
}
public boolean isScriptingInvalid() {
return scriptingInvalid;
}
public List<String> getIncludePrelude() {
return includePrelude;
}
public void setIncludePrelude(List<String> prelude) {
includePrelude = prelude;
}
public List<String> getIncludeCoda() {
return includeCoda;
}
public void setIncludeCoda(List<String> coda) {
includeCoda = coda;
}
public void setHasJspRoot(boolean s) {
hasJspRoot = s;
}
public boolean hasJspRoot() {
return hasJspRoot;
}
public String getOmitXmlDecl() {
return omitXmlDecl;
}
public void setOmitXmlDecl(String omit) {
omitXmlDecl = omit;
}
public String getDoctypeName() {
return doctypeName;
}
public void setDoctypeName(String doctypeName) {
this.doctypeName = doctypeName;
}
public String getDoctypeSystem() {
return doctypeSystem;
}
public void setDoctypeSystem(String doctypeSystem) {
this.doctypeSystem = doctypeSystem;
}
public String getDoctypePublic() {
return doctypePublic;
}
public void setDoctypePublic(String doctypePublic) {
this.doctypePublic = doctypePublic;
}
/* Tag library and XML namespace management methods */
public void setIsJspPrefixHijacked(boolean isHijacked) {
isJspPrefixHijacked = isHijacked;
}
public boolean isJspPrefixHijacked() {
return isJspPrefixHijacked;
}
/*
* Adds the given prefix to the set of prefixes of this translation unit.
*
* @param prefix The prefix to add
*/
public void addPrefix(String prefix) {
prefixes.add(prefix);
}
/*
* Checks to see if this translation unit contains the given prefix.
*
* @param prefix The prefix to check
*
* @return true if this translation unit contains the given prefix, false
* otherwise
*/
public boolean containsPrefix(String prefix) {
return prefixes.contains(prefix);
}
/*
* Maps the given URI to the given tag library.
*
* @param uri The URI to map
* @param info The tag library to be associated with the given URI
*/
public void addTaglib(String uri, TagLibraryInfo info) {
taglibsMap.put(uri, info);
}
/*
* Gets the tag library corresponding to the given URI.
*
* @return Tag library corresponding to the given URI
*/
public TagLibraryInfo getTaglib(String uri) {
return taglibsMap.get(uri);
}
/*
* Gets the collection of tag libraries that are associated with a URI
*
* @return Collection of tag libraries that are associated with a URI
*/
public Collection<TagLibraryInfo> getTaglibs() {
return taglibsMap.values();
}
/*
* Checks to see if the given URI is mapped to a tag library.
*
* @param uri The URI to map
*
* @return true if the given URI is mapped to a tag library, false
* otherwise
*/
public boolean hasTaglib(String uri) {
return taglibsMap.containsKey(uri);
}
/*
* Maps the given prefix to the given URI.
*
* @param prefix The prefix to map
* @param uri The URI to be associated with the given prefix
*/
public void addPrefixMapping(String prefix, String uri) {
jspPrefixMapper.put(prefix, uri);
}
/*
* Pushes the given URI onto the stack of URIs to which the given prefix
* is mapped.
*
* @param prefix The prefix whose stack of URIs is to be pushed
* @param uri The URI to be pushed onto the stack
*/
public void pushPrefixMapping(String prefix, String uri) {
LinkedList<String> stack = xmlPrefixMapper.get(prefix);
if (stack == null) {
stack = new LinkedList<String>();
xmlPrefixMapper.put(prefix, stack);
}
stack.addFirst(uri);
}
/*
* Removes the URI at the top of the stack of URIs to which the given
* prefix is mapped.
*
* @param prefix The prefix whose stack of URIs is to be popped
*/
public void popPrefixMapping(String prefix) {
LinkedList<String> stack = xmlPrefixMapper.get(prefix);
if (stack == null || stack.size() == 0) {
// XXX throw new Exception("XXX");
}
stack.removeFirst();
}
/*
* Returns the URI to which the given prefix maps.
*
* @param prefix The prefix whose URI is sought
*
* @return The URI to which the given prefix maps
*/
public String getURI(String prefix) {
String uri = null;
LinkedList<String> stack = xmlPrefixMapper.get(prefix);
if (stack == null || stack.size() == 0) {
uri = (String) jspPrefixMapper.get(prefix);
} else {
uri = (String) stack.getFirst();
}
return uri;
}
/* Page/Tag directive attributes */
/*
* language
*/
public void setLanguage(String value, Node n, ErrorDispatcher err,
boolean pagedir)
throws JasperException {
if (!"java".equalsIgnoreCase(value)) {
if (pagedir)
err.jspError(n, "jsp.error.page.language.nonjava");
else
err.jspError(n, "jsp.error.tag.language.nonjava");
}
language = value;
}
public String getLanguage(boolean useDefault) {
return (language == null && useDefault ? defaultLanguage : language);
}
public String getLanguage() {
return getLanguage(true);
}
/*
* extends
*/
public void setExtends(String value, Node.PageDirective n) {
xtends = value;
/*
* If page superclass is top level class (i.e. not in a package)
* explicitly import it. If this is not done, the compiler will assume
* the extended class is in the same pkg as the generated servlet.
*/
if (value.indexOf('.') < 0)
n.addImport(value);
}
/**
* Gets the value of the 'extends' page directive attribute.
*
* @param useDefault TRUE if the default
* (org.apache.jasper.runtime.HttpJspBase) should be returned if this
* attribute has not been set, FALSE otherwise
*
* @return The value of the 'extends' page directive attribute, or the
* default (org.apache.jasper.runtime.HttpJspBase) if this attribute has
* not been set and useDefault is TRUE
*/
public String getExtends(boolean useDefault) {
return (xtends == null && useDefault ? defaultExtends : xtends);
}
/**
* Gets the value of the 'extends' page directive attribute.
*
* @return The value of the 'extends' page directive attribute, or the
* default (org.apache.jasper.runtime.HttpJspBase) if this attribute has
* not been set
*/
public String getExtends() {
return getExtends(true);
}
/*
* contentType
*/
public void setContentType(String value) {
contentType = value;
}
public String getContentType() {
return contentType;
}
/*
* buffer
*/
public void setBufferValue(String value, Node n, ErrorDispatcher err)
throws JasperException {
if ("none".equalsIgnoreCase(value))
buffer = 0;
else {
if (value == null || !value.endsWith("kb"))
if (n == null)
err.jspError("jsp.error.jspproperty.invalid.buffer");
else
err.jspError(n, "jsp.error.page.invalid.buffer");
try {
Integer k = new Integer(value.substring(0, value.length()-2));
buffer = k.intValue() * 1024;
} catch (NumberFormatException e) {
if (n == null)
err.jspError("jsp.error.jspproperty.invalid.buffer");
else
err.jspError(n, "jsp.error.page.invalid.buffer");
}
}
bufferValue = value;
}
public String getBufferValue() {
return bufferValue;
}
public int getBuffer() {
return buffer;
}
public void setBuffer(int size) {
buffer = size;
}
/*
* session
*/
public void setSession(String value, Node n, ErrorDispatcher err)
throws JasperException {
if ("true".equalsIgnoreCase(value))
isSession = true;
else if ("false".equalsIgnoreCase(value))
isSession = false;
else
err.jspError(n, "jsp.error.page.invalid.session");
session = value;
}
public String getSession() {
return session;
}
public boolean isSession() {
return isSession;
}
/*
* autoFlush
*/
public void setAutoFlush(String value, Node n, ErrorDispatcher err)
throws JasperException {
if ("true".equalsIgnoreCase(value))
isAutoFlush = true;
else if ("false".equalsIgnoreCase(value))
isAutoFlush = false;
else
err.jspError(n, "jsp.error.autoFlush.invalid");
autoFlush = value;
}
public String getAutoFlush() {
return autoFlush;
}
public boolean isAutoFlush() {
return isAutoFlush;
}
/*
* isThreadSafe
*/
public void setIsThreadSafe(String value, Node n, ErrorDispatcher err)
throws JasperException {
if ("true".equalsIgnoreCase(value))
isThreadSafe = true;
else if ("false".equalsIgnoreCase(value))
isThreadSafe = false;
else
err.jspError(n, "jsp.error.page.invalid.isthreadsafe");
isThreadSafeValue = value;
}
public String getIsThreadSafe() {
return isThreadSafeValue;
}
public boolean isThreadSafe() {
return isThreadSafe;
}
/*
* info
*/
public void setInfo(String value) {
info = value;
}
public String getInfo() {
return info;
}
/*
* errorPage
*/
public void setErrorPage(String value) {
errorPage = value;
}
public String getErrorPage() {
return errorPage;
}
/*
* isErrorPage
*/
public void setIsErrorPage(String value, Node n, ErrorDispatcher err)
throws JasperException {
if ("true".equalsIgnoreCase(value))
isErrorPage = true;
else if ("false".equalsIgnoreCase(value))
isErrorPage = false;
else
err.jspError(n, "jsp.error.page.invalid.iserrorpage");
isErrorPageValue = value;
}
public String getIsErrorPage() {
return isErrorPageValue;
}
public boolean isErrorPage() {
return isErrorPage;
}
/*
* isELIgnored
*/
public void setIsELIgnored(String value, Node n, ErrorDispatcher err,
boolean pagedir)
throws JasperException {
if ("true".equalsIgnoreCase(value))
isELIgnored = true;
else if ("false".equalsIgnoreCase(value))
isELIgnored = false;
else {
if (pagedir)
err.jspError(n, "jsp.error.page.invalid.iselignored");
else
err.jspError(n, "jsp.error.tag.invalid.iselignored");
}
isELIgnoredValue = value;
}
public void setELIgnored(boolean s) {
isELIgnored = s;
}
public String getIsELIgnored() {
return isELIgnoredValue;
}
public boolean isELIgnored() {
return isELIgnored;
}
/*
* deferredSyntaxAllowedAsLiteral
*/
public void setDeferredSyntaxAllowedAsLiteral(String value, Node n,
ErrorDispatcher err, boolean pagedir)
throws JasperException {
if ("true".equalsIgnoreCase(value))
deferredSyntaxAllowedAsLiteral = true;
else if ("false".equalsIgnoreCase(value))
deferredSyntaxAllowedAsLiteral = false;
else {
if (pagedir)
err.jspError(n, "jsp.error.page.invalid.deferred");
else
err.jspError(n, "jsp.error.tag.invalid.deferred");
}
deferredSyntaxAllowedAsLiteralValue = value;
}
public void setDeferredSyntaxAllowedAsLiteral(boolean s) {
deferredSyntaxAllowedAsLiteral = s;
}
public String getDeferredSyntaxAllowedAsLiteral() {
return deferredSyntaxAllowedAsLiteralValue;
}
public boolean isDeferredSyntaxAllowedAsLiteral() {
return deferredSyntaxAllowedAsLiteral;
}
/*
* trimDirectiveWhitespaces
*/
public void setTrimDirectiveWhitespaces(String value, Node n,
ErrorDispatcher err, boolean pagedir)
throws JasperException {
if ("true".equalsIgnoreCase(value))
trimDirectiveWhitespaces = true;
else if ("false".equalsIgnoreCase(value))
trimDirectiveWhitespaces = false;
else {
if (pagedir)
err.jspError(n, "jsp.error.page.invalid.trim");
else
err.jspError(n, "jsp.error.tag.invalid.trim");
}
trimDirectiveWhitespacesValue = value;
}
public void setTrimDirectiveWhitespaces(boolean s) {
trimDirectiveWhitespaces = s;
}
public String getTrimDirectiveWhitespaces() {
return trimDirectiveWhitespacesValue;
}
public boolean isTrimDirectiveWhitespaces() {
return trimDirectiveWhitespaces;
}
public void setErrorOnUndeclaredNamespace(boolean s) {
errorOnUndeclaredNamespace = s;
}
public boolean errorOnUndeclaredNamespace() {
return this.errorOnUndeclaredNamespace;
}
public void putNonCustomTagPrefix(String prefix, Mark where) {
nonCustomTagPrefixMap.put(prefix, where);
}
public Mark getNonCustomTagPrefix(String prefix) {
return nonCustomTagPrefixMap.get(prefix);
}
/**
* Sets the resource location path of the translation unit's top-level
* page.
*
* @param rootPath Resource location path of the translation unit's
* top-level page
*/
void setRootPath(String rootPath) {
this.rootPath = rootPath;
}
/**
* Gets the resource location path of the translation unit's top-level
* page.
*
* @return Resource location path of the translation unit's top-level
* page
*/
String getRootPath() {
return rootPath;
}
}