comparison NGSrich_0.5.5/src/org/jdom/UncheckedJDOMFactory.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:89ad0a9cca52
1 /*--
2
3 $Id: UncheckedJDOMFactory.java,v 1.4 2007/11/10 05:28:59 jhunter Exp $
4
5 Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 1. Redistributions of source code must retain the above copyright
13 notice, this list of conditions, and the following disclaimer.
14
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions, and the disclaimer that follows
17 these conditions in the documentation and/or other materials
18 provided with the distribution.
19
20 3. The name "JDOM" must not be used to endorse or promote products
21 derived from this software without prior written permission. For
22 written permission, please contact <request_AT_jdom_DOT_org>.
23
24 4. Products derived from this software may not be called "JDOM", nor
25 may "JDOM" appear in their name, without prior written permission
26 from the JDOM Project Management <request_AT_jdom_DOT_org>.
27
28 In addition, we request (but do not require) that you include in the
29 end-user documentation provided with the redistribution and/or in the
30 software itself an acknowledgement equivalent to the following:
31 "This product includes software developed by the
32 JDOM Project (http://www.jdom.org/)."
33 Alternatively, the acknowledgment may be graphical using the logos
34 available at http://www.jdom.org/images/logos.
35
36 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39 DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
40 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 SUCH DAMAGE.
48
49 This software consists of voluntary contributions made by many
50 individuals on behalf of the JDOM Project and was originally
51 created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
52 Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
53 on the JDOM Project, please see <http://www.jdom.org/>.
54
55 */
56
57 package org.jdom;
58
59 import java.util.*;
60
61 /**
62 * Special factory for building documents without any content or structure
63 * checking. This should only be used when you are 100% positive that the
64 * input is absolutely correct. This factory can speed builds, but any
65 * problems in the input will be uncaught until later when they could cause
66 * infinite loops, malformed XML, or worse. Use with extreme caution.
67 */
68 public class UncheckedJDOMFactory implements JDOMFactory {
69
70 // =====================================================================
71 // Element Factory
72 // =====================================================================
73
74 public Element element(String name, Namespace namespace) {
75 Element e = new Element();
76 e.name = name;
77 if (namespace == null) {
78 namespace = Namespace.NO_NAMESPACE;
79 }
80 e.namespace = namespace;
81 return e;
82 }
83
84 public Element element(String name) {
85 Element e = new Element();
86 e.name = name;
87 e.namespace = Namespace.NO_NAMESPACE;
88 return e;
89 }
90
91 public Element element(String name, String uri) {
92 return element(name, Namespace.getNamespace("", uri));
93 }
94
95 public Element element(String name, String prefix, String uri) {
96 return element(name, Namespace.getNamespace(prefix, uri));
97 }
98
99 // =====================================================================
100 // Attribute Factory
101 // =====================================================================
102
103 public Attribute attribute(String name, String value, Namespace namespace) {
104 Attribute a = new Attribute();
105 a.name = name;
106 a.value = value;
107 if (namespace == null) {
108 namespace = Namespace.NO_NAMESPACE;
109 }
110 a.namespace = namespace;
111 return a;
112 }
113
114 public Attribute attribute(String name, String value, int type, Namespace namespace) {
115 Attribute a = new Attribute();
116 a.name = name;
117 a.type = type;
118 a.value = value;
119 if (namespace == null) {
120 namespace = Namespace.NO_NAMESPACE;
121 }
122 a.namespace = namespace;
123 return a;
124 }
125
126 public Attribute attribute(String name, String value) {
127 Attribute a = new Attribute();
128 a.name = name;
129 a.value = value;
130 a.namespace = Namespace.NO_NAMESPACE;
131 return a;
132 }
133
134 public Attribute attribute(String name, String value, int type) {
135 Attribute a = new Attribute();
136 a.name = name;
137 a.type = type;
138 a.value = value;
139 a.namespace = Namespace.NO_NAMESPACE;
140 return a;
141 }
142
143 // =====================================================================
144 // Text Factory
145 // =====================================================================
146
147 public Text text(String str) {
148 Text t = new Text();
149 t.value = str;
150 return t;
151 }
152
153 // =====================================================================
154 // CDATA Factory
155 // =====================================================================
156
157 public CDATA cdata(String str) {
158 CDATA c = new CDATA();
159 c.value = str;
160 return c;
161 }
162
163 // =====================================================================
164 // Comment Factory
165 // =====================================================================
166
167 public Comment comment(String str) {
168 Comment c = new Comment();
169 c.text = str;
170 return c;
171 }
172
173 // =====================================================================
174 // Processing Instruction Factory
175 // =====================================================================
176
177 public ProcessingInstruction processingInstruction(String target, Map data) {
178 ProcessingInstruction p = new ProcessingInstruction();
179 p.target = target;
180 p.setData(data);
181 return p;
182 }
183
184 public ProcessingInstruction processingInstruction(String target, String data) {
185 ProcessingInstruction p = new ProcessingInstruction();
186 p.target = target;
187 p.setData(data);
188 return p;
189 }
190
191 // =====================================================================
192 // Entity Ref Factory
193 // =====================================================================
194
195 public EntityRef entityRef(String name) {
196 EntityRef e = new org.jdom.EntityRef();
197 e.name = name;
198 return e;
199 }
200
201 public EntityRef entityRef(String name, String systemID) {
202 EntityRef e = new EntityRef();
203 e.name = name;
204 e.systemID = systemID;
205 return e;
206 }
207
208 public EntityRef entityRef(String name, String publicID, String systemID) {
209 EntityRef e = new EntityRef();
210 e.name = name;
211 e.publicID = publicID;
212 e.systemID = systemID;
213 return e;
214 }
215
216 // =====================================================================
217 // DocType Factory
218 // =====================================================================
219
220 public DocType docType(String elementName, String publicID, String systemID) {
221 DocType d = new DocType();
222 d.elementName = elementName;
223 d.publicID = publicID;
224 d.systemID = systemID;
225 return d;
226 }
227
228 public DocType docType(String elementName, String systemID) {
229 return docType(elementName, null, systemID);
230 }
231
232 public DocType docType(String elementName) {
233 return docType(elementName, null, null);
234 }
235
236 // =====================================================================
237 // Document Factory
238 // =====================================================================
239
240 public Document document(Element rootElement, DocType docType, String baseURI) {
241 Document d = new Document();
242 if (docType != null) {
243 addContent(d, docType);
244 }
245 if (rootElement != null) {
246 addContent(d, rootElement);
247 }
248 if (baseURI != null) {
249 d.baseURI = baseURI;
250 }
251 return d;
252 }
253
254 public Document document(Element rootElement, DocType docType) {
255 return document(rootElement, docType, null);
256 }
257
258 public Document document(Element rootElement) {
259 return document(rootElement, null, null);
260 }
261
262 // =====================================================================
263 // List manipulation
264 // =====================================================================
265
266 public void addContent(Parent parent, Content child) {
267 if (parent instanceof Element) {
268 Element elt = (Element) parent;
269 elt.content.uncheckedAddContent(child);
270 }
271 else {
272 Document doc = (Document) parent;
273 doc.content.uncheckedAddContent(child);
274 }
275 }
276
277 public void setAttribute(Element parent, Attribute a) {
278 parent.attributes.uncheckedAddAttribute(a);
279 }
280
281 public void addNamespaceDeclaration(Element parent, Namespace additional) {
282 if (parent.additionalNamespaces == null) {
283 parent.additionalNamespaces = new ArrayList(5); //Element.INITIAL_ARRAY_SIZE
284 }
285 parent.additionalNamespaces.add(additional);
286 }
287 }