|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| package org.dom4j.dom; |
|
9 |
| |
|
10 |
| import java.util.Map; |
|
11 |
| |
|
12 |
| import org.dom4j.Attribute; |
|
13 |
| import org.dom4j.CDATA; |
|
14 |
| import org.dom4j.Comment; |
|
15 |
| import org.dom4j.Document; |
|
16 |
| import org.dom4j.DocumentFactory; |
|
17 |
| import org.dom4j.DocumentType; |
|
18 |
| import org.dom4j.Element; |
|
19 |
| import org.dom4j.Entity; |
|
20 |
| import org.dom4j.Namespace; |
|
21 |
| import org.dom4j.ProcessingInstruction; |
|
22 |
| import org.dom4j.QName; |
|
23 |
| import org.dom4j.Text; |
|
24 |
| import org.dom4j.util.SingletonStrategy; |
|
25 |
| import org.w3c.dom.DOMException; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| public class DOMDocumentFactory extends DocumentFactory implements |
|
37 |
| org.w3c.dom.DOMImplementation { |
|
38 |
| |
|
39 |
| |
|
40 |
| private static SingletonStrategy singleton = null; |
|
41 |
| |
|
42 |
| static { |
|
43 |
3
| try {
|
|
44 |
3
| String defaultSingletonClass = "org.dom4j.util.SimpleSingleton";
|
|
45 |
3
| Class clazz = null;
|
|
46 |
3
| try {
|
|
47 |
3
| String singletonClass = defaultSingletonClass;
|
|
48 |
3
| singletonClass = System.getProperty(
|
|
49 |
| "org.dom4j.dom.DOMDocumentFactory.singleton.strategy", |
|
50 |
| singletonClass); |
|
51 |
3
| clazz = Class.forName(singletonClass);
|
|
52 |
| } catch (Exception exc1) { |
|
53 |
0
| try {
|
|
54 |
0
| String singletonClass = defaultSingletonClass;
|
|
55 |
0
| clazz = Class.forName(singletonClass);
|
|
56 |
| } catch (Exception exc2) { |
|
57 |
| } |
|
58 |
| } |
|
59 |
3
| singleton = (SingletonStrategy) clazz.newInstance();
|
|
60 |
3
| singleton.setSingletonClassName(DOMDocumentFactory.class.getName());
|
|
61 |
| } catch (Exception exc3) { |
|
62 |
| } |
|
63 |
| } |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
12
| public static DocumentFactory getInstance() {
|
|
73 |
12
| DOMDocumentFactory fact = (DOMDocumentFactory) singleton.instance();
|
|
74 |
12
| return fact;
|
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
6
| public Document createDocument() {
|
|
79 |
6
| DOMDocument answer = new DOMDocument();
|
|
80 |
6
| answer.setDocumentFactory(this);
|
|
81 |
| |
|
82 |
6
| return answer;
|
|
83 |
| } |
|
84 |
| |
|
85 |
0
| public DocumentType createDocType(String name, String publicId,
|
|
86 |
| String systemId) { |
|
87 |
0
| return new DOMDocumentType(name, publicId, systemId);
|
|
88 |
| } |
|
89 |
| |
|
90 |
151
| public Element createElement(QName qname) {
|
|
91 |
151
| return new DOMElement(qname);
|
|
92 |
| } |
|
93 |
| |
|
94 |
0
| public Element createElement(QName qname, int attributeCount) {
|
|
95 |
0
| return new DOMElement(qname, attributeCount);
|
|
96 |
| } |
|
97 |
| |
|
98 |
114
| public Attribute createAttribute(Element owner, QName qname, String value) {
|
|
99 |
114
| return new DOMAttribute(qname, value);
|
|
100 |
| } |
|
101 |
| |
|
102 |
0
| public CDATA createCDATA(String text) {
|
|
103 |
0
| return new DOMCDATA(text);
|
|
104 |
| } |
|
105 |
| |
|
106 |
12
| public Comment createComment(String text) {
|
|
107 |
12
| return new DOMComment(text);
|
|
108 |
| } |
|
109 |
| |
|
110 |
307
| public Text createText(String text) {
|
|
111 |
307
| return new DOMText(text);
|
|
112 |
| } |
|
113 |
| |
|
114 |
0
| public Entity createEntity(String name) {
|
|
115 |
0
| return new DOMEntityReference(name);
|
|
116 |
| } |
|
117 |
| |
|
118 |
0
| public Entity createEntity(String name, String text) {
|
|
119 |
0
| return new DOMEntityReference(name, text);
|
|
120 |
| } |
|
121 |
| |
|
122 |
159
| public Namespace createNamespace(String prefix, String uri) {
|
|
123 |
159
| return new DOMNamespace(prefix, uri);
|
|
124 |
| } |
|
125 |
| |
|
126 |
12
| public ProcessingInstruction createProcessingInstruction(String target,
|
|
127 |
| String data) { |
|
128 |
12
| return new DOMProcessingInstruction(target, data);
|
|
129 |
| } |
|
130 |
| |
|
131 |
0
| public ProcessingInstruction createProcessingInstruction(String target,
|
|
132 |
| Map data) { |
|
133 |
0
| return new DOMProcessingInstruction(target, data);
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
0
| public boolean hasFeature(String feat, String version) {
|
|
138 |
0
| if ("XML".equalsIgnoreCase(feat) || "Core".equalsIgnoreCase(feat)) {
|
|
139 |
0
| return ((version == null) || (version.length() == 0)
|
|
140 |
| || "1.0".equals(version) || "2.0".equals(version)); |
|
141 |
| } |
|
142 |
| |
|
143 |
0
| return false;
|
|
144 |
| } |
|
145 |
| |
|
146 |
0
| public org.w3c.dom.DocumentType createDocumentType(String qualifiedName,
|
|
147 |
| String publicId, String systemId) throws DOMException { |
|
148 |
0
| return new DOMDocumentType(qualifiedName, publicId, systemId);
|
|
149 |
| } |
|
150 |
| |
|
151 |
0
| public org.w3c.dom.Document createDocument(String namespaceURI,
|
|
152 |
| String qualifiedName, org.w3c.dom.DocumentType docType) |
|
153 |
| throws org.w3c.dom.DOMException { |
|
154 |
0
| DOMDocument document;
|
|
155 |
| |
|
156 |
0
| if (docType != null) {
|
|
157 |
0
| DOMDocumentType documentType = asDocumentType(docType);
|
|
158 |
0
| document = new DOMDocument(documentType);
|
|
159 |
| } else { |
|
160 |
0
| document = new DOMDocument();
|
|
161 |
| } |
|
162 |
| |
|
163 |
0
| document.addElement(createQName(qualifiedName, namespaceURI));
|
|
164 |
| |
|
165 |
0
| return document;
|
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
0
| protected DOMDocumentType asDocumentType(org.w3c.dom.DocumentType docType) {
|
|
170 |
0
| if (docType instanceof DOMDocumentType) {
|
|
171 |
0
| return (DOMDocumentType) docType;
|
|
172 |
| } else { |
|
173 |
0
| return new DOMDocumentType(docType.getName(),
|
|
174 |
| docType.getPublicId(), docType.getSystemId()); |
|
175 |
| } |
|
176 |
| } |
|
177 |
| } |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |