Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UncheckedJDOMFactory.java 9.7KB

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