1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.util.xml;
21  
22  import com.liferay.portal.kernel.util.GetterUtil;
23  import com.liferay.portal.kernel.xml.Element;
24  import com.liferay.portal.kernel.xml.Namespace;
25  import com.liferay.portal.kernel.xml.QName;
26  import com.liferay.portal.kernel.xml.SAXReaderUtil;
27  
28  /**
29   * <a href="DocUtil.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   *
33   */
34  public class DocUtil {
35  
36      public static void add(Element element, String name, boolean text) {
37          add(element, name, String.valueOf(text));
38      }
39  
40      public static void add(Element element, String name, double text) {
41          add(element, name, String.valueOf(text));
42      }
43  
44      public static void add(Element element, String name, float text) {
45          add(element, name, String.valueOf(text));
46      }
47  
48      public static void add(Element element, String name, int text) {
49          add(element, name, String.valueOf(text));
50      }
51  
52      public static void add(Element element, String name, long text) {
53          add(element, name, String.valueOf(text));
54      }
55  
56      public static void add(Element element, String name, short text) {
57          add(element, name, String.valueOf(text));
58      }
59  
60      public static void add(Element element, String name, Object text) {
61          add(element, name, String.valueOf(text));
62      }
63  
64      public static void add(Element element, String name, String text) {
65          Element childElement = element.addElement(name);
66  
67          childElement.addText(GetterUtil.getString(text));
68      }
69  
70      public static Element add(
71          Element element, String name, Namespace namespace) {
72  
73          QName qName = SAXReaderUtil.createQName(name, namespace);
74  
75          return element.addElement(qName);
76      }
77  
78      public static void add(
79          Element element, String name, Namespace namespace, boolean text) {
80  
81          add(element, name, namespace, String.valueOf(text));
82      }
83  
84      public static void add(
85          Element element, String name, Namespace namespace, double text) {
86  
87          add(element, name, namespace, String.valueOf(text));
88      }
89  
90      public static void add(
91          Element element, String name, Namespace namespace, float text) {
92  
93          add(element, name, namespace, String.valueOf(text));
94      }
95  
96      public static void add(
97          Element element, String name, Namespace namespace, int text) {
98  
99          add(element, name, namespace, String.valueOf(text));
100     }
101 
102     public static void add(
103         Element element, String name, Namespace namespace, long text) {
104 
105         add(element, name, namespace, String.valueOf(text));
106     }
107 
108     public static void add(
109         Element element, String name, Namespace namespace, short text) {
110 
111         add(element, name, namespace, String.valueOf(text));
112     }
113 
114     public static void add(
115         Element element, String name, Namespace namespace, Object text) {
116 
117         add(element, name, namespace, String.valueOf(text));
118     }
119 
120     public static void add(
121         Element element, String name, Namespace namespace, String text) {
122 
123         QName qName = SAXReaderUtil.createQName(name, namespace);
124 
125         Element childElement = element.addElement(qName);
126 
127         childElement.addText(GetterUtil.getString(text));
128     }
129 
130     /**
131      * @deprecated
132      */
133     public static void add(
134         org.dom4j.Element element, String name, boolean text) {
135 
136         add(element, name, String.valueOf(text));
137     }
138 
139     /**
140      * @deprecated
141      */
142     public static void add(
143         org.dom4j.Element element, String name, double text) {
144 
145         add(element, name, String.valueOf(text));
146     }
147 
148     /**
149      * @deprecated
150      */
151     public static void add(org.dom4j.Element element, String name, float text) {
152         add(element, name, String.valueOf(text));
153     }
154 
155     /**
156      * @deprecated
157      */
158     public static void add(org.dom4j.Element element, String name, int text) {
159         add(element, name, String.valueOf(text));
160     }
161 
162     /**
163      * @deprecated
164      */
165     public static void add(org.dom4j.Element element, String name, long text) {
166         add(element, name, String.valueOf(text));
167     }
168 
169     /**
170      * @deprecated
171      */
172     public static void add(org.dom4j.Element element, String name, short text) {
173         add(element, name, String.valueOf(text));
174     }
175 
176     /**
177      * @deprecated
178      */
179     public static void add(
180         org.dom4j.Element element, String name, Object text) {
181 
182         add(element, name, String.valueOf(text));
183     }
184 
185     /**
186      * @deprecated
187      */
188     public static void add(
189         org.dom4j.Element element, String name, String text) {
190 
191         org.dom4j.Element childElement = element.addElement(name);
192 
193         childElement.addText(GetterUtil.getString(text));
194     }
195 
196     /**
197      * @deprecated
198      */
199     public static org.dom4j.Element add(
200         org.dom4j.Element element, String name, org.dom4j.Namespace namespace) {
201 
202         org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
203 
204         return element.addElement(qName);
205     }
206 
207     /**
208      * @deprecated
209      */
210     public static void add(
211         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
212         boolean text) {
213 
214         add(element, name, namespace, String.valueOf(text));
215     }
216 
217     /**
218      * @deprecated
219      */
220     public static void add(
221         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
222         double text) {
223 
224         add(element, name, namespace, String.valueOf(text));
225     }
226 
227     /**
228      * @deprecated
229      */
230     public static void add(
231         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
232         float text) {
233 
234         add(element, name, namespace, String.valueOf(text));
235     }
236 
237     /**
238      * @deprecated
239      */
240     public static void add(
241         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
242         int text) {
243 
244         add(element, name, namespace, String.valueOf(text));
245     }
246 
247     /**
248      * @deprecated
249      */
250     public static void add(
251         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
252         long text) {
253 
254         add(element, name, namespace, String.valueOf(text));
255     }
256 
257     /**
258      * @deprecated
259      */
260     public static void add(
261         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
262         short text) {
263 
264         add(element, name, namespace, String.valueOf(text));
265     }
266 
267     /**
268      * @deprecated
269      */
270     public static void add(
271         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
272         Object text) {
273 
274         add(element, name, namespace, String.valueOf(text));
275     }
276 
277     /**
278      * @deprecated
279      */
280     public static void add(
281         org.dom4j.Element element, String name, org.dom4j.Namespace namespace,
282         String text) {
283 
284         org.dom4j.QName qName = new org.dom4j.QName(name, namespace);
285 
286         org.dom4j.Element childElement = element.addElement(qName);
287 
288         childElement.addText(GetterUtil.getString(text));
289     }
290 
291 }