1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class DocUtil {
37  
38      public static void add(Element element, String name, boolean text) {
39          add(element, name, String.valueOf(text));
40      }
41  
42      public static void add(Element element, String name, double text) {
43          add(element, name, String.valueOf(text));
44      }
45  
46      public static void add(Element element, String name, float text) {
47          add(element, name, String.valueOf(text));
48      }
49  
50      public static void add(Element element, String name, int text) {
51          add(element, name, String.valueOf(text));
52      }
53  
54      public static void add(Element element, String name, long text) {
55          add(element, name, String.valueOf(text));
56      }
57  
58      public static void add(Element element, String name, short text) {
59          add(element, name, String.valueOf(text));
60      }
61  
62      public static void add(Element element, String name, Object text) {
63          add(element, name, String.valueOf(text));
64      }
65  
66      public static void add(Element element, String name, String text) {
67          Element childElement = element.addElement(name);
68  
69          childElement.addText(GetterUtil.getString(text));
70      }
71  
72      public static Element add(
73          Element element, String name, Namespace namespace) {
74  
75          QName qName = SAXReaderUtil.createQName(name, namespace);
76  
77          return element.addElement(qName);
78      }
79  
80      public static void add(
81          Element element, String name, Namespace namespace, boolean text) {
82  
83          add(element, name, namespace, String.valueOf(text));
84      }
85  
86      public static void add(
87          Element element, String name, Namespace namespace, double text) {
88  
89          add(element, name, namespace, String.valueOf(text));
90      }
91  
92      public static void add(
93          Element element, String name, Namespace namespace, float text) {
94  
95          add(element, name, namespace, String.valueOf(text));
96      }
97  
98      public static void add(
99          Element element, String name, Namespace namespace, int text) {
100 
101         add(element, name, namespace, String.valueOf(text));
102     }
103 
104     public static void add(
105         Element element, String name, Namespace namespace, long text) {
106 
107         add(element, name, namespace, String.valueOf(text));
108     }
109 
110     public static void add(
111         Element element, String name, Namespace namespace, short text) {
112 
113         add(element, name, namespace, String.valueOf(text));
114     }
115 
116     public static void add(
117         Element element, String name, Namespace namespace, Object text) {
118 
119         add(element, name, namespace, String.valueOf(text));
120     }
121 
122     public static void add(
123         Element element, String name, Namespace namespace, String text) {
124 
125         QName qName = SAXReaderUtil.createQName(name, namespace);
126 
127         Element childElement = element.addElement(qName);
128 
129         childElement.addText(GetterUtil.getString(text));
130     }
131 
132     /**
133      * @deprecated
134      */
135     public static void add(
136         org.dom4j.Element element, String name, boolean text) {
137 
138         add(element, name, String.valueOf(text));
139     }
140 
141     /**
142      * @deprecated
143      */
144     public static void add(
145         org.dom4j.Element element, String name, double text) {
146 
147         add(element, name, String.valueOf(text));
148     }
149 
150     /**
151      * @deprecated
152      */
153     public static void add(org.dom4j.Element element, String name, float text) {
154         add(element, name, String.valueOf(text));
155     }
156 
157     /**
158      * @deprecated
159      */
160     public static void add(org.dom4j.Element element, String name, int text) {
161         add(element, name, String.valueOf(text));
162     }
163 
164     /**
165      * @deprecated
166      */
167     public static void add(org.dom4j.Element element, String name, long text) {
168         add(element, name, String.valueOf(text));
169     }
170 
171     /**
172      * @deprecated
173      */
174     public static void add(org.dom4j.Element element, String name, short text) {
175         add(element, name, String.valueOf(text));
176     }
177 
178     /**
179      * @deprecated
180      */
181     public static void add(
182         org.dom4j.Element element, String name, Object text) {
183 
184         add(element, name, String.valueOf(text));
185     }
186 
187     /**
188      * @deprecated
189      */
190     public static void add(
191         org.dom4j.Element element, String name, String text) {
192 
193         org.dom4j.Element childElement = element.addElement(name);
194 
195         childElement.addText(GetterUtil.getString(text));
196     }
197 
198     /**
199      * @deprecated
200      */
201     public static org.dom4j.Element add(
202         org.dom4j.Element element, String name, org.dom4j.Namespace namespace) {
203 
204         org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
205 
206         return element.addElement(qName);
207     }
208 
209     /**
210      * @deprecated
211      */
212     public static void add(
213         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
214         boolean text) {
215 
216         add(element, name, namespace, String.valueOf(text));
217     }
218 
219     /**
220      * @deprecated
221      */
222     public static void add(
223         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
224         double text) {
225 
226         add(element, name, namespace, String.valueOf(text));
227     }
228 
229     /**
230      * @deprecated
231      */
232     public static void add(
233         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
234         float text) {
235 
236         add(element, name, namespace, String.valueOf(text));
237     }
238 
239     /**
240      * @deprecated
241      */
242     public static void add(
243         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
244         int text) {
245 
246         add(element, name, namespace, String.valueOf(text));
247     }
248 
249     /**
250      * @deprecated
251      */
252     public static void add(
253         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
254         long text) {
255 
256         add(element, name, namespace, String.valueOf(text));
257     }
258 
259     /**
260      * @deprecated
261      */
262     public static void add(
263         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
264         short text) {
265 
266         add(element, name, namespace, String.valueOf(text));
267     }
268 
269     /**
270      * @deprecated
271      */
272     public static void add(
273         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
274         Object text) {
275 
276         add(element, name, namespace, String.valueOf(text));
277     }
278 
279     /**
280      * @deprecated
281      */
282     public static void add(
283         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
284         String text) {
285 
286         org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
287 
288         org.dom4j.Element childElement = element.addElement(qName);
289 
290         childElement.addText(GetterUtil.getString(text));
291     }
292 
293 }