1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| package org.dom4j.dom; |
11 |
| |
12 |
| import java.util.Map; |
13 |
| |
14 |
| import org.dom4j.Attribute; |
15 |
| import org.dom4j.CDATA; |
16 |
| import org.dom4j.Comment; |
17 |
| import org.dom4j.Document; |
18 |
| import org.dom4j.DocumentFactory; |
19 |
| import org.dom4j.DocumentType; |
20 |
| import org.dom4j.Element; |
21 |
| import org.dom4j.Entity; |
22 |
| import org.dom4j.Namespace; |
23 |
| import org.dom4j.ProcessingInstruction; |
24 |
| import org.dom4j.QName; |
25 |
| import org.dom4j.Text; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class DOMDocumentFactory extends DocumentFactory implements org.w3c.dom.DOMImplementation { |
34 |
| |
35 |
| |
36 |
| |
37 |
| private final static ThreadLocal singlePerThread=new ThreadLocal(); |
38 |
| private static String domDocumentFactoryClassName=null; |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
14
| public static DocumentFactory getInstance() {
|
47 |
14
| DOMDocumentFactory fact =(DOMDocumentFactory)singlePerThread.get();
|
48 |
14
| if (fact==null) {
|
49 |
4
| fact= new DOMDocumentFactory();
|
50 |
4
| singlePerThread.set(fact);
|
51 |
| } |
52 |
14
| if (fact==null){
|
53 |
| } |
54 |
14
| return fact;
|
55 |
| } |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
6
| public Document createDocument() {
|
61 |
6
| DOMDocument answer = new DOMDocument();
|
62 |
6
| answer.setDocumentFactory( this );
|
63 |
6
| return answer;
|
64 |
| } |
65 |
| |
66 |
0
| public DocumentType createDocType(String name, String publicId, String systemId) {
|
67 |
0
| return new DOMDocumentType( name, publicId, systemId );
|
68 |
| } |
69 |
| |
70 |
232
| public Element createElement(QName qname) {
|
71 |
232
| return new DOMElement(qname);
|
72 |
| } |
73 |
| |
74 |
0
| public Element createElement(QName qname, int attributeCount) {
|
75 |
0
| return new DOMElement(qname, attributeCount);
|
76 |
| } |
77 |
| |
78 |
176
| public Attribute createAttribute(Element owner, QName qname, String value) {
|
79 |
176
| return new DOMAttribute(qname, value);
|
80 |
| } |
81 |
| |
82 |
0
| public CDATA createCDATA(String text) {
|
83 |
0
| return new DOMCDATA(text);
|
84 |
| } |
85 |
| |
86 |
18
| public Comment createComment(String text) {
|
87 |
18
| return new DOMComment(text);
|
88 |
| } |
89 |
| |
90 |
424
| public Text createText(String text) {
|
91 |
424
| return new DOMText(text);
|
92 |
| } |
93 |
| |
94 |
0
| public Entity createEntity(String name) {
|
95 |
0
| return new DOMEntityReference(name);
|
96 |
| } |
97 |
| |
98 |
0
| public Entity createEntity(String name, String text) {
|
99 |
0
| return new DOMEntityReference(name, text);
|
100 |
| } |
101 |
| |
102 |
234
| public Namespace createNamespace(String prefix, String uri) {
|
103 |
234
| return new DOMNamespace(prefix, uri);
|
104 |
| } |
105 |
| |
106 |
| |
107 |
18
| public ProcessingInstruction createProcessingInstruction(String target, String data) {
|
108 |
18
| return new DOMProcessingInstruction(target, data);
|
109 |
| } |
110 |
| |
111 |
0
| public ProcessingInstruction createProcessingInstruction(String target, Map data) {
|
112 |
0
| return new DOMProcessingInstruction(target, data);
|
113 |
| } |
114 |
| |
115 |
| |
116 |
| |
117 |
0
| public boolean hasFeature(String feature, String version) {
|
118 |
0
| if ("XML".equalsIgnoreCase(feature) || "Core".equalsIgnoreCase(feature)) {
|
119 |
0
| return (version == null || version.length() == 0 || "1.0".equals(version) || "2.0".equals(version));
|
120 |
| } |
121 |
0
| return false;
|
122 |
| } |
123 |
| |
124 |
0
| public org.w3c.dom.DocumentType createDocumentType(
|
125 |
| String qualifiedName, String publicId, String systemId |
126 |
| ) throws org.w3c.dom.DOMException { |
127 |
0
| return new DOMDocumentType( qualifiedName, publicId, systemId );
|
128 |
| } |
129 |
| |
130 |
0
| public org.w3c.dom.Document createDocument(
|
131 |
| String namespaceURI, |
132 |
| String qualifiedName, |
133 |
| org.w3c.dom.DocumentType documentType |
134 |
| ) throws org.w3c.dom.DOMException { |
135 |
0
| DOMDocument document;
|
136 |
0
| if (documentType != null) {
|
137 |
0
| DOMDocumentType docType = asDocumentType( documentType );
|
138 |
0
| document = new DOMDocument( docType );
|
139 |
| } else { |
140 |
0
| document = new DOMDocument();
|
141 |
| } |
142 |
| |
143 |
0
| document.addElement( createQName( qualifiedName, namespaceURI ) );
|
144 |
0
| return document;
|
145 |
| } |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
0
| protected DOMDocumentType asDocumentType( org.w3c.dom.DocumentType documentType ) {
|
151 |
0
| if ( documentType instanceof DOMDocumentType ) {
|
152 |
0
| return (DOMDocumentType) documentType;
|
153 |
| } |
154 |
| else { |
155 |
0
| return new DOMDocumentType(
|
156 |
| documentType.getName(), |
157 |
| documentType.getPublicId(), |
158 |
| documentType.getSystemId() |
159 |
| ); |
160 |
| } |
161 |
| } |
162 |
| |
163 |
| } |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
| |
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 |
| |