1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.util.xml;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.kernel.xml.Element;
27  import com.liferay.portal.kernel.xml.Namespace;
28  import com.liferay.portal.kernel.xml.QName;
29  import com.liferay.portal.kernel.xml.SAXReaderUtil;
30  
31  /**
32   * <a href="DocUtil.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class DocUtil {
38  
39      public static void add(Element element, String name, boolean text) {
40          add(element, name, String.valueOf(text));
41      }
42  
43      public static void add(Element element, String name, double text) {
44          add(element, name, String.valueOf(text));
45      }
46  
47      public static void add(Element element, String name, float text) {
48          add(element, name, String.valueOf(text));
49      }
50  
51      public static void add(Element element, String name, int text) {
52          add(element, name, String.valueOf(text));
53      }
54  
55      public static void add(Element element, String name, long text) {
56          add(element, name, String.valueOf(text));
57      }
58  
59      public static void add(Element element, String name, short text) {
60          add(element, name, String.valueOf(text));
61      }
62  
63      public static void add(Element element, String name, Object text) {
64          add(element, name, String.valueOf(text));
65      }
66  
67      public static void add(Element element, String name, String text) {
68          Element childElement = element.addElement(name);
69  
70          childElement.addText(GetterUtil.getString(text));
71      }
72  
73      public static Element add(
74          Element element, String name, Namespace namespace) {
75  
76          QName qName = SAXReaderUtil.createQName(name, namespace);
77  
78          return element.addElement(qName);
79      }
80  
81      public static void add(
82          Element element, String name, Namespace namespace, boolean text) {
83  
84          add(element, name, namespace, String.valueOf(text));
85      }
86  
87      public static void add(
88          Element element, String name, Namespace namespace, double text) {
89  
90          add(element, name, namespace, String.valueOf(text));
91      }
92  
93      public static void add(
94          Element element, String name, Namespace namespace, float text) {
95  
96          add(element, name, namespace, String.valueOf(text));
97      }
98  
99      public static void add(
100         Element element, String name, Namespace namespace, int text) {
101 
102         add(element, name, namespace, String.valueOf(text));
103     }
104 
105     public static void add(
106         Element element, String name, Namespace namespace, long text) {
107 
108         add(element, name, namespace, String.valueOf(text));
109     }
110 
111     public static void add(
112         Element element, String name, Namespace namespace, short text) {
113 
114         add(element, name, namespace, String.valueOf(text));
115     }
116 
117     public static void add(
118         Element element, String name, Namespace namespace, Object text) {
119 
120         add(element, name, namespace, String.valueOf(text));
121     }
122 
123     public static void add(
124         Element element, String name, Namespace namespace, String text) {
125 
126         QName qName = SAXReaderUtil.createQName(name, namespace);
127 
128         Element childElement = element.addElement(qName);
129 
130         childElement.addText(GetterUtil.getString(text));
131     }
132 
133     /**
134      * @deprecated
135      */
136     public static void add(
137         org.dom4j.Element element, String name, boolean text) {
138 
139         add(element, name, String.valueOf(text));
140     }
141 
142     /**
143      * @deprecated
144      */
145     public static void add(
146         org.dom4j.Element element, String name, double text) {
147 
148         add(element, name, String.valueOf(text));
149     }
150 
151     /**
152      * @deprecated
153      */
154     public static void add(org.dom4j.Element element, String name, float text) {
155         add(element, name, String.valueOf(text));
156     }
157 
158     /**
159      * @deprecated
160      */
161     public static void add(org.dom4j.Element element, String name, int text) {
162         add(element, name, String.valueOf(text));
163     }
164 
165     /**
166      * @deprecated
167      */
168     public static void add(org.dom4j.Element element, String name, long text) {
169         add(element, name, String.valueOf(text));
170     }
171 
172     /**
173      * @deprecated
174      */
175     public static void add(org.dom4j.Element element, String name, short text) {
176         add(element, name, String.valueOf(text));
177     }
178 
179     /**
180      * @deprecated
181      */
182     public static void add(
183         org.dom4j.Element element, String name, Object text) {
184 
185         add(element, name, String.valueOf(text));
186     }
187 
188     /**
189      * @deprecated
190      */
191     public static void add(
192         org.dom4j.Element element, String name, String text) {
193 
194         org.dom4j.Element childElement = element.addElement(name);
195 
196         childElement.addText(GetterUtil.getString(text));
197     }
198 
199     /**
200      * @deprecated
201      */
202     public static org.dom4j.Element add(
203         org.dom4j.Element element, String name, org.dom4j.Namespace namespace) {
204 
205         org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
206 
207         return element.addElement(qName);
208     }
209 
210     /**
211      * @deprecated
212      */
213     public static void add(
214         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
215         boolean text) {
216 
217         add(element, name, namespace, String.valueOf(text));
218     }
219 
220     /**
221      * @deprecated
222      */
223     public static void add(
224         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
225         double text) {
226 
227         add(element, name, namespace, String.valueOf(text));
228     }
229 
230     /**
231      * @deprecated
232      */
233     public static void add(
234         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
235         float text) {
236 
237         add(element, name, namespace, String.valueOf(text));
238     }
239 
240     /**
241      * @deprecated
242      */
243     public static void add(
244         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
245         int text) {
246 
247         add(element, name, namespace, String.valueOf(text));
248     }
249 
250     /**
251      * @deprecated
252      */
253     public static void add(
254         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
255         long text) {
256 
257         add(element, name, namespace, String.valueOf(text));
258     }
259 
260     /**
261      * @deprecated
262      */
263     public static void add(
264         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
265         short text) {
266 
267         add(element, name, namespace, String.valueOf(text));
268     }
269 
270     /**
271      * @deprecated
272      */
273     public static void add(
274         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
275         Object text) {
276 
277         add(element, name, namespace, String.valueOf(text));
278     }
279 
280     /**
281      * @deprecated
282      */
283     public static void add(
284         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
285         String text) {
286 
287         org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
288 
289         org.dom4j.Element childElement = element.addElement(qName);
290 
291         childElement.addText(GetterUtil.getString(text));
292     }
293 
294 }