1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.core.util.xml;
18
19 import java.util.Date;
20
21 import org.jdom.CDATA;
22 import org.jdom.Element;
23 import org.jdom.Namespace;
24 import org.kuali.rice.core.util.RiceConstants;
25
26
27
28
29
30
31 public class XmlRenderer {
32
33 private Namespace namespace;
34
35 public XmlRenderer() {}
36
37 public XmlRenderer(Namespace namespace) {
38 this.namespace = namespace;
39 }
40
41 public Element renderElement(Element parent, String elementName) {
42 Element element = new Element(elementName, namespace);
43 if (parent != null) {
44 parent.addContent(element);
45 }
46 return element;
47 }
48
49 public Element renderTextElement(Element parent, String elementName, String text) {
50 Element element = null;
51 if (text != null) {
52 element = renderElement(parent, elementName);
53 element.setText(text);
54 }
55 return element;
56 }
57
58 public Element renderBooleanElement(Element parent, String elementName, Boolean bool, boolean defaultValue) {
59 if (bool == null) {
60 bool = new Boolean(defaultValue);
61 }
62 return renderTextElement(parent, elementName, (bool.booleanValue() ? "true" : "false"));
63 }
64
65 public Element renderDateElement(Element parent, String elementName, Date date) {
66 Element element = null;
67 if (date != null) {
68 element = renderTextElement(parent, elementName, RiceConstants.getDefaultDateFormat().format(date));
69 }
70 return element;
71 }
72
73 public void renderAttribute(Element element, String attributeName, String attributeValue) {
74 element.setAttribute(attributeName, attributeValue);
75 }
76
77 public Element renderCDATAElement(Element parent, String elementName, String data) {
78 Element element = null;
79 if (data != null) {
80 element = renderElement(parent, elementName);
81 element.addContent(new CDATA(data));
82 }
83 return element;
84 }
85
86 }