author | serb |
Thu, 25 Dec 2014 22:48:13 +0300 | |
changeset 28535 | 74115b2c211f |
parent 27574 | 2e8afdf5c6fb |
child 29419 | 534054ee6062 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
12005 | 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.parsers; |
|
27 |
||
28 |
import javax.xml.validation.Schema; |
|
29 |
||
30 |
/** |
|
31 |
* Defines a factory API that enables applications to obtain a |
|
32 |
* parser that produces DOM object trees from XML documents. |
|
33 |
* |
|
34 |
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a> |
|
35 |
* @author <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a> |
|
36 |
* |
|
25262 | 37 |
* @since 1.4 |
12005 | 38 |
*/ |
39 |
||
40 |
public abstract class DocumentBuilderFactory { |
|
41 |
||
42 |
private boolean validating = false; |
|
43 |
private boolean namespaceAware = false; |
|
44 |
private boolean whitespace = false; |
|
45 |
private boolean expandEntityRef = true; |
|
46 |
private boolean ignoreComments = false; |
|
47 |
private boolean coalescing = false; |
|
48 |
||
49 |
/** |
|
50 |
* <p>Protected constructor to prevent instantiation. |
|
51 |
* Use {@link #newInstance()}.</p> |
|
52 |
*/ |
|
53 |
protected DocumentBuilderFactory () { |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Obtain a new instance of a |
|
58 |
* <code>DocumentBuilderFactory</code>. This static method creates |
|
59 |
* a new factory instance. |
|
60 |
* This method uses the following ordered lookup procedure to determine |
|
61 |
* the <code>DocumentBuilderFactory</code> implementation class to |
|
62 |
* load: |
|
63 |
* <ul> |
|
64 |
* <li> |
|
65 |
* Use the <code>javax.xml.parsers.DocumentBuilderFactory</code> system |
|
66 |
* property. |
|
67 |
* </li> |
|
68 |
* <li> |
|
27574 | 69 |
* Use the properties file "conf/jaxp.properties" in the JRE directory. |
12005 | 70 |
* This configuration file is in standard <code>java.util.Properties |
71 |
* </code> format and contains the fully qualified name of the |
|
72 |
* implementation class with the key being the system property defined |
|
73 |
* above. |
|
74 |
* |
|
75 |
* The jaxp.properties file is read only once by the JAXP implementation |
|
76 |
* and it's values are then cached for future use. If the file does not exist |
|
77 |
* when the first attempt is made to read from it, no further attempts are |
|
78 |
* made to check for its existence. It is not possible to change the value |
|
79 |
* of any property in jaxp.properties after it has been read for the first time. |
|
80 |
* </li> |
|
81 |
* <li> |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
82 |
* Uses the service-provider loading facilities, defined by the |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
83 |
* {@link java.util.ServiceLoader} class, to attempt to locate and load an |
20581
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
84 |
* implementation of the service using the {@linkplain |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
85 |
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}: |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
86 |
* the service-provider loading facility will use the {@linkplain |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
87 |
* java.lang.Thread#getContextClassLoader() current thread's context class loader} |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
88 |
* to attempt to load the service. If the context class |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
89 |
* loader is null, the {@linkplain |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17534
diff
changeset
|
90 |
* ClassLoader#getSystemClassLoader() system class loader} will be used. |
12005 | 91 |
* </li> |
92 |
* <li> |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
93 |
* Otherwise, the system-default implementation is returned. |
12005 | 94 |
* </li> |
95 |
* </ul> |
|
96 |
* |
|
97 |
* Once an application has obtained a reference to a |
|
98 |
* <code>DocumentBuilderFactory</code> it can use the factory to |
|
99 |
* configure and obtain parser instances. |
|
100 |
* |
|
101 |
* |
|
102 |
* <h2>Tip for Trouble-shooting</h2> |
|
103 |
* <p>Setting the <code>jaxp.debug</code> system property will cause |
|
104 |
* this method to print a lot of debug messages |
|
105 |
* to <code>System.err</code> about what it is doing and where it is looking at.</p> |
|
106 |
* |
|
107 |
* <p> If you have problems loading {@link DocumentBuilder}s, try:</p> |
|
108 |
* <pre> |
|
109 |
* java -Djaxp.debug=1 YourProgram .... |
|
110 |
* </pre> |
|
111 |
* |
|
112 |
* @return New instance of a <code>DocumentBuilderFactory</code> |
|
113 |
* |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
114 |
* @throws FactoryConfigurationError in case of {@linkplain |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
115 |
* java.util.ServiceConfigurationError service configuration error} or if |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
116 |
* the implementation is not available or cannot be instantiated. |
12005 | 117 |
*/ |
118 |
public static DocumentBuilderFactory newInstance() { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
119 |
return FactoryFinder.find( |
12005 | 120 |
/* The default property name according to the JAXP spec */ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
121 |
DocumentBuilderFactory.class, // "javax.xml.parsers.DocumentBuilderFactory" |
12005 | 122 |
/* The fallback implementation class name */ |
123 |
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* <p>Obtain a new instance of a <code>DocumentBuilderFactory</code> from class name. |
|
128 |
* This function is useful when there are multiple providers in the classpath. |
|
129 |
* It gives more control to the application as it can specify which provider |
|
130 |
* should be loaded.</p> |
|
131 |
* |
|
132 |
* <p>Once an application has obtained a reference to a <code>DocumentBuilderFactory</code> |
|
133 |
* it can use the factory to configure and obtain parser instances.</p> |
|
134 |
* |
|
135 |
* |
|
136 |
* <h2>Tip for Trouble-shooting</h2> |
|
137 |
* <p>Setting the <code>jaxp.debug</code> system property will cause |
|
138 |
* this method to print a lot of debug messages |
|
139 |
* to <code>System.err</code> about what it is doing and where it is looking at.</p> |
|
140 |
* |
|
141 |
* <p> If you have problems try:</p> |
|
142 |
* <pre> |
|
143 |
* java -Djaxp.debug=1 YourProgram .... |
|
144 |
* </pre> |
|
145 |
* |
|
146 |
* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.parsers.DocumentBuilderFactory</code>. |
|
147 |
* |
|
148 |
* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code> |
|
149 |
* current <code>Thread</code>'s context classLoader is used to load the factory class. |
|
150 |
* |
|
151 |
* @return New instance of a <code>DocumentBuilderFactory</code> |
|
152 |
* |
|
153 |
* @throws FactoryConfigurationError if <code>factoryClassName</code> is <code>null</code>, or |
|
154 |
* the factory class cannot be loaded, instantiated. |
|
155 |
* |
|
156 |
* @see #newInstance() |
|
157 |
* |
|
158 |
* @since 1.6 |
|
159 |
*/ |
|
160 |
public static DocumentBuilderFactory newInstance(String factoryClassName, ClassLoader classLoader){ |
|
161 |
//do not fallback if given classloader can't find the class, throw exception |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
162 |
return FactoryFinder.newInstance(DocumentBuilderFactory.class, |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
163 |
factoryClassName, classLoader, false); |
12005 | 164 |
} |
165 |
||
166 |
/** |
|
167 |
* Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder} |
|
168 |
* using the currently configured parameters. |
|
169 |
* |
|
170 |
* @return A new instance of a DocumentBuilder. |
|
171 |
* |
|
172 |
* @throws ParserConfigurationException if a DocumentBuilder |
|
173 |
* cannot be created which satisfies the configuration requested. |
|
174 |
*/ |
|
175 |
||
176 |
public abstract DocumentBuilder newDocumentBuilder() |
|
177 |
throws ParserConfigurationException; |
|
178 |
||
179 |
||
180 |
/** |
|
181 |
* Specifies that the parser produced by this code will |
|
182 |
* provide support for XML namespaces. By default the value of this is set |
|
183 |
* to <code>false</code> |
|
184 |
* |
|
185 |
* @param awareness true if the parser produced will provide support |
|
186 |
* for XML namespaces; false otherwise. |
|
187 |
*/ |
|
188 |
||
189 |
public void setNamespaceAware(boolean awareness) { |
|
190 |
this.namespaceAware = awareness; |
|
191 |
} |
|
192 |
||
193 |
/** |
|
194 |
* Specifies that the parser produced by this code will |
|
195 |
* validate documents as they are parsed. By default the value of this |
|
196 |
* is set to <code>false</code>. |
|
197 |
* |
|
198 |
* <p> |
|
199 |
* Note that "the validation" here means |
|
200 |
* <a href="http://www.w3.org/TR/REC-xml#proc-types">a validating |
|
201 |
* parser</a> as defined in the XML recommendation. |
|
202 |
* In other words, it essentially just controls the DTD validation. |
|
203 |
* (except the legacy two properties defined in JAXP 1.2.) |
|
204 |
* </p> |
|
205 |
* |
|
206 |
* <p> |
|
207 |
* To use modern schema languages such as W3C XML Schema or |
|
208 |
* RELAX NG instead of DTD, you can configure your parser to be |
|
209 |
* a non-validating parser by leaving the {@link #setValidating(boolean)} |
|
210 |
* method <code>false</code>, then use the {@link #setSchema(Schema)} |
|
211 |
* method to associate a schema to a parser. |
|
212 |
* </p> |
|
213 |
* |
|
214 |
* @param validating true if the parser produced will validate documents |
|
215 |
* as they are parsed; false otherwise. |
|
216 |
*/ |
|
217 |
||
218 |
public void setValidating(boolean validating) { |
|
219 |
this.validating = validating; |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* Specifies that the parsers created by this factory must eliminate |
|
224 |
* whitespace in element content (sometimes known loosely as |
|
225 |
* 'ignorable whitespace') when parsing XML documents (see XML Rec |
|
226 |
* 2.10). Note that only whitespace which is directly contained within |
|
227 |
* element content that has an element only content model (see XML |
|
228 |
* Rec 3.2.1) will be eliminated. Due to reliance on the content model |
|
229 |
* this setting requires the parser to be in validating mode. By default |
|
230 |
* the value of this is set to <code>false</code>. |
|
231 |
* |
|
232 |
* @param whitespace true if the parser created must eliminate whitespace |
|
233 |
* in the element content when parsing XML documents; |
|
234 |
* false otherwise. |
|
235 |
*/ |
|
236 |
||
237 |
public void setIgnoringElementContentWhitespace(boolean whitespace) { |
|
238 |
this.whitespace = whitespace; |
|
239 |
} |
|
240 |
||
241 |
/** |
|
242 |
* Specifies that the parser produced by this code will |
|
243 |
* expand entity reference nodes. By default the value of this is set to |
|
244 |
* <code>true</code> |
|
245 |
* |
|
246 |
* @param expandEntityRef true if the parser produced will expand entity |
|
247 |
* reference nodes; false otherwise. |
|
248 |
*/ |
|
249 |
||
250 |
public void setExpandEntityReferences(boolean expandEntityRef) { |
|
251 |
this.expandEntityRef = expandEntityRef; |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* <p>Specifies that the parser produced by this code will |
|
256 |
* ignore comments. By default the value of this is set to <code>false |
|
257 |
* </code>.</p> |
|
258 |
* |
|
259 |
* @param ignoreComments <code>boolean</code> value to ignore comments during processing |
|
260 |
*/ |
|
261 |
||
262 |
public void setIgnoringComments(boolean ignoreComments) { |
|
263 |
this.ignoreComments = ignoreComments; |
|
264 |
} |
|
265 |
||
266 |
/** |
|
267 |
* Specifies that the parser produced by this code will |
|
268 |
* convert CDATA nodes to Text nodes and append it to the |
|
269 |
* adjacent (if any) text node. By default the value of this is set to |
|
270 |
* <code>false</code> |
|
271 |
* |
|
272 |
* @param coalescing true if the parser produced will convert CDATA nodes |
|
273 |
* to Text nodes and append it to the adjacent (if any) |
|
274 |
* text node; false otherwise. |
|
275 |
*/ |
|
276 |
||
277 |
public void setCoalescing(boolean coalescing) { |
|
278 |
this.coalescing = coalescing; |
|
279 |
} |
|
280 |
||
281 |
/** |
|
282 |
* Indicates whether or not the factory is configured to produce |
|
283 |
* parsers which are namespace aware. |
|
284 |
* |
|
285 |
* @return true if the factory is configured to produce parsers which |
|
286 |
* are namespace aware; false otherwise. |
|
287 |
*/ |
|
288 |
||
289 |
public boolean isNamespaceAware() { |
|
290 |
return namespaceAware; |
|
291 |
} |
|
292 |
||
293 |
/** |
|
294 |
* Indicates whether or not the factory is configured to produce |
|
295 |
* parsers which validate the XML content during parse. |
|
296 |
* |
|
297 |
* @return true if the factory is configured to produce parsers |
|
298 |
* which validate the XML content during parse; false otherwise. |
|
299 |
*/ |
|
300 |
||
301 |
public boolean isValidating() { |
|
302 |
return validating; |
|
303 |
} |
|
304 |
||
305 |
/** |
|
306 |
* Indicates whether or not the factory is configured to produce |
|
307 |
* parsers which ignore ignorable whitespace in element content. |
|
308 |
* |
|
309 |
* @return true if the factory is configured to produce parsers |
|
310 |
* which ignore ignorable whitespace in element content; |
|
311 |
* false otherwise. |
|
312 |
*/ |
|
313 |
||
314 |
public boolean isIgnoringElementContentWhitespace() { |
|
315 |
return whitespace; |
|
316 |
} |
|
317 |
||
318 |
/** |
|
319 |
* Indicates whether or not the factory is configured to produce |
|
320 |
* parsers which expand entity reference nodes. |
|
321 |
* |
|
322 |
* @return true if the factory is configured to produce parsers |
|
323 |
* which expand entity reference nodes; false otherwise. |
|
324 |
*/ |
|
325 |
||
326 |
public boolean isExpandEntityReferences() { |
|
327 |
return expandEntityRef; |
|
328 |
} |
|
329 |
||
330 |
/** |
|
331 |
* Indicates whether or not the factory is configured to produce |
|
332 |
* parsers which ignores comments. |
|
333 |
* |
|
334 |
* @return true if the factory is configured to produce parsers |
|
335 |
* which ignores comments; false otherwise. |
|
336 |
*/ |
|
337 |
||
338 |
public boolean isIgnoringComments() { |
|
339 |
return ignoreComments; |
|
340 |
} |
|
341 |
||
342 |
/** |
|
343 |
* Indicates whether or not the factory is configured to produce |
|
344 |
* parsers which converts CDATA nodes to Text nodes and appends it to |
|
345 |
* the adjacent (if any) Text node. |
|
346 |
* |
|
347 |
* @return true if the factory is configured to produce parsers |
|
348 |
* which converts CDATA nodes to Text nodes and appends it to |
|
349 |
* the adjacent (if any) Text node; false otherwise. |
|
350 |
*/ |
|
351 |
||
352 |
public boolean isCoalescing() { |
|
353 |
return coalescing; |
|
354 |
} |
|
355 |
||
356 |
/** |
|
357 |
* Allows the user to set specific attributes on the underlying |
|
358 |
* implementation. |
|
17534 | 359 |
* <p> |
360 |
* All implementations that implement JAXP 1.5 or newer are required to |
|
361 |
* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} and |
|
362 |
* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} properties. |
|
363 |
* </p> |
|
364 |
* <ul> |
|
365 |
* <li> |
|
366 |
* <p> |
|
367 |
* Setting the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property |
|
368 |
* restricts the access to external DTDs, external Entity References to the |
|
369 |
* protocols specified by the property. |
|
370 |
* If access is denied during parsing due to the restriction of this property, |
|
371 |
* {@link org.xml.sax.SAXException} will be thrown by the parse methods defined by |
|
372 |
* {@link javax.xml.parsers.DocumentBuilder}. |
|
373 |
* </p> |
|
374 |
* <p> |
|
375 |
* Setting the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} property |
|
376 |
* restricts the access to external Schema set by the schemaLocation attribute to |
|
377 |
* the protocols specified by the property. If access is denied during parsing |
|
378 |
* due to the restriction of this property, {@link org.xml.sax.SAXException} |
|
379 |
* will be thrown by the parse methods defined by |
|
380 |
* {@link javax.xml.parsers.DocumentBuilder}. |
|
381 |
* </p> |
|
382 |
* </li> |
|
383 |
* </ul> |
|
12005 | 384 |
* |
385 |
* @param name The name of the attribute. |
|
386 |
* @param value The value of the attribute. |
|
387 |
* |
|
388 |
* @throws IllegalArgumentException thrown if the underlying |
|
389 |
* implementation doesn't recognize the attribute. |
|
390 |
*/ |
|
391 |
public abstract void setAttribute(String name, Object value) |
|
392 |
throws IllegalArgumentException; |
|
393 |
||
394 |
/** |
|
395 |
* Allows the user to retrieve specific attributes on the underlying |
|
396 |
* implementation. |
|
397 |
* |
|
398 |
* @param name The name of the attribute. |
|
399 |
* |
|
400 |
* @return value The value of the attribute. |
|
401 |
* |
|
402 |
* @throws IllegalArgumentException thrown if the underlying |
|
403 |
* implementation doesn't recognize the attribute. |
|
404 |
*/ |
|
405 |
public abstract Object getAttribute(String name) |
|
406 |
throws IllegalArgumentException; |
|
407 |
||
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
408 |
/** |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
409 |
* <p>Set a feature for this <code>DocumentBuilderFactory</code> and <code>DocumentBuilder</code>s created by this factory.</p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
410 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
411 |
* <p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
412 |
* Feature names are fully qualified {@link java.net.URI}s. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
413 |
* Implementations may define their own features. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
414 |
* A {@link ParserConfigurationException} is thrown if this <code>DocumentBuilderFactory</code> or the |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
415 |
* <code>DocumentBuilder</code>s it creates cannot support the feature. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
416 |
* It is possible for a <code>DocumentBuilderFactory</code> to expose a feature value but be unable to change its state. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
417 |
* </p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
418 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
419 |
* <p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
420 |
* All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
421 |
* When the feature is:</p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
422 |
* <ul> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
423 |
* <li> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
424 |
* <code>true</code>: the implementation will limit XML processing to conform to implementation limits. |
24887 | 425 |
* Examples include entity expansion limits and XML Schema constructs that would consume large amounts of resources. |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
426 |
* If XML processing is limited for security reasons, it will be reported via a call to the registered |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
427 |
* {@link org.xml.sax.ErrorHandler#fatalError(SAXParseException exception)}. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
428 |
* See {@link DocumentBuilder#setErrorHandler(org.xml.sax.ErrorHandler errorHandler)}. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
429 |
* </li> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
430 |
* <li> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
431 |
* <code>false</code>: the implementation will processing XML according to the XML specifications without |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
432 |
* regard to possible implementation limits. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
433 |
* </li> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
434 |
* </ul> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
435 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
436 |
* @param name Feature name. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
437 |
* @param value Is feature state <code>true</code> or <code>false</code>. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
438 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
439 |
* @throws ParserConfigurationException if this <code>DocumentBuilderFactory</code> or the <code>DocumentBuilder</code>s |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
440 |
* it creates cannot support this feature. |
12005 | 441 |
* @throws NullPointerException If the <code>name</code> parameter is null. |
25262 | 442 |
* @since 1.5 |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
443 |
*/ |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
444 |
public abstract void setFeature(String name, boolean value) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
445 |
throws ParserConfigurationException; |
12005 | 446 |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
447 |
/** |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
448 |
* <p>Get the state of the named feature.</p> |
12005 | 449 |
* |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
450 |
* <p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
451 |
* Feature names are fully qualified {@link java.net.URI}s. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
452 |
* Implementations may define their own features. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
453 |
* An {@link ParserConfigurationException} is thrown if this <code>DocumentBuilderFactory</code> or the |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
454 |
* <code>DocumentBuilder</code>s it creates cannot support the feature. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
455 |
* It is possible for an <code>DocumentBuilderFactory</code> to expose a feature value but be unable to change its state. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
456 |
* </p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
457 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
458 |
* @param name Feature name. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
459 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
460 |
* @return State of the named feature. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
461 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
462 |
* @throws ParserConfigurationException if this <code>DocumentBuilderFactory</code> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
463 |
* or the <code>DocumentBuilder</code>s it creates cannot support this feature. |
25262 | 464 |
* @since 1.5 |
12005 | 465 |
*/ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
466 |
public abstract boolean getFeature(String name) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
467 |
throws ParserConfigurationException; |
12005 | 468 |
|
469 |
||
470 |
/** |
|
471 |
* Gets the {@link Schema} object specified through |
|
472 |
* the {@link #setSchema(Schema schema)} method. |
|
473 |
* |
|
474 |
* @return |
|
475 |
* the {@link Schema} object that was last set through |
|
476 |
* the {@link #setSchema(Schema)} method, or null |
|
477 |
* if the method was not invoked since a {@link DocumentBuilderFactory} |
|
478 |
* is created. |
|
479 |
* |
|
480 |
* @throws UnsupportedOperationException When implementation does not |
|
481 |
* override this method. |
|
482 |
* |
|
483 |
* @since 1.5 |
|
484 |
*/ |
|
485 |
public Schema getSchema() { |
|
486 |
throw new UnsupportedOperationException( |
|
487 |
"This parser does not support specification \"" |
|
488 |
+ this.getClass().getPackage().getSpecificationTitle() |
|
489 |
+ "\" version \"" |
|
490 |
+ this.getClass().getPackage().getSpecificationVersion() |
|
491 |
+ "\"" |
|
492 |
); |
|
493 |
||
494 |
} |
|
495 |
||
496 |
/** |
|
497 |
* <p>Set the {@link Schema} to be used by parsers created |
|
498 |
* from this factory. |
|
499 |
* |
|
500 |
* <p> |
|
501 |
* When a {@link Schema} is non-null, a parser will use a validator |
|
502 |
* created from it to validate documents before it passes information |
|
503 |
* down to the application. |
|
504 |
* |
|
505 |
* <p>When errors are found by the validator, the parser is responsible |
|
506 |
* to report them to the user-specified {@link org.xml.sax.ErrorHandler} |
|
507 |
* (or if the error handler is not set, ignore them or throw them), just |
|
508 |
* like any other errors found by the parser itself. |
|
509 |
* In other words, if the user-specified {@link org.xml.sax.ErrorHandler} |
|
510 |
* is set, it must receive those errors, and if not, they must be |
|
511 |
* treated according to the implementation specific |
|
512 |
* default error handling rules. |
|
513 |
* |
|
514 |
* <p> |
|
515 |
* A validator may modify the outcome of a parse (for example by |
|
516 |
* adding default values that were missing in documents), and a parser |
|
517 |
* is responsible to make sure that the application will receive |
|
518 |
* modified DOM trees. |
|
519 |
* |
|
520 |
* <p> |
|
24887 | 521 |
* Initially, null is set as the {@link Schema}. |
12005 | 522 |
* |
523 |
* <p> |
|
524 |
* This processing will take effect even if |
|
525 |
* the {@link #isValidating()} method returns <code>false</code>. |
|
526 |
* |
|
527 |
* <p>It is an error to use |
|
528 |
* the <code>http://java.sun.com/xml/jaxp/properties/schemaSource</code> |
|
529 |
* property and/or the <code>http://java.sun.com/xml/jaxp/properties/schemaLanguage</code> |
|
530 |
* property in conjunction with a {@link Schema} object. |
|
531 |
* Such configuration will cause a {@link ParserConfigurationException} |
|
532 |
* exception when the {@link #newDocumentBuilder()} is invoked.</p> |
|
533 |
* |
|
534 |
* |
|
24887 | 535 |
* <h4>Note for implementors</h4> |
12005 | 536 |
* |
537 |
* <p> |
|
538 |
* A parser must be able to work with any {@link Schema} |
|
539 |
* implementation. However, parsers and schemas are allowed |
|
540 |
* to use implementation-specific custom mechanisms |
|
541 |
* as long as they yield the result described in the specification. |
|
542 |
* </p> |
|
543 |
* |
|
544 |
* @param schema <code>Schema</code> to use or <code>null</code> |
|
545 |
* to remove a schema. |
|
546 |
* |
|
547 |
* @throws UnsupportedOperationException When implementation does not |
|
548 |
* override this method. |
|
549 |
* |
|
550 |
* @since 1.5 |
|
551 |
*/ |
|
552 |
public void setSchema(Schema schema) { |
|
553 |
throw new UnsupportedOperationException( |
|
554 |
"This parser does not support specification \"" |
|
555 |
+ this.getClass().getPackage().getSpecificationTitle() |
|
556 |
+ "\" version \"" |
|
557 |
+ this.getClass().getPackage().getSpecificationVersion() |
|
558 |
+ "\"" |
|
559 |
); |
|
560 |
} |
|
561 |
||
562 |
||
563 |
||
564 |
/** |
|
565 |
* <p>Set state of XInclude processing.</p> |
|
566 |
* |
|
567 |
* <p>If XInclude markup is found in the document instance, should it be |
|
568 |
* processed as specified in <a href="http://www.w3.org/TR/xinclude/"> |
|
569 |
* XML Inclusions (XInclude) Version 1.0</a>.</p> |
|
570 |
* |
|
571 |
* <p>XInclude processing defaults to <code>false</code>.</p> |
|
572 |
* |
|
573 |
* @param state Set XInclude processing to <code>true</code> or |
|
574 |
* <code>false</code> |
|
575 |
* |
|
576 |
* @throws UnsupportedOperationException When implementation does not |
|
577 |
* override this method. |
|
578 |
* |
|
579 |
* @since 1.5 |
|
580 |
*/ |
|
581 |
public void setXIncludeAware(final boolean state) { |
|
582 |
if (state) { |
|
583 |
throw new UnsupportedOperationException(" setXIncludeAware " + |
|
584 |
"is not supported on this JAXP" + |
|
585 |
" implementation or earlier: " + this.getClass()); |
|
586 |
} |
|
587 |
} |
|
588 |
||
589 |
/** |
|
590 |
* <p>Get state of XInclude processing.</p> |
|
591 |
* |
|
592 |
* @return current state of XInclude processing |
|
593 |
* |
|
594 |
* @throws UnsupportedOperationException When implementation does not |
|
595 |
* override this method. |
|
596 |
* |
|
597 |
* @since 1.5 |
|
598 |
*/ |
|
599 |
public boolean isXIncludeAware() { |
|
600 |
throw new UnsupportedOperationException( |
|
601 |
"This parser does not support specification \"" |
|
602 |
+ this.getClass().getPackage().getSpecificationTitle() |
|
603 |
+ "\" version \"" |
|
604 |
+ this.getClass().getPackage().getSpecificationVersion() |
|
605 |
+ "\"" |
|
606 |
); |
|
607 |
} |
|
608 |
} |