view flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java @ 5622:b28a6d05e969

Add a new mechanism in mapfish print call to add arbitary data maps Data properties are identified by starting with mapfish-data and they are then split in info value pairs where info can be the description of the information and value the value of the information to be transported in the data map.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 09 Apr 2013 19:04:32 +0200
parents bc06a671ef60
children
line wrap: on
line source
package de.intevation.flys.client.server;

import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

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

import org.apache.log4j.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
import de.intevation.artifacts.httpclient.http.HttpClient;
import de.intevation.artifacts.httpclient.http.HttpClientImpl;
import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DistanceInfoXML
extends      HttpServlet
{
    private static final Logger logger = Logger.getLogger(DistanceInfoXML.class);


    public static final String ERROR_NO_DISTANCEINFO_FOUND =
        "error_no_distanceinfo_found";


    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        logger.info("DistanceInfoXML.doGet");

        String url  = getServletContext().getInitParameter("server-url");

        String river  = req.getParameter("river");
        String filter = req.getParameter("filter");

        Document doc = XMLUtils.newDocument();

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

        Element riverEl = ec.create("river");
        riverEl.setTextContent(river);

        doc.appendChild(riverEl);

        if (filter != null && filter.length() > 0) {
            Element typeEl = ec.create("filter");
            typeEl.setTextContent(filter);

            riverEl.appendChild(typeEl);
        }

        HttpClient client = new HttpClientImpl(url);

        try {
            InputStream in = (InputStream) client.callService(
                url, "distanceinfo", doc, new StreamResponseHandler());

            OutputStream out = resp.getOutputStream();

            byte[] b = new byte[4096];
            int i;
            while ((i = in.read(b)) >= 0) {
                out.write(b, 0, i);
            }

            out.flush();
            out.close();
        }
        catch (ConnectionException ce) {
            logger.error(ce, ce);
        }
        catch (IOException ioe) {
            logger.error(ioe, ioe);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org