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.Iterator;
20:
21: import org.jdom.Element;
22:
23: import edu.iu.uis.eden.export.ExportDataSet;
24: import edu.iu.uis.eden.help.HelpEntry;
25: import edu.iu.uis.eden.xml.XmlConstants;
26:
27: /**
28: * Exports {@link HelpEntry}s to XML.
29: *
30: * @see HelpEntry
31: *
32: * @author shenl
33: */
34: public class HelpEntryXmlExporter implements XmlExporter, XmlConstants {
35:
36: protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
37: .getLogger(getClass());
38:
39: private ExportRenderer renderer = new ExportRenderer(HELP_NAMESPACE);
40:
41: public Element export(ExportDataSet dataSet) {
42: if (!dataSet.getHelp().isEmpty()) {
43: Element rootElement = renderer.renderElement(null,
44: HELP_ENTRIES);
45: rootElement.setAttribute(SCHEMA_LOCATION_ATTR,
46: HELP_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
47: for (Iterator iterator = dataSet.getHelp().iterator(); iterator
48: .hasNext();) {
49: HelpEntry helpEntry = (HelpEntry) iterator.next();
50: exportHelpEntry(rootElement, helpEntry);
51: }
52: return rootElement;
53: }
54: return null;
55: }
56:
57: private void exportHelpEntry(Element parent, HelpEntry helpEntry) {
58: Element helpElement = renderer
59: .renderElement(parent, HELP_ENTRY);
60: renderer.renderTextElement(helpElement, HELP_NAME, helpEntry
61: .getHelpName());
62: renderer.renderTextElement(helpElement, HELP_KEY, helpEntry
63: .getHelpKey());
64: renderer.renderCDATAElement(helpElement, HELP_TEXT, helpEntry
65: .getHelpText());
66: }
67:
68: }
|