1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.xml;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  import com.liferay.portal.kernel.xml.Element;
19  import com.liferay.portal.kernel.xml.Namespace;
20  import com.liferay.portal.kernel.xml.QName;
21  import com.liferay.portal.kernel.xml.SAXReaderUtil;
22  
23  /**
24   * <a href="DocUtil.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class DocUtil {
29  
30      public static Element add(Element element, String name, boolean text) {
31          return add(element, name, String.valueOf(text));
32      }
33  
34      public static Element add(Element element, String name, double text) {
35          return add(element, name, String.valueOf(text));
36      }
37  
38      public static Element add(Element element, String name, float text) {
39          return add(element, name, String.valueOf(text));
40      }
41  
42      public static Element add(Element element, String name, int text) {
43          return add(element, name, String.valueOf(text));
44      }
45  
46      public static Element add(Element element, String name, long text) {
47          return add(element, name, String.valueOf(text));
48      }
49  
50      public static Element add(
51          Element element, String name, Namespace namespace) {
52  
53          QName qName = SAXReaderUtil.createQName(name, namespace);
54  
55          return element.addElement(qName);
56      }
57  
58      public static Element add(
59          Element element, String name, Namespace namespace, boolean text) {
60  
61          return add(element, name, namespace, String.valueOf(text));
62      }
63  
64      public static Element add(
65          Element element, String name, Namespace namespace, double text) {
66  
67          return add(element, name, namespace, String.valueOf(text));
68      }
69  
70      public static Element add(
71          Element element, String name, Namespace namespace, float text) {
72  
73          return add(element, name, namespace, String.valueOf(text));
74      }
75  
76      public static Element add(
77          Element element, String name, Namespace namespace, int text) {
78  
79          return add(element, name, namespace, String.valueOf(text));
80      }
81  
82      public static Element add(
83          Element element, String name, Namespace namespace, long text) {
84  
85          return add(element, name, namespace, String.valueOf(text));
86      }
87  
88      public static Element add(
89          Element element, String name, Namespace namespace, Object text) {
90  
91          return add(element, name, namespace, String.valueOf(text));
92      }
93  
94      public static Element add(
95          Element element, String name, Namespace namespace, short text) {
96  
97          return add(element, name, namespace, String.valueOf(text));
98      }
99  
100     public static Element add(
101         Element element, String name, Namespace namespace, String text) {
102 
103         QName qName = SAXReaderUtil.createQName(name, namespace);
104 
105         Element childElement = element.addElement(qName);
106 
107         childElement.addText(GetterUtil.getString(text));
108 
109         return childElement;
110     }
111 
112     public static Element add(Element element, String name, Object text) {
113         return add(element, name, String.valueOf(text));
114     }
115 
116     public static Element add(Element element, String name, short text) {
117         return add(element, name, String.valueOf(text));
118     }
119 
120     public static Element add(Element element, String name, String text) {
121         Element childElement = element.addElement(name);
122 
123         childElement.addText(GetterUtil.getString(text));
124 
125         return childElement;
126     }
127 
128 }