Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java
40948 views
1
/*
2
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.xml.stream;
27
28
import com.sun.xml.internal.stream.XMLInputFactoryImpl;
29
import javax.xml.stream.util.XMLEventAllocator;
30
import javax.xml.transform.Source;
31
32
/**
33
* Defines an abstract implementation of a factory for getting streams.
34
*
35
* The following table defines the standard properties of this specification.
36
* Each property varies in the level of support required by each implementation.
37
* The level of support required is described in the 'Required' column.
38
*
39
* <table class="striped">
40
* <caption>Configuration Parameters</caption>
41
* <thead>
42
* <tr>
43
* <th scope="col">Property Name</th>
44
* <th scope="col">Behavior</th>
45
* <th scope="col">Return type</th>
46
* <th scope="col">Default Value</th>
47
* <th scope="col">Required</th>
48
* </tr>
49
* </thead>
50
* <tbody>
51
* <tr><th scope="row">javax.xml.stream.isValidating</th><td>Turns on/off implementation specific DTD validation</td><td>Boolean</td><td>False</td><td>No</td></tr>
52
* <tr><th scope="row">javax.xml.stream.isNamespaceAware</th><td>Turns on/off namespace processing for XML 1.0 support</td><td>Boolean</td><td>True</td><td>True (required) / False (optional)</td></tr>
53
* <tr><th scope="row">javax.xml.stream.isCoalescing</th><td>Requires the processor to coalesce adjacent character data</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
54
* <tr><th scope="row">javax.xml.stream.isReplacingEntityReferences</th><td>replace internal entity references with their replacement text and report them as characters</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
55
*<tr><th scope="row">javax.xml.stream.isSupportingExternalEntities</th><td>Resolve external parsed entities</td><td>Boolean</td><td>Unspecified</td><td>Yes</td></tr>
56
*<tr><th scope="row">javax.xml.stream.supportDTD</th><td>Use this property to request processors that do not support DTDs</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
57
*<tr><th scope="row">javax.xml.stream.reporter</th><td>sets/gets the impl of the XMLReporter </td><td>javax.xml.stream.XMLReporter</td><td>Null</td><td>Yes</td></tr>
58
*<tr><th scope="row">javax.xml.stream.resolver</th><td>sets/gets the impl of the XMLResolver interface</td><td>javax.xml.stream.XMLResolver</td><td>Null</td><td>Yes</td></tr>
59
*<tr><th scope="row">javax.xml.stream.allocator</th><td>sets/gets the impl of the XMLEventAllocator interface</td><td>javax.xml.stream.util.XMLEventAllocator</td><td>Null</td><td>Yes</td></tr>
60
* </tbody>
61
* </table>
62
*
63
*
64
* @version 1.2
65
* @author Copyright (c) 2009, 2015 by Oracle Corporation. All Rights Reserved.
66
* @see XMLOutputFactory
67
* @see XMLEventReader
68
* @see XMLStreamReader
69
* @see EventFilter
70
* @see XMLReporter
71
* @see XMLResolver
72
* @see javax.xml.stream.util.XMLEventAllocator
73
* @since 1.6
74
*/
75
76
public abstract class XMLInputFactory {
77
/**
78
* The property used to turn on/off namespace support,
79
* this is to support XML 1.0 documents,
80
* only the true setting must be supported
81
*/
82
public static final String IS_NAMESPACE_AWARE=
83
"javax.xml.stream.isNamespaceAware";
84
85
/**
86
* The property used to turn on/off implementation specific validation
87
*/
88
public static final String IS_VALIDATING=
89
"javax.xml.stream.isValidating";
90
91
/**
92
* The property that requires the parser to coalesce adjacent character data sections
93
*/
94
public static final String IS_COALESCING=
95
"javax.xml.stream.isCoalescing";
96
97
/**
98
* Requires the parser to replace internal
99
* entity references with their replacement
100
* text and report them as characters
101
*/
102
public static final String IS_REPLACING_ENTITY_REFERENCES=
103
"javax.xml.stream.isReplacingEntityReferences";
104
105
/**
106
* The property that requires the parser to resolve external parsed entities
107
*/
108
public static final String IS_SUPPORTING_EXTERNAL_ENTITIES=
109
"javax.xml.stream.isSupportingExternalEntities";
110
111
/**
112
* The property that requires the parser to support DTDs
113
*/
114
public static final String SUPPORT_DTD=
115
"javax.xml.stream.supportDTD";
116
117
/**
118
* The property used to
119
* set/get the implementation of the XMLReporter interface
120
*/
121
public static final String REPORTER=
122
"javax.xml.stream.reporter";
123
124
/**
125
* The property used to set/get the implementation of the XMLResolver
126
*/
127
public static final String RESOLVER=
128
"javax.xml.stream.resolver";
129
130
/**
131
* The property used to set/get the implementation of the allocator
132
*/
133
public static final String ALLOCATOR=
134
"javax.xml.stream.allocator";
135
136
static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
137
138
/**
139
* Protected constructor to prevent instantiation.
140
* Use {@link #newFactory()} instead.
141
*/
142
protected XMLInputFactory(){}
143
144
/**
145
* Creates a new instance of the {@code XMLInputFactory} builtin
146
* system-default implementation.
147
*
148
* @return A new instance of the {@code XMLInputFactory} builtin
149
* system-default implementation.
150
*
151
* @since 9
152
*/
153
public static XMLInputFactory newDefaultFactory() {
154
return new XMLInputFactoryImpl();
155
}
156
157
/**
158
* Creates a new instance of the factory in exactly the same manner as the
159
* {@link #newFactory()} method.
160
* @return an instance of the {@code XMLInputFactory}
161
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
162
*/
163
public static XMLInputFactory newInstance()
164
throws FactoryConfigurationError
165
{
166
return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);
167
}
168
169
/**
170
* Creates a new instance of the factory. This method uses the
171
* <a href="../../../module-summary.html#LookupMechanism">JAXP Lookup Mechanism</a>
172
* to determine the {@code XMLInputFactory} implementation class to load.
173
* <p>
174
* Once an application has obtained a reference to a {@code XMLInputFactory}, it
175
* can use the factory to configure and obtain stream instances.
176
*
177
* @return an instance of the {@code XMLInputFactory}
178
* @throws FactoryConfigurationError in case of {@linkplain
179
* java.util.ServiceConfigurationError service configuration error} or if
180
* the implementation is not available or cannot be instantiated.
181
*/
182
public static XMLInputFactory newFactory()
183
throws FactoryConfigurationError
184
{
185
return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);
186
}
187
188
/**
189
* Create a new instance of the factory.
190
*
191
* @param factoryId Name of the factory to find, same as
192
* a property name
193
* @param classLoader classLoader to use
194
* @return the factory implementation
195
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
196
*
197
* @deprecated This method has been deprecated to maintain API consistency.
198
* All newInstance methods have been replaced with corresponding
199
* newFactory methods. The replacement {@link
200
* #newFactory(java.lang.String, java.lang.ClassLoader)} method
201
* defines no changes in behavior.
202
*/
203
@Deprecated(since="1.7")
204
public static XMLInputFactory newInstance(String factoryId,
205
ClassLoader classLoader)
206
throws FactoryConfigurationError {
207
//do not fallback if given classloader can't find the class, throw exception
208
return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
209
}
210
211
/**
212
* Create a new instance of the factory.
213
* If the classLoader argument is null, then the ContextClassLoader is used.
214
* <p>
215
* This method uses the following ordered lookup procedure to determine
216
* the XMLInputFactory implementation class to load:
217
* <ul>
218
* <li>
219
* <p>
220
* Use the value of the system property identified by {@code factoryId}.
221
* </li>
222
* <li>
223
* <p>
224
* Use the configuration file "stax.properties". The file is in standard
225
* {@link java.util.Properties} format and typically located in the
226
* {@code conf} directory of the Java installation. It contains the fully qualified
227
* name of the implementation class with the key being the system property
228
* defined above.
229
*
230
* <p>
231
* The stax.properties file is read only once by the implementation
232
* and its values are then cached for future use. If the file does not exist
233
* when the first attempt is made to read from it, no further attempts are
234
* made to check for its existence. It is not possible to change the value
235
* of any property in stax.properties after it has been read for the first time.
236
*
237
* <p>
238
* Use the jaxp configuration file "jaxp.properties". The file is in the same
239
* format as stax.properties and will only be read if stax.properties does
240
* not exist.
241
* </li>
242
* <li>
243
* <p>
244
* If {@code factoryId} is "javax.xml.stream.XMLInputFactory",
245
* use the service-provider loading facility, defined by the
246
* {@link java.util.ServiceLoader} class, to attempt to {@linkplain
247
* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}
248
* an implementation of the service using the specified {@code ClassLoader}.
249
* If {@code classLoader} is null, the {@linkplain
250
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
251
* That is, the service-provider loading facility will use the {@linkplain
252
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
253
* to attempt to load the service. If the context class
254
* loader is null, the {@linkplain
255
* ClassLoader#getSystemClassLoader() system class loader} will be used.
256
* </li>
257
* <li>
258
* <p>
259
* Otherwise, throws a {@link FactoryConfigurationError}.
260
* </li>
261
* </ul>
262
*
263
* <p>
264
* Note that this is a new method that replaces the deprecated
265
* {@link #newInstance(java.lang.String, java.lang.ClassLoader)
266
* newInstance(String factoryId, ClassLoader classLoader)} method.
267
* No changes in behavior are defined by this replacement method relative
268
* to the deprecated method.
269
*
270
*
271
* @apiNote The parameter factoryId defined here is inconsistent with that
272
* of other JAXP factories where the first parameter is fully qualified
273
* factory class name that provides implementation of the factory.
274
*
275
* @param factoryId Name of the factory to find, same as
276
* a property name
277
* @param classLoader classLoader to use
278
* @return the factory implementation
279
* @throws FactoryConfigurationError in case of {@linkplain
280
* java.util.ServiceConfigurationError service configuration error} or if
281
* the implementation is not available or cannot be instantiated.
282
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
283
*/
284
public static XMLInputFactory newFactory(String factoryId,
285
ClassLoader classLoader)
286
throws FactoryConfigurationError {
287
//do not fallback if given classloader can't find the class, throw exception
288
return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
289
}
290
291
/**
292
* Create a new XMLStreamReader from a reader.
293
* @param reader the XML data to read from
294
* @return an instance of the {@code XMLStreamReader}
295
* @throws XMLStreamException if an error occurs
296
*/
297
public abstract XMLStreamReader createXMLStreamReader(java.io.Reader reader)
298
throws XMLStreamException;
299
300
/**
301
* Create a new XMLStreamReader from a JAXP source. This method is optional.
302
* @param source the source to read from
303
* @return an instance of the {@code XMLStreamReader}
304
* @throws UnsupportedOperationException if this method is not
305
* supported by this XMLInputFactory
306
* @throws XMLStreamException if an error occurs
307
*/
308
public abstract XMLStreamReader createXMLStreamReader(Source source)
309
throws XMLStreamException;
310
311
/**
312
* Create a new XMLStreamReader from a java.io.InputStream.
313
* @param stream the InputStream to read from
314
* @return an instance of the {@code XMLStreamReader}
315
* @throws XMLStreamException if an error occurs
316
*/
317
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream)
318
throws XMLStreamException;
319
320
/**
321
* Create a new XMLStreamReader from a java.io.InputStream.
322
* @param stream the InputStream to read from
323
* @param encoding the character encoding of the stream
324
* @return an instance of the {@code XMLStreamReader}
325
* @throws XMLStreamException if an error occurs
326
*/
327
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream, String encoding)
328
throws XMLStreamException;
329
330
/**
331
* Create a new XMLStreamReader from a java.io.InputStream.
332
* @param systemId the system ID of the stream
333
* @param stream the InputStream to read from
334
* @return an instance of the {@code XMLStreamReader}
335
* @throws XMLStreamException if an error occurs
336
*/
337
public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.InputStream stream)
338
throws XMLStreamException;
339
340
/**
341
* Create a new XMLStreamReader from a java.io.InputStream.
342
* @param systemId the system ID of the stream
343
* @param reader the InputStream to read from
344
* @return an instance of the {@code XMLStreamReader}
345
* @throws XMLStreamException if an error occurs
346
*/
347
public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.Reader reader)
348
throws XMLStreamException;
349
350
/**
351
* Create a new XMLEventReader from a reader.
352
* @param reader the XML data to read from
353
* @return an instance of the {@code XMLEventReader}
354
* @throws XMLStreamException if an error occurs
355
*/
356
public abstract XMLEventReader createXMLEventReader(java.io.Reader reader)
357
throws XMLStreamException;
358
359
/**
360
* Create a new XMLEventReader from a reader.
361
* @param systemId the system ID of the input
362
* @param reader the XML data to read from
363
* @return an instance of the {@code XMLEventReader}
364
* @throws XMLStreamException if an error occurs
365
*/
366
public abstract XMLEventReader createXMLEventReader(String systemId, java.io.Reader reader)
367
throws XMLStreamException;
368
369
/**
370
* Create a new XMLEventReader from an XMLStreamReader. After being used
371
* to construct the XMLEventReader instance returned from this method
372
* the XMLStreamReader must not be used.
373
* @param reader the XMLStreamReader to read from (may not be modified)
374
* @return a new XMLEventReader
375
* @throws XMLStreamException if an error occurs
376
*/
377
public abstract XMLEventReader createXMLEventReader(XMLStreamReader reader)
378
throws XMLStreamException;
379
380
/**
381
* Create a new XMLEventReader from a JAXP source.
382
* Support of this method is optional.
383
* @param source the source to read from
384
* @return an instance of the {@code XMLEventReader}
385
* @throws XMLStreamException if an error occurs
386
* @throws UnsupportedOperationException if this method is not
387
* supported by this XMLInputFactory
388
*/
389
public abstract XMLEventReader createXMLEventReader(Source source)
390
throws XMLStreamException;
391
392
/**
393
* Create a new XMLEventReader from a java.io.InputStream
394
* @param stream the InputStream to read from
395
* @return an instance of the {@code XMLEventReader}
396
* @throws XMLStreamException if an error occurs
397
*/
398
public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream)
399
throws XMLStreamException;
400
401
/**
402
* Create a new XMLEventReader from a java.io.InputStream
403
* @param stream the InputStream to read from
404
* @param encoding the character encoding of the stream
405
* @return an instance of the {@code XMLEventReader}
406
* @throws XMLStreamException if an error occurs
407
*/
408
public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding)
409
throws XMLStreamException;
410
411
/**
412
* Create a new XMLEventReader from a java.io.InputStream
413
* @param systemId the system ID of the stream
414
* @param stream the InputStream to read from
415
* @return an instance of the {@code XMLEventReader}
416
* @throws XMLStreamException if an error occurs
417
*/
418
public abstract XMLEventReader createXMLEventReader(String systemId, java.io.InputStream stream)
419
throws XMLStreamException;
420
421
/**
422
* Create a filtered reader that wraps the filter around the reader
423
* @param reader the reader to filter
424
* @param filter the filter to apply to the reader
425
* @return an instance of the {@code XMLEventReader}
426
* @throws XMLStreamException if an error occurs
427
*/
428
public abstract XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)
429
throws XMLStreamException;
430
431
/**
432
* Create a filtered event reader that wraps the filter around the event reader
433
* @param reader the event reader to wrap
434
* @param filter the filter to apply to the event reader
435
* @return an instance of the {@code XMLEventReader}
436
* @throws XMLStreamException if an error occurs
437
*/
438
public abstract XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
439
throws XMLStreamException;
440
441
/**
442
* The resolver that will be set on any XMLStreamReader or XMLEventReader created
443
* by this factory instance.
444
* @return an instance of the {@code XMLResolver}
445
*/
446
public abstract XMLResolver getXMLResolver();
447
448
/**
449
* The resolver that will be set on any XMLStreamReader or XMLEventReader created
450
* by this factory instance.
451
* @param resolver the resolver to use to resolve references
452
*/
453
public abstract void setXMLResolver(XMLResolver resolver);
454
455
/**
456
* The reporter that will be set on any XMLStreamReader or XMLEventReader created
457
* by this factory instance.
458
* @return an instance of the {@code XMLReporter}
459
*/
460
public abstract XMLReporter getXMLReporter();
461
462
/**
463
* The reporter that will be set on any XMLStreamReader or XMLEventReader created
464
* by this factory instance.
465
* @param reporter the resolver to use to report non fatal errors
466
*/
467
public abstract void setXMLReporter(XMLReporter reporter);
468
469
/**
470
* Allows the user to set specific feature/property on the underlying
471
* implementation. The underlying implementation is not required to support
472
* every setting of every property in the specification and may use
473
* IllegalArgumentException to signal that an unsupported property may not be
474
* set with the specified value.
475
* <p>
476
* All implementations that implement JAXP 1.5 or newer are required to
477
* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.
478
* <ul>
479
* <li>
480
* <p>
481
* Access to external DTDs, external Entity References is restricted to the
482
* protocols specified by the property. If access is denied during parsing
483
* due to the restriction of this property, {@link javax.xml.stream.XMLStreamException}
484
* will be thrown by the {@link javax.xml.stream.XMLStreamReader#next()} or
485
* {@link javax.xml.stream.XMLEventReader#nextEvent()} method.
486
*
487
* </li>
488
* </ul>
489
* @param name The name of the property (may not be null)
490
* @param value The value of the property
491
* @throws java.lang.IllegalArgumentException if the property is not supported
492
*/
493
public abstract void setProperty(java.lang.String name, Object value)
494
throws java.lang.IllegalArgumentException;
495
496
/**
497
* Get the value of a feature/property from the underlying implementation
498
* @param name The name of the property (may not be null)
499
* @return The value of the property
500
* @throws IllegalArgumentException if the property is not supported
501
*/
502
public abstract Object getProperty(java.lang.String name)
503
throws java.lang.IllegalArgumentException;
504
505
506
/**
507
* Query the set of properties that this factory supports.
508
*
509
* @param name The name of the property (may not be null)
510
* @return true if the property is supported and false otherwise
511
*/
512
public abstract boolean isPropertySupported(String name);
513
514
/**
515
* Set a user defined event allocator for events
516
* @param allocator the user defined allocator
517
*/
518
public abstract void setEventAllocator(XMLEventAllocator allocator);
519
520
/**
521
* Gets the allocator used by streams created with this factory
522
* @return an instance of the {@code XMLEventAllocator}
523
*/
524
public abstract XMLEventAllocator getEventAllocator();
525
526
}
527
528