view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CacheInvalidationService.java @ 4173:7d4480c0e68e

Allow users to select the current relevant discharge table in historical discharge table calculattion. In addition to this, the discharge tables in the helper panel displayed in the client is ordered in time.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 18 Oct 2012 12:13:48 +0200
parents 5642a83420f2
children
line wrap: on
line source
package de.intevation.flys.artifacts.services;

import de.intevation.artifacts.CallMeta;
import de.intevation.artifacts.GlobalContext;

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

import de.intevation.artifactdatabase.XMLService;

import de.intevation.flys.artifacts.cache.CacheFactory;

import net.sf.ehcache.Cache;

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

public class CacheInvalidationService
extends      XMLService
{
    @Override
    public Document processXML(
        Document      data,
        GlobalContext globalContext,
        CallMeta      callMeta
    ) {
        Document result = XMLUtils.newDocument();

        Element all = result.createElement("caches");

        NodeList caches = data.getElementsByTagName("cache");

        for (int i = 0, C = caches.getLength(); i < C; ++i) {
            Element c = (Element)caches.item(i);
            String name = c.getAttribute("name");
            Element e = result.createElement("cache");
            e.setAttribute("name", name);
            Cache cache = CacheFactory.getCache(name);
            if (cache != null) {
                cache.removeAll();
                e.setTextContent("All elements removed.");
            }
            else {
                e.setTextContent("Error: Cache not found.");
            }
            all.appendChild(e);
        }

        result.appendChild(all);

        return result;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org