-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
ReaderConfig.java
1775 lines (1494 loc) · 59.6 KB
/
ReaderConfig.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
package com.ctc.wstx.api;
import java.lang.ref.SoftReference;
import java.net.URL;
import java.util.*;
import javax.xml.XMLConstants;
import javax.xml.stream.*;
import org.codehaus.stax2.XMLInputFactory2; // for property consts
import org.codehaus.stax2.XMLStreamProperties; // for property consts
import org.codehaus.stax2.validation.DTDValidationSchema;
import com.ctc.wstx.cfg.InputConfigFlags;
import com.ctc.wstx.dtd.DTDEventListener;
import com.ctc.wstx.ent.IntEntity;
import com.ctc.wstx.ent.EntityDecl;
import com.ctc.wstx.io.BufferRecycler;
import com.ctc.wstx.util.ArgUtil;
import com.ctc.wstx.util.DataUtil;
import com.ctc.wstx.util.SymbolTable;
/**
* Simple configuration container class; passed by reader factory to reader
* instance created.
*<p>
* In addition to its main task as a configuration container, this class
* also acts as a wrapper around simple buffer recycling functionality.
* The reason is that while conceptually this is a separate concern,
* there are enough commonalities with the life-cycle of this object to
* make this a very convenience place to add that functionality...
* (that is: conceptually this is not right, but from pragmatic viewpoint
* it just makes sense)
*/
public final class ReaderConfig
extends CommonConfig
implements InputConfigFlags
{
// Default limit values
public final static int DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT = 1000;
public final static int DEFAULT_MAX_ATTRIBUTE_LENGTH = 65536 * 8;
public final static int DEFAULT_MAX_ELEMENT_DEPTH = 1000;
public final static int DEFAULT_MAX_ENTITY_DEPTH = 500;
public final static int DEFAULT_MAX_ENTITY_COUNT = 100 * 1000;
/*
///////////////////////////////////////////////////////////////////////
// Constants for reader properties:
///////////////////////////////////////////////////////////////////////
*/
// // First, standard StAX properties:
// Simple flags:
final static int PROP_COALESCE_TEXT = 1;
final static int PROP_NAMESPACE_AWARE = 2;
final static int PROP_REPLACE_ENTITY_REFS = 3;
final static int PROP_SUPPORT_EXTERNAL_ENTITIES = 4;
final static int PROP_VALIDATE_AGAINST_DTD = 5;
final static int PROP_SUPPORT_DTD = 6;
// Object type properties
public final static int PROP_EVENT_ALLOCATOR = 7;
final static int PROP_WARNING_REPORTER = 8;
final static int PROP_XML_RESOLVER = 9;
// // Then StAX2 standard properties:
// Simple flags:
final static int PROP_INTERN_NS_URIS = 20;
final static int PROP_INTERN_NAMES = 21;
final static int PROP_REPORT_CDATA = 22;
final static int PROP_REPORT_PROLOG_WS = 23;
final static int PROP_PRESERVE_LOCATION = 24;
final static int PROP_AUTO_CLOSE_INPUT = 25;
// Enum / Object type properties:
final static int PROP_SUPPORT_XMLID = 26; // shared with WriterConfig
final static int PROP_DTD_OVERRIDE = 27;
// And then JAXB feature(s) (since 5.3)
final static int PROP_JAXP_SECURE_PROCESSING = 30;
// // // Constants for additional Wstx properties:
// Simple flags:
/**
* Note: this entry was deprecated for 4.0 versions up until
* and including 4.0.7; was brought back for 4.0.8 (and will
* be retained for 4.1)
*/
final static int PROP_NORMALIZE_LFS = 40;
/* This entry was deprecated for 3.2 and removed in 4.0
* version. There are no plans to bring it back.
*/
//final static int PROP_NORMALIZE_ATTR_VALUES = 41;
final static int PROP_CACHE_DTDS = 42;
final static int PROP_CACHE_DTDS_BY_PUBLIC_ID = 43;
final static int PROP_LAZY_PARSING = 44;
final static int PROP_SUPPORT_DTDPP = 45;
final static int PROP_TREAT_CHAR_REFS_AS_ENTS = 46;
/**
* @since 5.2
*/
final static int PROP_ALLOW_XML11_ESCAPED_CHARS_IN_XML10 = 47;
// Object type properties:
final static int PROP_INPUT_BUFFER_LENGTH = 50;
//final static int PROP_TEXT_BUFFER_LENGTH = 51;
final static int PROP_MIN_TEXT_SEGMENT = 52;
final static int PROP_CUSTOM_INTERNAL_ENTITIES = 53;
final static int PROP_DTD_RESOLVER = 54;
final static int PROP_ENTITY_RESOLVER = 55;
final static int PROP_UNDECLARED_ENTITY_RESOLVER = 56;
final static int PROP_BASE_URL = 57;
final static int PROP_INPUT_PARSING_MODE = 58;
// Size limitation to prevent various DOS attacks
final static int PROP_MAX_ATTRIBUTES_PER_ELEMENT = 60;
final static int PROP_MAX_CHILDREN_PER_ELEMENT = 61;
final static int PROP_MAX_ELEMENT_COUNT = 62;
final static int PROP_MAX_ELEMENT_DEPTH = 63;
final static int PROP_MAX_CHARACTERS = 64;
final static int PROP_MAX_ATTRIBUTE_SIZE = 65;
final static int PROP_MAX_TEXT_LENGTH = 66;
final static int PROP_MAX_ENTITY_COUNT = 67;
final static int PROP_MAX_ENTITY_DEPTH = 68;
/*
////////////////////////////////////////////////
// Limits for numeric properties
////////////////////////////////////////////////
*/
/**
* Need to set a minimum size, since there are some limitations to
* smallest consequtive block that can be used.
*/
final static int MIN_INPUT_BUFFER_LENGTH = 8; // 16 bytes
/**
* Let's allow caching of just a dozen DTDs... shouldn't really
* matter, how many DTDs does one really use?
*/
final static int DTD_CACHE_SIZE_J2SE = 12;
final static int DTD_CACHE_SIZE_J2ME = 5;
/*
///////////////////////////////////////////////////////////////////////
// Default values for custom properties:
///////////////////////////////////////////////////////////////////////
*/
/**
* By default, let's require minimum of 64 chars to be delivered
* as shortest partial (piece of) text (CDATA, text) segment;
* same for both J2ME subset and full readers. Prevents tiniest
* runts from getting passed
*/
final static int DEFAULT_SHORTEST_TEXT_SEGMENT = 64;
/**
* Default config flags are converted from individual settings,
* to conform to StAX 1.0 specifications.
*/
final static int DEFAULT_FLAGS_FULL =
0
// First, default settings StAX specs dictate:
| CFG_NAMESPACE_AWARE
// Coalescing to be disabled
//| CFG_COALESCE_TEXT
| CFG_REPLACE_ENTITY_REFS
| CFG_SUPPORT_EXTERNAL_ENTITIES
| CFG_SUPPORT_DTD
// and then custom setting defaults:
// and namespace URI interning
| CFG_INTERN_NAMES
| CFG_INTERN_NS_URIS
// we will also accurately report CDATA, by default
| CFG_REPORT_CDATA
/* 20-Jan-2006, TSa: As per discussions on stax-builders list
* (and input from xml experts), 4.0 will revert to "do not
* report SPACE events outside root element by default"
* settings. Conceptually this is what xml specification
* implies should be done: there is no content outside of
* the element tree, including any ignorable content, just
* processing instructions and comments.
*/
//| CFG_REPORT_PROLOG_WS
/* but enable DTD caching (if they are handled):
* (... maybe J2ME subset shouldn't do it?)
*/
| CFG_CACHE_DTDS
/* 29-Mar-2006, TSa: But note, no caching by public-id, due
* to problems with cases where public-id/system-id were
* inconsistently used, leading to problems.
*/
/* by default, let's also allow lazy parsing, since it tends
* to improve performance
*/
| CFG_LAZY_PARSING
/* and also make Event objects preserve location info...
* can be turned off for maximum performance
*/
| CFG_PRESERVE_LOCATION
// As per Stax 1.0 specs, we can not enable this by default:
//| CFG_AUTO_CLOSE_INPUT);
/* Also, let's enable dtd++ support (shouldn't hurt with non-dtd++
* dtds)
*/
| CFG_SUPPORT_DTDPP
/*
* Set this as a default, as this is required in xml;
*/
| CFG_NORMALIZE_LFS
/* Regarding Xml:id, let's enabled typing by default, but not
* uniqueness validity checks: latter will be taken care of
* by DTD validation if enabled, otherwise needs to be explicitly
* enabled
*/
| CFG_XMLID_TYPING
// | CFG_XMLID_UNIQ_CHECKS
;
/**
* For now defaults for J2ME flags can be identical to 'full' set;
* differences are in buffer sizes.
*/
final static int DEFAULT_FLAGS_J2ME = DEFAULT_FLAGS_FULL;
// // //
/**
* Map to use for converting from String property ids to ints
* described above; useful to allow use of switch later on.
*/
final static HashMap<String,Integer> sProperties = new HashMap<String,Integer>(64); // we have about 40 entries
static {
// Standard ones; support for features
sProperties.put(XMLInputFactory.IS_COALESCING, PROP_COALESCE_TEXT);
sProperties.put(XMLInputFactory.IS_NAMESPACE_AWARE,
PROP_NAMESPACE_AWARE);
sProperties.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
PROP_REPLACE_ENTITY_REFS);
sProperties.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
PROP_SUPPORT_EXTERNAL_ENTITIES);
sProperties.put(XMLInputFactory.IS_VALIDATING,
PROP_VALIDATE_AGAINST_DTD);
sProperties.put(XMLInputFactory.SUPPORT_DTD,
PROP_SUPPORT_DTD);
// Standard ones; pluggable components
sProperties.put(XMLInputFactory.ALLOCATOR,
PROP_EVENT_ALLOCATOR);
sProperties.put(XMLInputFactory.REPORTER,
PROP_WARNING_REPORTER);
sProperties.put(XMLInputFactory.RESOLVER,
PROP_XML_RESOLVER);
// StAX2-introduced flags:
sProperties.put(XMLInputFactory2.P_INTERN_NAMES,
PROP_INTERN_NAMES);
sProperties.put(XMLInputFactory2.P_INTERN_NS_URIS,
PROP_INTERN_NS_URIS);
sProperties.put(XMLInputFactory2.P_REPORT_CDATA,
PROP_REPORT_CDATA);
sProperties.put(XMLInputFactory2.P_REPORT_PROLOG_WHITESPACE,
PROP_REPORT_PROLOG_WS);
sProperties.put(XMLInputFactory2.P_PRESERVE_LOCATION,
PROP_PRESERVE_LOCATION);
sProperties.put(XMLInputFactory2.P_AUTO_CLOSE_INPUT,
PROP_AUTO_CLOSE_INPUT);
sProperties.put(XMLInputFactory2.XSP_SUPPORT_XMLID,
PROP_SUPPORT_XMLID);
sProperties.put(XMLInputFactory2.P_DTD_OVERRIDE,
PROP_DTD_OVERRIDE);
// JAXP-features/properties:
sProperties.put(XMLConstants.FEATURE_SECURE_PROCESSING,
PROP_JAXP_SECURE_PROCESSING);
// Non-standard ones, flags:
sProperties.put(WstxInputProperties.P_CACHE_DTDS, PROP_CACHE_DTDS);
sProperties.put(WstxInputProperties.P_CACHE_DTDS_BY_PUBLIC_ID,
PROP_CACHE_DTDS_BY_PUBLIC_ID);
sProperties.put(XMLInputFactory2.P_LAZY_PARSING, PROP_LAZY_PARSING);
/*
sProperties.put(WstxInputProperties.P_SUPPORT_DTDPP,
PROP_SUPPORT_DTDPP));
*/
sProperties.put(WstxInputProperties.P_TREAT_CHAR_REFS_AS_ENTS,
PROP_TREAT_CHAR_REFS_AS_ENTS);
sProperties.put(WstxInputProperties.P_ALLOW_XML11_ESCAPED_CHARS_IN_XML10,
PROP_ALLOW_XML11_ESCAPED_CHARS_IN_XML10);
sProperties.put(WstxInputProperties.P_NORMALIZE_LFS, PROP_NORMALIZE_LFS);
// Non-standard ones, non-flags:
sProperties.put(WstxInputProperties.P_INPUT_BUFFER_LENGTH,
PROP_INPUT_BUFFER_LENGTH);
sProperties.put(WstxInputProperties.P_MIN_TEXT_SEGMENT,
PROP_MIN_TEXT_SEGMENT);
sProperties.put(WstxInputProperties.P_MAX_ATTRIBUTES_PER_ELEMENT,
PROP_MAX_ATTRIBUTES_PER_ELEMENT);
sProperties.put(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE,
PROP_MAX_ATTRIBUTE_SIZE);
sProperties.put(WstxInputProperties.P_MAX_CHILDREN_PER_ELEMENT,
PROP_MAX_CHILDREN_PER_ELEMENT);
sProperties.put(WstxInputProperties.P_MAX_TEXT_LENGTH,
PROP_MAX_TEXT_LENGTH);
sProperties.put(WstxInputProperties.P_MAX_ELEMENT_COUNT,
PROP_MAX_ELEMENT_COUNT);
sProperties.put(WstxInputProperties.P_MAX_ELEMENT_DEPTH,
PROP_MAX_ELEMENT_DEPTH);
sProperties.put(WstxInputProperties.P_MAX_ENTITY_DEPTH,
PROP_MAX_ENTITY_DEPTH);
sProperties.put(WstxInputProperties.P_MAX_ENTITY_COUNT,
PROP_MAX_ENTITY_COUNT);
sProperties.put(WstxInputProperties.P_MAX_CHARACTERS, PROP_MAX_CHARACTERS);
sProperties.put(WstxInputProperties.P_CUSTOM_INTERNAL_ENTITIES,
Integer.valueOf(PROP_CUSTOM_INTERNAL_ENTITIES));
sProperties.put(WstxInputProperties.P_DTD_RESOLVER,
PROP_DTD_RESOLVER);
sProperties.put(WstxInputProperties.P_ENTITY_RESOLVER,
PROP_ENTITY_RESOLVER);
sProperties.put(WstxInputProperties.P_UNDECLARED_ENTITY_RESOLVER,
PROP_UNDECLARED_ENTITY_RESOLVER);
sProperties.put(WstxInputProperties.P_BASE_URL,
PROP_BASE_URL);
sProperties.put(WstxInputProperties.P_INPUT_PARSING_MODE,
PROP_INPUT_PARSING_MODE);
}
/*
///////////////////////////////////////////////////////////////////////
// Current config state:
///////////////////////////////////////////////////////////////////////
*/
final protected boolean mIsJ2MESubset;
final protected SymbolTable mSymbols;
/**
* Bitset that contains state of on/off properties; initialized
* to defaults, but can be set/cleared.
*/
protected int mConfigFlags;
/**
* Bitset that indicates explicit changes to {@link #mConfigFlags}
* through calls; empty bit means that the corresponding property
* has its default value, set bit that an explicit call has been
* made.
*/
protected int mConfigFlagMods;
/**
* 13-Nov-2008, tatus: Need to be able to keep track of whether
* name-interning has been explicitly enabled/disable or not
* (not if it's whatever defaults we have)
*/
final static int PROP_INTERN_NAMES_EXPLICIT = 26;
final static int PROP_INTERN_NS_URIS_EXPLICIT = 27;
protected int mInputBufferLen;
protected int mMinTextSegmentLen;
protected int mMaxAttributesPerElement = DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT;
protected int mMaxAttributeSize = DEFAULT_MAX_ATTRIBUTE_LENGTH;
protected int mMaxChildrenPerElement = Integer.MAX_VALUE;
protected int mMaxElementDepth = DEFAULT_MAX_ELEMENT_DEPTH;
protected long mMaxElementCount = Long.MAX_VALUE; // unlimited
protected long mMaxCharacters = Long.MAX_VALUE; // unlimited
protected int mMaxTextLength = Integer.MAX_VALUE; // unlimited
protected int mMaxEntityDepth = DEFAULT_MAX_ENTITY_DEPTH;
protected long mMaxEntityCount = DEFAULT_MAX_ENTITY_COUNT;
/**
* Base URL to use as the resolution context for relative entity
* references
*/
protected URL mBaseURL;
/**
* Parsing mode can be changed from the default xml compliant
* behavior to one of alternate modes (fragment processing,
* multiple document processing).
*/
protected WstxInputProperties.ParsingMode mParsingMode =
WstxInputProperties.PARSING_MODE_DOCUMENT;
/**
* This boolean flag is set if the input document requires
* xml 1.1 (or above) compliant processing: default is xml 1.0
* compliant. Note that unlike most other properties, this
* does not come from configuration settings, but from processed
* document itself.
*/
protected boolean mXml11 = false;
/*
///////////////////////////////////////////////////////////////////////
// Common configuration objects
///////////////////////////////////////////////////////////////////////
*/
XMLReporter mReporter;
XMLResolver mDtdResolver = null;
XMLResolver mEntityResolver = null;
/*
///////////////////////////////////////////////////////////////////////
// More special(ized) configuration objects
///////////////////////////////////////////////////////////////////////
*/
//Map mCustomEntities;
//XMLResolver mUndeclaredEntityResolver;
//DTDEventListener mDTDEventListener;
Object[] mSpecialProperties = null;
private final static int SPEC_PROC_COUNT = 4;
private final static int SP_IX_CUSTOM_ENTITIES = 0;
private final static int SP_IX_UNDECL_ENT_RESOLVER = 1;
private final static int SP_IX_DTD_EVENT_LISTENER = 2;
private final static int SP_IX_DTD_OVERRIDE = 3;
/*
///////////////////////////////////////////////////////////////////////
// Buffer recycling:
///////////////////////////////////////////////////////////////////////
*/
/**
* This <code>ThreadLocal</code> contains a {@link SoftRerefence}
* to a {@link BufferRecycler} used to provide a low-cost
* buffer recycling between Reader instances.
*/
final static ThreadLocal<SoftReference<BufferRecycler>> mRecyclerRef = new ThreadLocal<SoftReference<BufferRecycler>>();
/**
* This is the actually container of the recyclable buffers. It
* is obtained via ThreadLocal/SoftReference combination, if one
* exists, when Config instance is created. If one does not
* exist, it will created first time a buffer is returned.
*/
BufferRecycler mCurrRecycler = null;
/*
///////////////////////////////////////////////////////////////////////
// Life-cycle
///////////////////////////////////////////////////////////////////////
*/
private ReaderConfig(ReaderConfig base,
boolean j2meSubset, SymbolTable symbols,
int configFlags, int configFlagMods,
int inputBufLen,
int minTextSegmentLen)
{
super(base);
mIsJ2MESubset = j2meSubset;
mSymbols = symbols;
mConfigFlags = configFlags;
mConfigFlagMods = configFlagMods;
mInputBufferLen = inputBufLen;
mMinTextSegmentLen = minTextSegmentLen;
if (base != null) {
mMaxAttributesPerElement = base.mMaxAttributesPerElement;
mMaxAttributeSize = base.mMaxAttributeSize;
mMaxChildrenPerElement = base.mMaxChildrenPerElement;
mMaxElementCount = base.mMaxElementCount;
mMaxElementDepth = base.mMaxElementDepth;
mMaxCharacters = base.mMaxCharacters;
mMaxTextLength = base.mMaxTextLength;
mMaxEntityDepth = base.mMaxEntityDepth;
mMaxEntityCount = base.mMaxEntityCount;
}
/* Ok, let's then see if we can find a buffer recycler. Since they
* are lazily constructed, and since GC may just flush them out
* on its whims, it's possible we might not find one. That's ok;
* we can reconstruct one if and when we are to return one or more
* buffers.
*/
SoftReference<BufferRecycler> ref = mRecyclerRef.get();
if (ref != null) {
mCurrRecycler = ref.get();
}
}
public static ReaderConfig createJ2MEDefaults()
{
/* For J2ME we'll use slightly smaller buffer sizes by
* default, on assumption lower memory usage is desireable:
*/
ReaderConfig rc = new ReaderConfig(null,
true, null, DEFAULT_FLAGS_J2ME, 0,
// 4k input buffer (2000 chars):
2000,
DEFAULT_SHORTEST_TEXT_SEGMENT);
return rc;
}
public static ReaderConfig createFullDefaults()
{
/* For full version, can use bit larger buffers to achieve better
* overall performance.
*/
ReaderConfig rc = new ReaderConfig(null,
false, null, DEFAULT_FLAGS_FULL, 0,
// 8k input buffer (4000 chars):
4000,
DEFAULT_SHORTEST_TEXT_SEGMENT);
return rc;
}
public ReaderConfig createNonShared(SymbolTable sym)
{
// should we throw an exception?
//if (sym == null) { }
ReaderConfig rc = new ReaderConfig(this,
mIsJ2MESubset, sym,
mConfigFlags, mConfigFlagMods,
mInputBufferLen,
mMinTextSegmentLen);
rc.mReporter = mReporter;
rc.mDtdResolver = mDtdResolver;
rc.mEntityResolver = mEntityResolver;
rc.mBaseURL = mBaseURL;
rc.mParsingMode = mParsingMode;
rc.mMaxAttributesPerElement = mMaxAttributesPerElement;
rc.mMaxAttributeSize = mMaxAttributeSize;
rc.mMaxChildrenPerElement = mMaxChildrenPerElement;
rc.mMaxElementCount = mMaxElementCount;
rc.mMaxCharacters = mMaxCharacters;
rc.mMaxTextLength = mMaxTextLength;
rc.mMaxElementDepth = mMaxElementDepth;
rc.mMaxEntityDepth = mMaxEntityDepth;
rc.mMaxEntityCount = mMaxEntityCount;
if (mSpecialProperties != null) {
int len = mSpecialProperties.length;
Object[] specProps = new Object[len];
System.arraycopy(mSpecialProperties, 0, specProps, 0, len);
rc.mSpecialProperties = specProps;
}
return rc;
}
/**
* Unlike name suggests there is also some limited state information
* associated with the config object. If these objects are reused,
* that state needs to be reset between reuses, to avoid carrying
* over incorrect state.
*/
public void resetState()
{
// Current, only xml 1.0 vs 1.1 state is stored here:
mXml11 = false;
}
/*
///////////////////////////////////////////////////////////////////////
// Implementation of abstract methods
///////////////////////////////////////////////////////////////////////
*/
@Override
protected int findPropertyId(String propName)
{
Integer I = sProperties.get(propName);
return (I == null) ? -1 : I.intValue();
}
/*
///////////////////////////////////////////////////////////////////////
// Public API, accessors
///////////////////////////////////////////////////////////////////////
*/
// // // Accessors for immutable configuration:
public SymbolTable getSymbols() { return mSymbols; }
/**
* In future this property could/should be made configurable?
*/
public int getDtdCacheSize() {
return mIsJ2MESubset ? DTD_CACHE_SIZE_J2ME : DTD_CACHE_SIZE_J2SE;
}
// // // "Raw" accessors for on/off properties:
public int getConfigFlags() { return mConfigFlags; }
// // // Standard StAX on/off property accessors
public boolean willCoalesceText() {
return _hasConfigFlag(CFG_COALESCE_TEXT);
}
public boolean willSupportNamespaces() {
return _hasConfigFlag(CFG_NAMESPACE_AWARE);
}
public boolean willReplaceEntityRefs() {
return _hasConfigFlag(CFG_REPLACE_ENTITY_REFS);
}
public boolean willSupportExternalEntities() {
return _hasConfigFlag(CFG_SUPPORT_EXTERNAL_ENTITIES);
}
public boolean willSupportDTDs() {
return _hasConfigFlag(CFG_SUPPORT_DTD);
}
public boolean willValidateWithDTD() {
return _hasConfigFlag(CFG_VALIDATE_AGAINST_DTD);
}
// // // Stax2 on/off property accessors
public boolean willReportCData() {
return _hasConfigFlag(CFG_REPORT_CDATA);
}
public boolean willParseLazily() {
return _hasConfigFlag(CFG_LAZY_PARSING);
}
public boolean willInternNames() {
return _hasConfigFlag(CFG_INTERN_NAMES);
}
public boolean willInternNsURIs() {
return _hasConfigFlag(CFG_INTERN_NS_URIS);
}
public boolean willPreserveLocation() {
return _hasConfigFlag(CFG_PRESERVE_LOCATION);
}
public boolean willAutoCloseInput() {
return _hasConfigFlag(CFG_AUTO_CLOSE_INPUT);
}
// // // JAXP on/off
public boolean willProcessSecurely() {
return _hasConfigFlag(CFG_JAXP_FEATURE_SECURE_PROCESSING);
}
// // // Woodstox on/off property accessors
public boolean willReportPrologWhitespace() {
return _hasConfigFlag(CFG_REPORT_PROLOG_WS);
}
public boolean willCacheDTDs() {
return _hasConfigFlag(CFG_CACHE_DTDS);
}
public boolean willCacheDTDsByPublicId() {
return _hasConfigFlag(CFG_CACHE_DTDS_BY_PUBLIC_ID);
}
public boolean willDoXmlIdTyping() {
return _hasConfigFlag(CFG_XMLID_TYPING);
}
public boolean willDoXmlIdUniqChecks() {
return _hasConfigFlag(CFG_XMLID_UNIQ_CHECKS);
}
public boolean willSupportDTDPP() {
return _hasConfigFlag(CFG_SUPPORT_DTDPP);
}
public boolean willNormalizeLFs() {
return _hasConfigFlag(CFG_NORMALIZE_LFS);
}
public boolean willTreatCharRefsAsEnts() {
return _hasConfigFlag(CFG_TREAT_CHAR_REFS_AS_ENTS);
}
public boolean willAllowXml11EscapedCharsInXml10() {
return _hasConfigFlag(CFG_ALLOW_XML11_ESCAPED_CHARS_IN_XML10);
}
public int getInputBufferLength() { return mInputBufferLen; }
public int getShortestReportedTextSegment() { return mMinTextSegmentLen; }
public int getMaxAttributesPerElement() { return mMaxAttributesPerElement; }
public int getMaxAttributeSize() { return mMaxAttributeSize; }
public int getMaxChildrenPerElement() { return mMaxChildrenPerElement; }
public int getMaxElementDepth() { return mMaxElementDepth; }
public long getMaxElementCount() { return mMaxElementCount; }
public int getMaxEntityDepth() { return mMaxEntityDepth; }
public long getMaxEntityCount() { return mMaxEntityCount; }
public long getMaxCharacters() { return mMaxCharacters; }
public long getMaxTextLength() { return mMaxTextLength; }
public Map<String,EntityDecl> getCustomInternalEntities()
{
@SuppressWarnings("unchecked")
Map<String,EntityDecl> custEnt = (Map<String,EntityDecl>) _getSpecialProperty(SP_IX_CUSTOM_ENTITIES);
if (custEnt == null) {
return Collections.emptyMap();
}
// Better be defensive and just return a copy...
int len = custEnt.size();
HashMap<String,EntityDecl> m = new HashMap<String,EntityDecl>(len + (len >> 2), 0.81f);
for (Map.Entry<String,EntityDecl> me : custEnt.entrySet()) {
m.put(me.getKey(), me.getValue());
}
return m;
}
public EntityDecl findCustomInternalEntity(String id)
{
@SuppressWarnings("unchecked")
Map<String,EntityDecl> custEnt = (Map<String,EntityDecl>) _getSpecialProperty(SP_IX_CUSTOM_ENTITIES);
if (custEnt == null) {
return null;
}
return custEnt.get(id);
}
public XMLReporter getXMLReporter() { return mReporter; }
public XMLResolver getXMLResolver() { return mEntityResolver; }
public XMLResolver getDtdResolver() { return mDtdResolver; }
public XMLResolver getEntityResolver() { return mEntityResolver; }
public XMLResolver getUndeclaredEntityResolver() {
return (XMLResolver) _getSpecialProperty(SP_IX_UNDECL_ENT_RESOLVER);
}
public URL getBaseURL() { return mBaseURL; }
public WstxInputProperties.ParsingMode getInputParsingMode() {
return mParsingMode;
}
public boolean inputParsingModeDocuments() {
return mParsingMode == WstxInputProperties.PARSING_MODE_DOCUMENTS;
}
public boolean inputParsingModeFragment() {
return mParsingMode == WstxInputProperties.PARSING_MODE_FRAGMENT;
}
/**
* @return True if the input well-formedness and validation checks
* should be done according to xml 1.1 specification; false if
* xml 1.0 specification.
*/
public boolean isXml11() {
return mXml11;
}
public DTDEventListener getDTDEventListener() {
return (DTDEventListener) _getSpecialProperty(SP_IX_DTD_EVENT_LISTENER);
}
public DTDValidationSchema getDTDOverride() {
return (DTDValidationSchema) _getSpecialProperty(SP_IX_DTD_OVERRIDE);
}
/**
* Special accessor to use to verify whether name interning has
* explicitly been enabled; true if call was been made to set
* it to true; false otherwise (default, or set to false)
*/
public boolean hasInternNamesBeenEnabled() {
return _hasExplicitConfigFlag(CFG_INTERN_NAMES);
}
public boolean hasInternNsURIsBeenEnabled() {
return _hasExplicitConfigFlag(CFG_INTERN_NS_URIS);
}
/**
* Checks if the user explicitly set coalescing to false. (That is if
* coalescing is disabled only because that is the default value, this method
* will return false.)
*
* @return true, if the user explicitly disabled coalescing, else false
*/
public boolean isCoalescingExplicitlyDisabled() {
// coalescing is disabled and was explicitly set by user
return !_hasConfigFlag(CFG_COALESCE_TEXT) && (mConfigFlagMods & CFG_COALESCE_TEXT) != 0;
}
/*
///////////////////////////////////////////////////////////////////////
// Simple mutators
///////////////////////////////////////////////////////////////////////
*/
public void setConfigFlag(int flag) {
mConfigFlags |= flag;
mConfigFlagMods |= flag;
}
public void clearConfigFlag(int flag) {
mConfigFlags &= ~flag;
mConfigFlagMods |= flag;
}
// // // Mutators for standard StAX properties
public void doCoalesceText(boolean state) {
setConfigFlag(CFG_COALESCE_TEXT, state);
}
public void doSupportNamespaces(boolean state) {
setConfigFlag(CFG_NAMESPACE_AWARE, state);
}
public void doReplaceEntityRefs(boolean state) {
setConfigFlag(CFG_REPLACE_ENTITY_REFS, state);
}
public void doSupportExternalEntities(boolean state) {
setConfigFlag(CFG_SUPPORT_EXTERNAL_ENTITIES, state);
}
public void doSupportDTDs(boolean state) {
setConfigFlag(CFG_SUPPORT_DTD, state);
}
public void doValidateWithDTD(boolean state) {
setConfigFlag(CFG_VALIDATE_AGAINST_DTD, state);
}
// // // Mutators for JAXB features/properties
/**
* Method called when {code XMLConstants.FEATURE_SECURE_PROCESSING} is being
* enabled or disabled.
*<p>
* Note that disabling (passing {code false} as argument) does not actually
* change any settings.
*<p>
* Calls made when {@code true} is passed (that is, secure processing enabled):
*<ul>
* <li>{@code doSupportExternalEntities(false)}
* </li>
*</ul>
*
* @since 5.3
*/
public void doProcessSecurely(boolean value) {
// if disabling, nothing special to do; only matters if it's being enabled
setConfigFlag(CFG_JAXP_FEATURE_SECURE_PROCESSING, value);
if (value) {
doSupportExternalEntities(false);
}
}
// // // Mutators for Woodstox-specific properties
public void doInternNames(boolean state) {
setConfigFlag(CFG_INTERN_NAMES, state);
}
public void doInternNsURIs(boolean state) {
setConfigFlag(CFG_INTERN_NS_URIS, state);
}
public void doReportPrologWhitespace(boolean state) {
setConfigFlag(CFG_REPORT_PROLOG_WS, state);
}
public void doReportCData(boolean state) {
setConfigFlag(CFG_REPORT_CDATA, state);
}
public void doCacheDTDs(boolean state) {
setConfigFlag(CFG_CACHE_DTDS, state);
}
public void doCacheDTDsByPublicId(boolean state) {
setConfigFlag(CFG_CACHE_DTDS_BY_PUBLIC_ID, state);
}
public void doParseLazily(boolean state) {
setConfigFlag(CFG_LAZY_PARSING, state);
}
public void doXmlIdTyping(boolean state) {
setConfigFlag(CFG_XMLID_TYPING, state);
}
public void doXmlIdUniqChecks(boolean state) {
setConfigFlag(CFG_XMLID_UNIQ_CHECKS, state);
}
public void doPreserveLocation(boolean state) {
setConfigFlag(CFG_PRESERVE_LOCATION, state);
}
public void doAutoCloseInput(boolean state) {
setConfigFlag(CFG_AUTO_CLOSE_INPUT, state);
}
public void doSupportDTDPP(boolean state) {
setConfigFlag(CFG_SUPPORT_DTDPP, state);
}
public void doTreatCharRefsAsEnts(final boolean state) {
setConfigFlag(CFG_TREAT_CHAR_REFS_AS_ENTS, state);
}
public void doAllowXml11EscapedCharsInXml10(final boolean state) {
setConfigFlag(CFG_ALLOW_XML11_ESCAPED_CHARS_IN_XML10, state);
}
public void doNormalizeLFs(final boolean state) {
setConfigFlag(CFG_NORMALIZE_LFS, state);
}
public void setInputBufferLength(int value)
{
/* Let's enforce minimum here; necessary to allow longest
* consequtive text span to be available (xml decl, etc)
*/
if (value < MIN_INPUT_BUFFER_LENGTH) {
value = MIN_INPUT_BUFFER_LENGTH;
}
mInputBufferLen = value;
}
public void setShortestReportedTextSegment(int value) {
mMinTextSegmentLen = value;
}
public void setMaxAttributesPerElement(int value) {
mMaxAttributesPerElement = value;
}
public void setMaxAttributeSize(int value) {
mMaxAttributeSize = value;
}
public void setMaxChildrenPerElement(int value) {
mMaxChildrenPerElement = value;
}
public void setMaxElementDepth(int value) {
mMaxElementDepth = value;
}
public void setMaxElementCount(long value) {
mMaxElementCount = value;
}
public void setMaxCharacters(long value) {
mMaxCharacters = value;
}
public void setMaxTextLength(int value) {
mMaxTextLength = value;
}
public void setMaxEntityDepth(int value) {
mMaxEntityDepth = value;
}
public void setMaxEntityCount(long value) {