001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.xml;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.xml.Element;
019    import com.liferay.portal.kernel.xml.Namespace;
020    import com.liferay.portal.kernel.xml.QName;
021    import com.liferay.portal.kernel.xml.SAXReaderUtil;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class DocUtil {
027    
028            public static void add(Element element, String name, boolean text) {
029                    add(element, name, String.valueOf(text));
030            }
031    
032            public static void add(Element element, String name, double text) {
033                    add(element, name, String.valueOf(text));
034            }
035    
036            public static void add(Element element, String name, float text) {
037                    add(element, name, String.valueOf(text));
038            }
039    
040            public static void add(Element element, String name, int text) {
041                    add(element, name, String.valueOf(text));
042            }
043    
044            public static void add(Element element, String name, long text) {
045                    add(element, name, String.valueOf(text));
046            }
047    
048            public static Element add(
049                    Element element, String name, Namespace namespace) {
050    
051                    QName qName = SAXReaderUtil.createQName(name, namespace);
052    
053                    return element.addElement(qName);
054            }
055    
056            public static void add(
057                    Element element, String name, Namespace namespace, boolean text) {
058    
059                    add(element, name, namespace, String.valueOf(text));
060            }
061    
062            public static void add(
063                    Element element, String name, Namespace namespace, double text) {
064    
065                    add(element, name, namespace, String.valueOf(text));
066            }
067    
068            public static void add(
069                    Element element, String name, Namespace namespace, float text) {
070    
071                    add(element, name, namespace, String.valueOf(text));
072            }
073    
074            public static void add(
075                    Element element, String name, Namespace namespace, int text) {
076    
077                    add(element, name, namespace, String.valueOf(text));
078            }
079    
080            public static void add(
081                    Element element, String name, Namespace namespace, long text) {
082    
083                    add(element, name, namespace, String.valueOf(text));
084            }
085    
086            public static void add(
087                    Element element, String name, Namespace namespace, Object text) {
088    
089                    add(element, name, namespace, String.valueOf(text));
090            }
091    
092            public static void add(
093                    Element element, String name, Namespace namespace, short text) {
094    
095                    add(element, name, namespace, String.valueOf(text));
096            }
097    
098            public static void add(
099                    Element element, String name, Namespace namespace, String text) {
100    
101                    QName qName = SAXReaderUtil.createQName(name, namespace);
102    
103                    Element childElement = element.addElement(qName);
104    
105                    childElement.addText(GetterUtil.getString(text));
106            }
107    
108            public static void add(Element element, String name, Object text) {
109                    add(element, name, String.valueOf(text));
110            }
111    
112            public static void add(Element element, String name, short text) {
113                    add(element, name, String.valueOf(text));
114            }
115    
116            public static void add(Element element, String name, String text) {
117                    Element childElement = element.addElement(name);
118    
119                    childElement.addText(GetterUtil.getString(text));
120            }
121    
122            /**
123             * @deprecated
124             */
125            public static void add(
126                    org.dom4j.Element element, String name, boolean text) {
127    
128                    add(element, name, String.valueOf(text));
129            }
130    
131            /**
132             * @deprecated
133             */
134            public static void add(
135                    org.dom4j.Element element, String name, double text) {
136    
137                    add(element, name, String.valueOf(text));
138            }
139    
140            /**
141             * @deprecated
142             */
143            public static void add(org.dom4j.Element element, String name, float text) {
144                    add(element, name, String.valueOf(text));
145            }
146    
147            /**
148             * @deprecated
149             */
150            public static void add(org.dom4j.Element element, String name, int text) {
151                    add(element, name, String.valueOf(text));
152            }
153    
154            /**
155             * @deprecated
156             */
157            public static void add(org.dom4j.Element element, String name, long text) {
158                    add(element, name, String.valueOf(text));
159            }
160    
161            /**
162             * @deprecated
163             */
164            public static void add(
165                    org.dom4j.Element element, String name, Object text) {
166    
167                    add(element, name, String.valueOf(text));
168            }
169    
170            /**
171             * @deprecated
172             */
173            public static org.dom4j.Element add(
174                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace) {
175    
176                    org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
177    
178                    return element.addElement(qName);
179            }
180    
181            /**
182             * @deprecated
183             */
184            public static void add(
185                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
186                    boolean text) {
187    
188                    add(element, name, namespace, String.valueOf(text));
189            }
190    
191            /**
192             * @deprecated
193             */
194            public static void add(
195                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
196                    double text) {
197    
198                    add(element, name, namespace, String.valueOf(text));
199            }
200    
201            /**
202             * @deprecated
203             */
204            public static void add(
205                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
206                    float text) {
207    
208                    add(element, name, namespace, String.valueOf(text));
209            }
210    
211            /**
212             * @deprecated
213             */
214            public static void add(
215                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
216                    int text) {
217    
218                    add(element, name, namespace, String.valueOf(text));
219            }
220    
221            /**
222             * @deprecated
223             */
224            public static void add(
225                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
226                    long text) {
227    
228                    add(element, name, namespace, String.valueOf(text));
229            }
230    
231            /**
232             * @deprecated
233             */
234            public static void add(
235                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
236                    Object text) {
237    
238                    add(element, name, namespace, String.valueOf(text));
239            }
240    
241            /**
242             * @deprecated
243             */
244            public static void add(
245                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
246                    short text) {
247    
248                    add(element, name, namespace, String.valueOf(text));
249            }
250    
251            /**
252             * @deprecated
253             */
254            public static void add(
255                    org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
256                    String text) {
257    
258                    org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
259    
260                    org.dom4j.Element childElement = element.addElement(qName);
261    
262                    childElement.addText(GetterUtil.getString(text));
263            }
264    
265            /**
266             * @deprecated
267             */
268            public static void add(org.dom4j.Element element, String name, short text) {
269                    add(element, name, String.valueOf(text));
270            }
271    
272            /**
273             * @deprecated
274             */
275            public static void add(
276                    org.dom4j.Element element, String name, String text) {
277    
278                    org.dom4j.Element childElement = element.addElement(name);
279    
280                    childElement.addText(GetterUtil.getString(text));
281            }
282    
283    }