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/XMLOutputFactory.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.XMLOutputFactoryImpl;
29
import javax.xml.transform.Result;
30
31
/**
32
* Defines an abstract implementation of a factory for
33
* getting XMLEventWriters and XMLStreamWriters.
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.isRepairingNamespaces</th><td>defaults prefixes
52
* on the output side</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
53
* </tbody>
54
* </table>
55
*
56
* <p>The following paragraphs describe the namespace and prefix repair algorithm:
57
*
58
* <p>The property can be set with the following code line:
59
* {@code setProperty("javax.xml.stream.isRepairingNamespaces", new Boolean(true|false));}
60
*
61
* <p>This property specifies that the writer default namespace prefix declarations.
62
* The default value is false.
63
*
64
* <p>If a writer isRepairingNamespaces it will create a namespace declaration
65
* on the current StartElement for
66
* any attribute that does not
67
* currently have a namespace declaration in scope. If the StartElement
68
* has a uri but no prefix specified a prefix will be assigned, if the prefix
69
* has not been declared in a parent of the current StartElement it will be declared
70
* on the current StartElement. If the defaultNamespace is bound and in scope
71
* and the default namespace matches the URI of the attribute or StartElement
72
* QName no prefix will be assigned.
73
*
74
* <p>If an element or attribute name has a prefix, but is not
75
* bound to any namespace URI, then the prefix will be removed
76
* during serialization.
77
*
78
* <p>If element and/or attribute names in the same start or
79
* empty-element tag are bound to different namespace URIs and
80
* are using the same prefix then the element or the first
81
* occurring attribute retains the original prefix and the
82
* following attributes have their prefixes replaced with a
83
* new prefix that is bound to the namespace URIs of those
84
* attributes.
85
*
86
* <p>If an element or attribute name uses a prefix that is
87
* bound to a different URI than that inherited from the
88
* namespace context of the parent of that element and there
89
* is no namespace declaration in the context of the current
90
* element then such a namespace declaration is added.
91
*
92
* <p>If an element or attribute name is bound to a prefix and
93
* there is a namespace declaration that binds that prefix
94
* to a different URI then that namespace declaration is
95
* either removed if the correct mapping is inherited from
96
* the parent context of that element, or changed to the
97
* namespace URI of the element or attribute using that prefix.
98
*
99
* @version 1.2
100
* @author Copyright (c) 2009, 2015 by Oracle Corporation. All Rights Reserved.
101
* @see XMLInputFactory
102
* @see XMLEventWriter
103
* @see XMLStreamWriter
104
* @since 1.6
105
*/
106
public abstract class XMLOutputFactory {
107
/**
108
* Property used to set prefix defaulting on the output side
109
*/
110
public static final String IS_REPAIRING_NAMESPACES=
111
"javax.xml.stream.isRepairingNamespaces";
112
113
static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
114
115
/**
116
* Protected constructor to prevent instantiation.
117
* Use {@link #newFactory()} instead.
118
*/
119
protected XMLOutputFactory(){}
120
121
/**
122
* Creates a new instance of the {@code XMLOutputFactory} builtin
123
* system-default implementation.
124
*
125
* @return A new instance of the {@code XMLOutputFactory} builtin
126
* system-default implementation.
127
*
128
* @since 9
129
*/
130
public static XMLOutputFactory newDefaultFactory() {
131
return new XMLOutputFactoryImpl();
132
}
133
134
/**
135
* Creates a new instance of the factory in exactly the same manner as the
136
* {@link #newFactory()} method.
137
* @return an instance of the {@code XMLOutputFactory}
138
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
139
*/
140
public static XMLOutputFactory newInstance()
141
throws FactoryConfigurationError
142
{
143
return FactoryFinder.find(XMLOutputFactory.class, DEFAULIMPL);
144
}
145
146
/**
147
* Creates a new instance of the factory. This method uses the
148
* <a href="../../../module-summary.html#LookupMechanism">JAXP Lookup Mechanism</a>
149
* to determine the {@code XMLOutputFactory} implementation class to load.
150
* <p>
151
* Once an application has obtained a reference to a {@code XMLOutputFactory}, it
152
* can use the factory to configure and obtain stream instances.
153
*
154
* @return an instance of the {@code XMLOutputFactory}
155
* @throws FactoryConfigurationError in case of {@linkplain
156
* java.util.ServiceConfigurationError service configuration error} or if
157
* the implementation is not available or cannot be instantiated.
158
*/
159
public static XMLOutputFactory newFactory()
160
throws FactoryConfigurationError
161
{
162
return FactoryFinder.find(XMLOutputFactory.class, DEFAULIMPL);
163
}
164
165
/**
166
* Create a new instance of the factory.
167
*
168
* @param factoryId Name of the factory to find, same as
169
* a property name
170
* @param classLoader classLoader to use
171
* @return the factory implementation
172
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
173
*
174
* @deprecated This method has been deprecated because it returns an
175
* instance of XMLInputFactory, which is of the wrong class.
176
* Use the new method {@link #newFactory(java.lang.String,
177
* java.lang.ClassLoader)} instead.
178
*/
179
@Deprecated(since="1.7")
180
public static XMLInputFactory newInstance(String factoryId,
181
ClassLoader classLoader)
182
throws FactoryConfigurationError {
183
//do not fallback if given classloader can't find the class, throw exception
184
return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
185
}
186
187
/**
188
* Create a new instance of the factory.
189
* If the classLoader argument is null, then the ContextClassLoader is used.
190
* <p>
191
* This method uses the following ordered lookup procedure to determine
192
* the XMLOutputFactory implementation class to load:
193
* <ul>
194
* <li>
195
* Use the value of the system property identified by {@code factoryId}.
196
* </li>
197
* <li>
198
* <p>
199
* Use the configuration file "stax.properties". The file is in standard
200
* {@link java.util.Properties} format and typically located in the
201
* {@code conf} directory of the Java installation. It contains the fully qualified
202
* name of the implementation class with the key being the system property
203
* defined above.
204
*
205
* <p>
206
* The stax.properties file is read only once by the implementation
207
* and its values are then cached for future use. If the file does not exist
208
* when the first attempt is made to read from it, no further attempts are
209
* made to check for its existence. It is not possible to change the value
210
* of any property in stax.properties after it has been read for the first time.
211
*
212
* <p>
213
* Use the jaxp configuration file "jaxp.properties". The file is in the same
214
* format as stax.properties and will only be read if stax.properties does
215
* not exist.
216
* </li>
217
* <li>
218
* <p>
219
* If {@code factoryId} is "javax.xml.stream.XMLOutputFactory",
220
* use the service-provider loading facility, defined by the
221
* {@link java.util.ServiceLoader} class, to attempt to {@linkplain
222
* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}
223
* an implementation of the service using the specified {@code ClassLoader}.
224
* If {@code classLoader} is null, the {@linkplain
225
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
226
* That is, the service-provider loading facility will use the {@linkplain
227
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
228
* to attempt to load the service. If the context class
229
* loader is null, the {@linkplain
230
* ClassLoader#getSystemClassLoader() system class loader} will be used.
231
* </li>
232
* <li>
233
* <p>
234
* Otherwise, throws a {@link FactoryConfigurationError}.
235
* </li>
236
* </ul>
237
*
238
* @apiNote The parameter factoryId defined here is inconsistent with that
239
* of other JAXP factories where the first parameter is fully qualified
240
* factory class name that provides implementation of the factory.
241
*
242
* <p>
243
* Note that this is a new method that replaces the deprecated
244
* {@link #newInstance(java.lang.String, java.lang.ClassLoader)
245
* newInstance(String factoryId, ClassLoader classLoader)} method.
246
* The original method was incorrectly defined to return XMLInputFactory.
247
*
248
*
249
* @param factoryId Name of the factory to find, same as
250
* a property name
251
* @param classLoader classLoader to use
252
* @return the factory implementation
253
* @throws FactoryConfigurationError in case of {@linkplain
254
* java.util.ServiceConfigurationError service configuration error} or if
255
* the implementation is not available or cannot be instantiated.
256
*/
257
public static XMLOutputFactory newFactory(String factoryId,
258
ClassLoader classLoader)
259
throws FactoryConfigurationError {
260
//do not fallback if given classloader can't find the class, throw exception
261
return FactoryFinder.find(XMLOutputFactory.class, factoryId, classLoader, null);
262
}
263
264
/**
265
* Create a new XMLStreamWriter that writes to a writer
266
* @param stream the writer to write to
267
* @return instance of the {@code XMLStreamWriter}
268
* @throws XMLStreamException if an error occurs
269
*/
270
public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException;
271
272
/**
273
* Create a new XMLStreamWriter that writes to a stream
274
* @param stream the stream to write to
275
* @return instance of the {@code XMLStreamWriter}
276
* @throws XMLStreamException if an error occurs
277
*/
278
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException;
279
280
/**
281
* Create a new XMLStreamWriter that writes to a stream
282
* @param stream the stream to write to
283
* @param encoding the encoding to use
284
* @return instance of the {@code XMLStreamWriter}
285
* @throws XMLStreamException if an error occurs
286
*/
287
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream,
288
String encoding) throws XMLStreamException;
289
290
/**
291
* Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.
292
* @param result the result to write to
293
* @return instance of the {@code XMLStreamWriter}
294
* @throws UnsupportedOperationException if this method is not
295
* supported by this XMLOutputFactory
296
* @throws XMLStreamException if an error occurs
297
*/
298
public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;
299
300
301
/**
302
* Create a new XMLEventWriter that writes to a JAXP result. This method is optional.
303
* @param result the result to write to
304
* @return instance of the {@code XMLEventWriter}
305
* @throws UnsupportedOperationException if this method is not
306
* supported by this XMLOutputFactory
307
* @throws XMLStreamException if an error occurs
308
*/
309
public abstract XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException;
310
311
/**
312
* Create a new XMLEventWriter that writes to a stream
313
* @param stream the stream to write to
314
* @return instance of the {@code XMLEventWriter}
315
* @throws XMLStreamException if an error occurs
316
*/
317
public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream) throws XMLStreamException;
318
319
320
321
/**
322
* Create a new XMLEventWriter that writes to a stream
323
* @param stream the stream to write to
324
* @param encoding the encoding to use
325
* @return instance of the {@code XMLEventWriter}
326
* @throws XMLStreamException if an error occurs
327
*/
328
public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream,
329
String encoding) throws XMLStreamException;
330
331
/**
332
* Create a new XMLEventWriter that writes to a writer
333
* @param stream the stream to write to
334
* @return instance of the {@code XMLEventWriter}
335
* @throws XMLStreamException if an error occurs
336
*/
337
public abstract XMLEventWriter createXMLEventWriter(java.io.Writer stream) throws XMLStreamException;
338
339
/**
340
* Allows the user to set specific features/properties on the underlying implementation.
341
* @param name The name of the property
342
* @param value The value of the property
343
* @throws java.lang.IllegalArgumentException if the property is not supported
344
*/
345
public abstract void setProperty(java.lang.String name,
346
Object value)
347
throws IllegalArgumentException;
348
349
/**
350
* Get a feature/property on the underlying implementation
351
* @param name The name of the property
352
* @return The value of the property
353
* @throws java.lang.IllegalArgumentException if the property is not supported
354
*/
355
public abstract Object getProperty(java.lang.String name)
356
throws IllegalArgumentException;
357
358
/**
359
* Query the set of properties that this factory supports.
360
*
361
* @param name The name of the property (may not be null)
362
* @return true if the property is supported and false otherwise
363
*/
364
public abstract boolean isPropertySupported(String name);
365
}
366
367