Mercurial > dive4elements > framework
comparison artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java @ 338:ec5c7e54cae1
Cosmetics (and fix for XMLUtils.toString(Element)).
artifacts/trunk@2913 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 10 Oct 2011 07:37:06 +0000 |
parents | 2c968defd878 |
children | b3eb029e07dd |
comparison
equal
deleted
inserted
replaced
337:6d239c58c636 | 338:ec5c7e54cae1 |
---|---|
58 * and so on. | 58 * and so on. |
59 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 59 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
60 */ | 60 */ |
61 public final class XMLUtils | 61 public final class XMLUtils |
62 { | 62 { |
63 /** | 63 /** W3C URL of XForms. */ |
64 * W3C URL of XForms | |
65 */ | |
66 public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; | 64 public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; |
67 /** | 65 |
68 * W3C prefix of XForms | 66 /** W3C prefix of XForms. */ |
69 */ | |
70 public static final String XFORM_PREFIX = "xform"; | 67 public static final String XFORM_PREFIX = "xform"; |
71 | 68 |
69 /** Logger for this class. */ | |
72 private static Logger logger = Logger.getLogger(XMLUtils.class); | 70 private static Logger logger = Logger.getLogger(XMLUtils.class); |
73 | 71 |
74 private XMLUtils() { | 72 private XMLUtils() { |
75 } | 73 } |
76 | 74 |
78 * Helper class to generate elements and attributes with | 76 * Helper class to generate elements and attributes with |
79 * namespaces. | 77 * namespaces. |
80 */ | 78 */ |
81 public static class ElementCreator | 79 public static class ElementCreator |
82 { | 80 { |
83 /** | 81 /** Owner document of the elements to be created. */ |
84 * owner document of the elements to be created | |
85 */ | |
86 protected Document document; | 82 protected Document document; |
87 /** | 83 |
88 * namespace to be used | 84 /** Namespace to be used. */ |
89 */ | |
90 protected String ns; | 85 protected String ns; |
91 /** | 86 |
92 * prefix to be used | 87 /** Prefix to be used. */ |
93 */ | |
94 protected String prefix; | 88 protected String prefix; |
95 | 89 |
96 /** | 90 /** |
97 * Constructor to create an element/attribute creator | 91 * Constructor to create an element/attribute creator |
98 * with a given namespace and namespace prefix using a | 92 * with a given namespace and namespace prefix using a |
182 * Create xml/string representation of element (nested in otherwise empty | 176 * Create xml/string representation of element (nested in otherwise empty |
183 * document). | 177 * document). |
184 * @param element element to inspect in string. | 178 * @param element element to inspect in string. |
185 * @return string with xml representation of element. | 179 * @return string with xml representation of element. |
186 */ | 180 */ |
187 public final static String toString(Element element) { | |
188 Document doc = newDocument(); | |
189 doc.appendChild(doc.importNode(element,true)); | |
190 return toString(doc); | |
191 } | |
192 | |
193 | |
194 /** | |
195 * Creates xml/string representation of node (nested in otherwise empty | |
196 * document). | |
197 * @param element element to inspect in string. | |
198 * @return string with xml representation of element. | |
199 */ | |
200 public final static String toString(Node node) { | 181 public final static String toString(Node node) { |
201 Document doc = newDocument(); | 182 Document doc = newDocument(); |
202 doc.importNode(node, true); | 183 doc.appendChild(doc.importNode(node,true)); |
203 return toString(doc); | 184 return toString(doc); |
204 } | 185 } |
205 | 186 |
206 | 187 |
207 /** | 188 /** |
208 * Loads a XML document namespace aware from a file | 189 * Loads a XML document namespace aware from a file |
209 * @param file The file to load. | 190 * @param file The file to load. |
210 * @return the XML document or null if something went wrong | 191 * @return the XML document or null if something went wrong |