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