01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.util.xml;
11:
12: import java.util.*;
13: import java.util.Map.Entry;
14:
15: import org.mmbase.module.Module;
16: import org.mmbase.util.XMLEntityResolver;
17:
18: import org.w3c.dom.*;
19:
20: /**
21: * @author Daniel Ockeloen
22: * @version $Id: ModuleWriter.java,v 1.9 2007/02/24 21:57:50 nklasens Exp $
23: */
24: public class ModuleWriter extends DocumentWriter {
25:
26: /**
27: * Hold a reference to the module for which to create an XML document.
28: */
29: protected Module module;
30:
31: /**
32: * Constructs the document writer.
33: * The constructor calls its super to create a basic document, based on the module document type.
34: * @param module the module for which to create an XML document.
35: */
36: public ModuleWriter(Module module) throws DOMException {
37: super ("module", ModuleReader.PUBLIC_ID_MODULE,
38: XMLEntityResolver.DOMAIN
39: + XMLEntityResolver.DTD_SUBPATH
40: + ModuleReader.DTD_MODULE);
41: this .module = module;
42: getMessageRetriever("org.mmbase.util.xml.resources.modulewriter");
43: }
44:
45: /**
46: * Generates the document. Can only be called once.
47: * @throws DOMException when an error occurred during generation
48: */
49: protected void generate() throws DOMException {
50: Element root = document.getDocumentElement();
51: addComment("module.configuration", module.getName(), module
52: .getModuleInfo(), root);
53: root.setAttribute("maintainer", module.getMaintainer());
54: root.setAttribute("version", "" + module.getVersion());
55: // status
56: addComment("module.status", root);
57: addContentElement("status", "active", root);
58: // classfile
59: addComment("module.classfile", root);
60: addContentElement("classfile", module.getClass().getName(),
61: root);
62: // properties
63: Element properties = document.createElement("properties");
64: addComment("module.properties", root);
65: root.appendChild(properties);
66: // properties.property
67: Map<String, String> datamap = module.getInitParameters();
68: for (Entry<String, String> entry : datamap.entrySet()) {
69: String propname = entry.getKey();
70: String propvalue = entry.getValue();
71: Element elm = addContentElement("property", propvalue,
72: properties);
73: elm.setAttribute("name", propname);
74: }
75: }
76: }
|