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