view artifacts/src/main/java/org/dive4elements/river/artifacts/services/ServerInfoService.java @ 7471:fff862f4ef76

Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time. Hopefully this improves the overall speed of loading data from the datacage.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Oct 2013 15:26:21 +0100
parents d30ae7275e5a
children e4606eae8ea5
line wrap: on
line source
package org.dive4elements.river.artifacts.services;

import javax.xml.xpath.XPathConstants;

import org.apache.log4j.Logger;
import org.dive4elements.artifacts.CallMeta;
import org.dive4elements.artifacts.GlobalContext;
import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
import org.dive4elements.artifacts.common.utils.Config;
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * Through this service the client can retrieve basic information about or
 * configuration of the artifact server.
 * Currently it only returns the help-url (wiki) to the client.
 *
 * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a>
 */
public class ServerInfoService extends D4EService {

    /** The logger used in this service.*/
    private static Logger logger = Logger.getLogger(ServerInfoService.class);

    private static final String XPATH_HELP_URL = "/artifact-database/help-url/text()";

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

        Document result = XMLUtils.newDocument();

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

        Element serverInfo = ec.create("server");

        String helpUrl = (String) XMLUtils.xpath(
                Config.getConfig(),
                XPATH_HELP_URL,
                XPathConstants.STRING);

        Element info = ec.create("info");
        ec.addAttr(info, "key", "help-url", true);
        ec.addAttr(info, "value", helpUrl, true);
        serverInfo.appendChild(info);

        result.appendChild(serverInfo);

        return result;
    }

}

http://dive4elements.wald.intevation.org