All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.config.persister.tools.PropertiesPersister Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.framework.config.persister.tools;

import net.n2oapp.framework.api.metadata.persister.AbstractSimpleElementPersister;
import net.n2oapp.framework.config.persister.util.PersisterJdomUtil;
import org.jdom2.Element;
import org.jdom2.Namespace;

import java.util.Map;

/**
 * User: operhod
 * Date: 30.01.14
 * Time: 15:29
 */
public class PropertiesPersister extends AbstractSimpleElementPersister> {

    public PropertiesPersister(Namespace namespace) {
        super(namespace);
    }


    @Override
    public Element persist(Map properties, Namespace namespace) {
        Element element = new Element("properties", getNamespace());
        for (Map.Entry entry : properties.entrySet()) {
            persist(entry, element);
        }
        return element;
    }

    private void persist(Map.Entry entry, Element parent) {
        Element element = new Element("property", getNamespace());
        PersisterJdomUtil.setAttribute(element, "key", entry.getKey());
        PersisterJdomUtil.setAttribute(element, "value", entry.getValue() != null ? entry.getValue().toString() : null);
        parent.addContent(element);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy