1 package tests.org.w3c.dom;
2 
3 import javax.xml.parsers.DocumentBuilder;
4 import javax.xml.parsers.DocumentBuilderFactory;
5 import javax.xml.parsers.ParserConfigurationException;
6 
7 public class DOMDocumentBuilderFactory {
8     /**
9      * Parser configuration
10      */
11     private DocumentBuilderSetting[] settings = null;
12 
13     private DocumentBuilder builder = null;
14 
15     private DocumentBuilderFactory factory = null;
16 
DOMDocumentBuilderFactory(DocumentBuilderSetting[] settings)17     public DOMDocumentBuilderFactory(DocumentBuilderSetting[] settings) {
18         if (settings == null) {
19             settings = new DocumentBuilderSetting[0];
20         } else {
21             settings = (DocumentBuilderSetting[]) settings.clone();
22         }
23 
24         factory = DocumentBuilderFactory.newInstance();
25 
26         if (factory == null) {
27             throw new RuntimeException("DocumentBuilderFactory must not be null");
28         }
29 
30         if (settings != null) {
31             for (int i = 0; i < settings.length; i++) {
32                 settings[i].applySetting(factory);
33             }
34         }
35         try {
36             builder = factory.newDocumentBuilder();
37         } catch (ParserConfigurationException e) {
38             e.printStackTrace();
39         }
40 
41         if (builder == null) {
42             throw new RuntimeException("DocumentBuilder must not be null");
43         }
44 
45     }
46 
getBuilder()47     public DocumentBuilder getBuilder() {
48         return builder;
49     }
50 
hasFeature(String feature, String version)51     public boolean hasFeature(String feature, String version) {
52         return builder.getDOMImplementation().hasFeature(feature, version);
53     }
54 
isCoalescing()55     public boolean isCoalescing() {
56         return factory.isCoalescing();
57     }
58 
isExpandEntityReferences()59     public boolean isExpandEntityReferences() {
60         return factory.isExpandEntityReferences();
61     }
62 
isIgnoringElementContentWhitespace()63     public boolean isIgnoringElementContentWhitespace() {
64         return factory.isIgnoringElementContentWhitespace();
65     }
66 
isNamespaceAware()67     public boolean isNamespaceAware() {
68         return factory.isNamespaceAware();
69     }
70 
isValidating()71     public boolean isValidating() {
72         return factory.isValidating();
73     }
74 
getConfiguration1()75     public static DocumentBuilderSetting[] getConfiguration1() {
76         return new DocumentBuilderSetting[] {
77                 DocumentBuilderSetting.notCoalescing,
78                 DocumentBuilderSetting.notExpandEntityReferences,
79                 DocumentBuilderSetting.notIgnoringElementContentWhitespace,
80                 DocumentBuilderSetting.notNamespaceAware,
81                 DocumentBuilderSetting.notValidating };
82     }
83 
getConfiguration2()84     public static DocumentBuilderSetting[] getConfiguration2() {
85         return new DocumentBuilderSetting[] {
86                 DocumentBuilderSetting.notCoalescing,
87                 DocumentBuilderSetting.notExpandEntityReferences,
88                 DocumentBuilderSetting.notIgnoringElementContentWhitespace,
89                 DocumentBuilderSetting.namespaceAware,
90                 DocumentBuilderSetting.notValidating };
91 
92     }
93 
94 }
95