01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.xml.export;
18:
19: import java.util.Date;
20:
21: import org.jdom.CDATA;
22: import org.jdom.Element;
23: import org.jdom.Namespace;
24:
25: import edu.iu.uis.eden.EdenConstants;
26:
27: /**
28: * A helper class which helps with building the XML for export.
29: *
30: * @author ewestfal
31: */
32: public class ExportRenderer {
33:
34: private Namespace namespace;
35:
36: public ExportRenderer(Namespace namespace) {
37: this .namespace = namespace;
38: }
39:
40: public Element renderElement(Element parent, String elementName) {
41: Element element = new Element(elementName, namespace);
42: if (parent != null) {
43: parent.addContent(element);
44: }
45: return element;
46: }
47:
48: public Element renderTextElement(Element parent,
49: 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,
59: String elementName, Boolean bool, boolean defaultValue) {
60: if (bool == null) {
61: bool = new Boolean(defaultValue);
62: }
63: return renderTextElement(parent, elementName, (bool
64: .booleanValue() ? "true" : "false"));
65: }
66:
67: public Element renderDateElement(Element parent,
68: String elementName, Date date) {
69: Element element = null;
70: if (date != null) {
71: element = renderTextElement(parent, elementName,
72: EdenConstants.getDefaultDateFormat().format(date));
73: }
74: return element;
75: }
76:
77: public void renderAttribute(Element element, String attributeName,
78: String attributeValue) {
79: element.setAttribute(attributeName, attributeValue);
80: }
81:
82: public Element renderCDATAElement(Element parent,
83: String elementName, String data) {
84: Element element = null;
85: if (data != null) {
86: element = renderElement(parent, elementName);
87: element.addContent(new CDATA(data));
88: }
89: return element;
90: }
91:
92: }
|