teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.themes;
ingo@340:
ingo@340: import java.util.HashMap;
ingo@340: import java.util.Map;
ingo@340:
ingo@340: import org.w3c.dom.Document;
ingo@340: import org.w3c.dom.Element;
ingo@340:
teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils;
teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
ingo@340:
ingo@340:
ingo@340: /**
ingo@340: * @author Ingo Weinzierl
ingo@340: */
ingo@340: public class DefaultThemeField implements ThemeField {
ingo@340:
ingo@340: protected String name;
ingo@340:
ingo@340: protected Map attr;
ingo@340:
ingo@340:
ingo@340: public DefaultThemeField(String name) {
ingo@340: this.name = name;
ingo@340: this.attr = new HashMap();
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public String getName() {
ingo@340: return name;
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public String getType() {
ingo@340: return (String) getAttribute("type");
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public Object getValue() {
ingo@340: return getAttribute("value");
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public void setValue(Object value) {
ingo@340: setAttribute("value", value);
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public Object getAttribute(String name) {
ingo@340: return attr.get(name);
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public void setAttribute(String name, Object value) {
ingo@340: if (name == null || value == null) {
ingo@340: return;
ingo@340: }
ingo@340:
ingo@340: attr.put(name, value);
ingo@340: }
ingo@340:
ingo@340:
ingo@340: public Document toXML() {
ingo@340: Document doc = XMLUtils.newDocument();
ingo@340:
ingo@340: ElementCreator cr = new ElementCreator(doc, null, null);
ingo@340:
ingo@340: Element field = cr.create("field");
ingo@340:
sascha@3731: for (Map.Entry entry: attr.entrySet()) {
sascha@3731: cr.addAttr(field, entry.getKey(), (String)entry.getValue());
ingo@340: }
ingo@340:
ingo@340: doc.appendChild(field);
ingo@340:
ingo@340: return doc;
ingo@340: }
ingo@340: }
ingo@340: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :