view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/ModuleService.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents 28be160b5870
children
line wrap: on
line source
package de.intevation.flys.artifacts.services;

import java.util.List;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.artifacts.CallMeta;
import de.intevation.artifacts.GlobalContext;
import de.intevation.artifacts.ArtifactNamespaceContext;
import de.intevation.flys.artifacts.model.Module;
import de.intevation.flys.artifacts.context.FLYSContext;
import de.intevation.flys.artifacts.resources.Resources;

public class ModuleService extends FLYSService {

    private static final String MODULE = "module";

    private static Logger logger = Logger.getLogger(ModuleService.class);

    protected Document doProcess(
        Document      data,
        GlobalContext globalContext,
        CallMeta      callMeta
    ) {
        logger.debug("ModuleService.process");

        Document result = XMLUtils.newDocument();

        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
            result,
            ArtifactNamespaceContext.NAMESPACE_URI,
            ArtifactNamespaceContext.NAMESPACE_PREFIX);

        Element em = ec.create("modules");
        List<Module> modules = (List<Module>)globalContext.get(FLYSContext.MODULES);

        for (Module module : modules) {
            Element m = ec.create("module");
            ec.addAttr(m, "name", module.getName(), true);
            String localname = Resources.getMsg(callMeta,
                    MODULE + "." + module.getName(), module.getName());
            ec.addAttr(m, "localname", localname, true);

            if (module.isSelected()) {
                ec.addAttr(m, "selected", "true", true);
            }

            em.appendChild(m);
        }

        result.appendChild(em);

        return result;
    }
}

// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80:

http://dive4elements.wald.intevation.org