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 org.kuali.workflow.workgroup;
18:
19: import java.util.List;
20:
21: import org.apache.commons.lang.StringUtils;
22: import org.jdom.Element;
23:
24: import edu.iu.uis.eden.export.ExportDataSet;
25: import edu.iu.uis.eden.xml.XmlConstants;
26: import edu.iu.uis.eden.xml.export.ExportRenderer;
27: import edu.iu.uis.eden.xml.export.XmlExporter;
28:
29: /**
30: * Exports {@link WorkgroupType}s to XML.
31: *
32: * @see WorkgroupType
33: *
34: * @author ewestfal
35: */
36: public class WorkgroupTypeXmlExporter implements XmlExporter,
37: XmlConstants {
38:
39: protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
40: .getLogger(getClass());
41:
42: private ExportRenderer renderer = new ExportRenderer(
43: WORKGROUP_TYPE_NAMESPACE);
44:
45: public Element export(ExportDataSet dataSet) {
46: if (!dataSet.getWorkgroupTypes().isEmpty()) {
47: Element rootElement = renderer.renderElement(null,
48: WORKGROUP_TYPES);
49: rootElement.setAttribute(SCHEMA_LOCATION_ATTR,
50: WORKGROUP_TYPE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
51: for (WorkgroupType workgroupType : dataSet
52: .getWorkgroupTypes()) {
53: exportWorkgroupType(rootElement, workgroupType);
54: }
55: return rootElement;
56: }
57: return null;
58: }
59:
60: private void exportWorkgroupType(Element parent,
61: WorkgroupType workgroupType) {
62: Element workgroupTypeElement = renderer.renderElement(parent,
63: WORKGROUP_TYPE);
64: renderer.renderTextElement(workgroupTypeElement, NAME,
65: workgroupType.getName());
66: renderer.renderTextElement(workgroupTypeElement, LABEL,
67: workgroupType.getLabel());
68: if (!StringUtils.isBlank(workgroupType.getDescription())) {
69: renderer.renderTextElement(workgroupTypeElement,
70: DESCRIPTION, workgroupType.getDescription());
71: }
72: if (!StringUtils.isBlank(workgroupType.getDocumentTypeName())) {
73: renderer.renderTextElement(workgroupTypeElement,
74: DOCUMENT_TYPE, workgroupType.getDocumentTypeName());
75: }
76:
77: exportAttributes(workgroupTypeElement, workgroupType
78: .getActiveAttributes());
79: }
80:
81: private void exportAttributes(Element parent,
82: List<WorkgroupTypeAttribute> workgroupTypeAttributes) {
83: if (!workgroupTypeAttributes.isEmpty()) {
84: Element attributesElement = renderer.renderElement(parent,
85: ATTRIBUTES);
86: for (WorkgroupTypeAttribute attribute : workgroupTypeAttributes) {
87: Element attributeElement = renderer.renderElement(
88: attributesElement, ATTRIBUTE);
89: renderer.renderTextElement(attributeElement, NAME,
90: attribute.getAttribute().getName());
91: }
92: }
93: }
94:
95: }
|