1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jxpath.xml;
17
18 import java.io.InputStream;
19
20 import org.apache.commons.jxpath.JXPathException;
21 import org.jdom.input.SAXBuilder;
22
23 /***
24 * An implementation of the XMLParser interface that produces a JDOM Document.
25 *
26 * @author Dmitri Plotnikov
27 * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:37 $
28 */
29 public class JDOMParser extends XMLParser2 {
30
31 public Object parseXML(InputStream stream) {
32 if (!isNamespaceAware()) {
33 throw new JXPathException("JDOM parser configuration error. JDOM "
34 + "does not support the namespaceAware=false setting.");
35 }
36
37 try {
38 SAXBuilder builder = new SAXBuilder();
39 builder.setExpandEntities(isExpandEntityReferences());
40 builder.setIgnoringElementContentWhitespace(
41 isIgnoringElementContentWhitespace());
42 builder.setValidation(isValidating());
43 return builder.build(stream);
44 }
45 catch (Exception ex) {
46 throw new JXPathException("JDOM parser error", ex);
47 }
48 }
49 }