Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jaxp/src/com/sun/xml/internal/stream/Entity.java
83408 views
1
/*
2
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3
*/
4
5
/*
6
* Copyright 2005 The Apache Software Foundation.
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*/
20
21
package com.sun.xml.internal.stream;
22
23
import java.io.InputStream;
24
import java.io.Reader;
25
import java.io.IOException;
26
27
import com.sun.xml.internal.stream.util.BufferAllocator;
28
import com.sun.xml.internal.stream.util.ThreadLocalBufferAllocator;
29
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
30
31
/**
32
* Entity information.
33
*
34
* @author
35
*/
36
public abstract class Entity {
37
38
//
39
// Data
40
//
41
42
//xxx why dont we declare the type of entities, like assign integer for external/ internal etc..
43
44
/** Entity name. */
45
public String name;
46
47
// whether this entity's declaration was found in the internal
48
// or external subset
49
public boolean inExternalSubset;
50
51
//
52
// Constructors
53
//
54
55
/** Default constructor. */
56
public Entity() {
57
clear();
58
} // <init>()
59
60
/** Constructs an entity. */
61
public Entity(String name, boolean inExternalSubset) {
62
this.name = name;
63
this.inExternalSubset = inExternalSubset;
64
} // <init>(String)
65
66
//
67
// Public methods
68
//
69
70
/** Returns true if this entity was declared in the external subset. */
71
public boolean isEntityDeclInExternalSubset() {
72
return inExternalSubset;
73
}
74
75
/** Returns true if this is an external entity. */
76
public abstract boolean isExternal();
77
78
/** Returns true if this is an unparsed entity. */
79
public abstract boolean isUnparsed();
80
81
/** Clears the entity. */
82
public void clear() {
83
name = null;
84
inExternalSubset = false;
85
} // clear()
86
87
/** Sets the values of the entity. */
88
public void setValues(Entity entity) {
89
name = entity.name;
90
inExternalSubset = entity.inExternalSubset;
91
} // setValues(Entity)
92
93
94
/**
95
* Internal entity.
96
*
97
* @author nb131165
98
*/
99
public static class InternalEntity
100
extends Entity {
101
102
//
103
// Data
104
//
105
106
/** Text value of entity. */
107
public String text;
108
109
//
110
// Constructors
111
//
112
113
/** Default constructor. */
114
public InternalEntity() {
115
clear();
116
} // <init>()
117
118
/** Constructs an internal entity. */
119
public InternalEntity(String name, String text, boolean inExternalSubset) {
120
super(name,inExternalSubset);
121
this.text = text;
122
} // <init>(String,String)
123
124
//
125
// Entity methods
126
//
127
128
/** Returns true if this is an external entity. */
129
public final boolean isExternal() {
130
return false;
131
} // isExternal():boolean
132
133
/** Returns true if this is an unparsed entity. */
134
public final boolean isUnparsed() {
135
return false;
136
} // isUnparsed():boolean
137
138
/** Clears the entity. */
139
public void clear() {
140
super.clear();
141
text = null;
142
} // clear()
143
144
/** Sets the values of the entity. */
145
public void setValues(Entity entity) {
146
super.setValues(entity);
147
text = null;
148
} // setValues(Entity)
149
150
/** Sets the values of the entity. */
151
public void setValues(InternalEntity entity) {
152
super.setValues(entity);
153
text = entity.text;
154
} // setValues(InternalEntity)
155
156
} // class InternalEntity
157
158
/**
159
* External entity.
160
*
161
* @author nb131165
162
*/
163
public static class ExternalEntity
164
extends Entity {
165
166
//
167
// Data
168
//
169
170
/** container for all relevant entity location information. */
171
public XMLResourceIdentifier entityLocation;
172
173
/** Notation name for unparsed entity. */
174
public String notation;
175
176
//
177
// Constructors
178
//
179
180
/** Default constructor. */
181
public ExternalEntity() {
182
clear();
183
} // <init>()
184
185
/** Constructs an internal entity. */
186
public ExternalEntity(String name, XMLResourceIdentifier entityLocation,
187
String notation, boolean inExternalSubset) {
188
super(name,inExternalSubset);
189
this.entityLocation = entityLocation;
190
this.notation = notation;
191
} // <init>(String,XMLResourceIdentifier, String)
192
193
//
194
// Entity methods
195
//
196
197
/** Returns true if this is an external entity. */
198
public final boolean isExternal() {
199
return true;
200
} // isExternal():boolean
201
202
/** Returns true if this is an unparsed entity. */
203
public final boolean isUnparsed() {
204
return notation != null;
205
} // isUnparsed():boolean
206
207
/** Clears the entity. */
208
public void clear() {
209
super.clear();
210
entityLocation = null;
211
notation = null;
212
} // clear()
213
214
/** Sets the values of the entity. */
215
public void setValues(Entity entity) {
216
super.setValues(entity);
217
entityLocation = null;
218
notation = null;
219
} // setValues(Entity)
220
221
/** Sets the values of the entity. */
222
public void setValues(ExternalEntity entity) {
223
super.setValues(entity);
224
entityLocation = entity.entityLocation;
225
notation = entity.notation;
226
} // setValues(ExternalEntity)
227
228
} // class ExternalEntity
229
230
/**
231
* Entity state.
232
*
233
* @author nb131165
234
*/
235
public static class ScannedEntity
236
extends Entity {
237
238
239
/** Default buffer size (4096). */
240
public static final int DEFAULT_BUFFER_SIZE = 8192;
241
//4096;
242
243
/**
244
* Buffer size. We get this value from a property. The default size
245
* is used if the input buffer size property is not specified.
246
* REVISIT: do we need a property for internal entity buffer size?
247
*/
248
public int fBufferSize = DEFAULT_BUFFER_SIZE;
249
250
/** Default buffer size before we've finished with the XMLDecl: */
251
public static final int DEFAULT_XMLDECL_BUFFER_SIZE = 28;
252
253
/** Default internal entity buffer size (1024). */
254
public static final int DEFAULT_INTERNAL_BUFFER_SIZE = 1024;
255
256
//
257
// Data
258
//
259
260
// i/o
261
262
/** XXX let these field remain public right now, though we have defined methods for them.
263
* Input stream. */
264
public InputStream stream;
265
266
/** XXX let these field remain public right now, though we have defined methods for them.
267
* Reader. */
268
public Reader reader;
269
270
// locator information
271
272
/** entity location information */
273
public XMLResourceIdentifier entityLocation;
274
275
// encoding
276
277
/** Auto-detected encoding. */
278
public String encoding;
279
280
// status
281
282
/** True if in a literal. */
283
public boolean literal;
284
285
// whether this is an external or internal scanned entity
286
public boolean isExternal;
287
288
//each 'external' parsed entity may have xml/text declaration containing version information
289
public String version ;
290
291
// buffer
292
293
/** Character buffer. */
294
public char[] ch = null;
295
296
/** Position in character buffer at any point of time. */
297
public int position;
298
299
/** Count of characters present in buffer. */
300
public int count;
301
302
/** Line number. */
303
public int lineNumber = 1;
304
305
/** Column number. */
306
public int columnNumber = 1;
307
308
/** Encoding has been set externally for eg: using DOMInput*/
309
boolean declaredEncoding = false;
310
311
// status
312
313
/**
314
* Encoding has been set externally, for example
315
* using a SAX InputSource or a DOM LSInput.
316
*/
317
boolean externallySpecifiedEncoding = false;
318
319
/** XML version. **/
320
public String xmlVersion = "1.0";
321
322
/** This variable is used to calculate the current position in the XML stream.
323
* Note that fCurrentEntity.position maintains the position relative to
324
* the buffer.
325
* At any point of time absolute position in the XML stream can be calculated
326
* as fTotalCountTillLastLoad + fCurrentEntity.position
327
*/
328
public int fTotalCountTillLastLoad ;
329
330
/** This variable stores the number of characters read during the load()
331
* operation. It is used to calculate fTotalCountTillLastLoad
332
*/
333
public int fLastCount ;
334
335
/** Base character offset for computing absolute character offset. */
336
public int baseCharOffset;
337
338
/** Start position in character buffer. */
339
public int startPosition;
340
341
// to allow the reader/inputStream to behave efficiently:
342
public boolean mayReadChunks;
343
344
// to know that prolog is read
345
public boolean xmlDeclChunkRead = false;
346
347
// flag to indicate whether the Entity is a General Entity
348
public boolean isGE = false;
349
350
/** returns the name of the current encoding
351
* @return current encoding name
352
*/
353
public String getEncodingName(){
354
return encoding ;
355
}
356
357
/**each 'external' parsed entity may have xml/text declaration containing version information
358
* @return String version of the enity, for an internal entity version would be null
359
*/
360
public String getEntityVersion(){
361
return version ;
362
}
363
364
/** each 'external' parsed entity may have xml/text declaration containing version information
365
* @param String version of the external parsed entity
366
*/
367
public void setEntityVersion(String version){
368
this.version = version ;
369
}
370
371
/** Returns the java.io.Reader associated with this entity.Readers are used
372
* to read from the file. Readers wrap any particular InputStream that was
373
* used to open the entity.
374
* @return java.io.Reader Reader associated with this entity
375
*/
376
public Reader getEntityReader(){
377
return reader;
378
}
379
380
381
/** if entity was opened using the stream, return the associated inputstream
382
* with this entity
383
*@return java.io.InputStream InputStream associated with this entity
384
*/
385
public InputStream getEntityInputStream(){
386
return stream;
387
}
388
389
//
390
// Constructors
391
//
392
393
/** Constructs a scanned entity. */
394
public ScannedEntity(boolean isGE, String name,
395
XMLResourceIdentifier entityLocation,
396
InputStream stream, Reader reader,
397
String encoding, boolean literal, boolean mayReadChunks, boolean isExternal) {
398
this.isGE = isGE;
399
this.name = name ;
400
this.entityLocation = entityLocation;
401
this.stream = stream;
402
this.reader = reader;
403
this.encoding = encoding;
404
this.literal = literal;
405
this.mayReadChunks = mayReadChunks;
406
this.isExternal = isExternal;
407
final int size = isExternal ? fBufferSize : DEFAULT_INTERNAL_BUFFER_SIZE;
408
BufferAllocator ba = ThreadLocalBufferAllocator.getBufferAllocator();
409
ch = ba.getCharBuffer(size);
410
if (ch == null) {
411
this.ch = new char[size];
412
}
413
} // <init>(StringXMLResourceIdentifier,InputStream,Reader,String,boolean, boolean)
414
415
/**
416
* Release any resources associated with this entity.
417
*/
418
public void close() throws IOException {
419
BufferAllocator ba = ThreadLocalBufferAllocator.getBufferAllocator();
420
ba.returnCharBuffer(ch);
421
ch = null;
422
reader.close();
423
}
424
425
//
426
// Entity methods
427
//
428
429
/** Returns whether the encoding of this entity was externally specified. **/
430
public boolean isEncodingExternallySpecified() {
431
return externallySpecifiedEncoding;
432
}
433
434
/** Sets whether the encoding of this entity was externally specified. **/
435
public void setEncodingExternallySpecified(boolean value) {
436
externallySpecifiedEncoding = value;
437
}
438
439
public boolean isDeclaredEncoding() {
440
return declaredEncoding;
441
}
442
443
public void setDeclaredEncoding(boolean value) {
444
declaredEncoding = value;
445
}
446
447
/** Returns true if this is an external entity. */
448
public final boolean isExternal() {
449
return isExternal;
450
} // isExternal():boolean
451
452
/** Returns true if this is an unparsed entity. */
453
public final boolean isUnparsed() {
454
return false;
455
} // isUnparsed():boolean
456
457
//
458
// Object methods
459
//
460
461
/** Returns a string representation of this object. */
462
public String toString() {
463
464
StringBuffer str = new StringBuffer();
465
str.append("name=\""+name+'"');
466
str.append(",ch="+ new String(ch));
467
str.append(",position="+position);
468
str.append(",count="+count);
469
return str.toString();
470
471
} // toString():String
472
473
} // class ScannedEntity
474
475
} // class Entity
476
477