001    /**
002     * Copyright (c) 2000-2013 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     * @author Alexander Chow
026     */
027    public class DocUtil {
028    
029            public static Element add(Element element, QName qName) {
030                    return element.addElement(qName);
031            }
032    
033            public static Element add(Element element, QName qName, boolean text) {
034                    return add(element, qName, String.valueOf(text));
035            }
036    
037            public static Element add(Element element, QName qName, double text) {
038                    return add(element, qName, String.valueOf(text));
039            }
040    
041            public static Element add(Element element, QName qName, float text) {
042                    return add(element, qName, String.valueOf(text));
043            }
044    
045            public static Element add(Element element, QName qName, int text) {
046                    return add(element, qName, String.valueOf(text));
047            }
048    
049            public static Element add(Element element, QName qName, long text) {
050                    return add(element, qName, String.valueOf(text));
051            }
052    
053            public static Element add(Element element, QName qName, Object text) {
054                    return add(element, qName, String.valueOf(text));
055            }
056    
057            public static Element add(Element element, QName qName, short text) {
058                    return add(element, qName, String.valueOf(text));
059            }
060    
061            public static Element add(Element element, QName qName, String text) {
062                    Element childElement = element.addElement(qName);
063    
064                    childElement.addText(GetterUtil.getString(text));
065    
066                    return childElement;
067            }
068    
069            public static Element add(Element element, String name, boolean text) {
070                    return add(element, name, String.valueOf(text));
071            }
072    
073            public static Element add(Element element, String name, double text) {
074                    return add(element, name, String.valueOf(text));
075            }
076    
077            public static Element add(Element element, String name, float text) {
078                    return add(element, name, String.valueOf(text));
079            }
080    
081            public static Element add(Element element, String name, int text) {
082                    return add(element, name, String.valueOf(text));
083            }
084    
085            public static Element add(Element element, String name, long text) {
086                    return add(element, name, String.valueOf(text));
087            }
088    
089            public static Element add(
090                    Element element, String name, Namespace namespace) {
091    
092                    QName qName = SAXReaderUtil.createQName(name, namespace);
093    
094                    return element.addElement(qName);
095            }
096    
097            public static Element add(
098                    Element element, String name, Namespace namespace, boolean text) {
099    
100                    return add(element, name, namespace, String.valueOf(text));
101            }
102    
103            public static Element add(
104                    Element element, String name, Namespace namespace, double text) {
105    
106                    return add(element, name, namespace, String.valueOf(text));
107            }
108    
109            public static Element add(
110                    Element element, String name, Namespace namespace, float text) {
111    
112                    return add(element, name, namespace, String.valueOf(text));
113            }
114    
115            public static Element add(
116                    Element element, String name, Namespace namespace, int text) {
117    
118                    return add(element, name, namespace, String.valueOf(text));
119            }
120    
121            public static Element add(
122                    Element element, String name, Namespace namespace, long text) {
123    
124                    return add(element, name, namespace, String.valueOf(text));
125            }
126    
127            public static Element add(
128                    Element element, String name, Namespace namespace, Object text) {
129    
130                    return add(element, name, namespace, String.valueOf(text));
131            }
132    
133            public static Element add(
134                    Element element, String name, Namespace namespace, short text) {
135    
136                    return add(element, name, namespace, String.valueOf(text));
137            }
138    
139            public static Element add(
140                    Element element, String name, Namespace namespace, String text) {
141    
142                    QName qName = SAXReaderUtil.createQName(name, namespace);
143    
144                    return add(element, qName, text);
145            }
146    
147            public static Element add(Element element, String name, Object text) {
148                    return add(element, name, String.valueOf(text));
149            }
150    
151            public static Element add(Element element, String name, short text) {
152                    return add(element, name, String.valueOf(text));
153            }
154    
155            public static Element add(Element element, String name, String text) {
156                    Element childElement = element.addElement(name);
157    
158                    childElement.addText(GetterUtil.getString(text));
159    
160                    return childElement;
161            }
162    
163    }