view gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java @ 1022:28a0628b11b0

Added license file and license header. gnv/trunk@1258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:15:08 +0000
parents 902d4de27c37
children e887763a37e2
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.action.mapviewer;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

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

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import de.intevation.gnv.action.ArtifactDatabaseActionBase;
import de.intevation.gnv.action.mapviewer.parser.ExternalCallParser;
import de.intevation.gnv.action.mapviewer.parser.XMLExternalCallParser;
import de.intevation.gnv.action.sessionmodel.SessionModel;
import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
import de.intevation.gnv.artifactdatabase.objects.map.MapService;

/**
 * This class provides the businesslogic for handling an 
 * MV-GNV-Interface-call.
 * This call can be done in two ways.
 * First is to put the requestbody into the body of the http-post-request.
 * Second to put the requestbody to the parameter "document" of the
 * http-post-request.
 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
 */
public class MapViewerCallAction extends ArtifactDatabaseActionBase {

    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(MapViewerCallAction.class);

    /**
     * Constructor
     */
    public MapViewerCallAction() {
        super();
    }

    /**
     * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {
        log.debug("MapViewerCallAction.execute");
        InputStream inputStream = null;
        String documentvalue = request.getParameter("document");
        if (documentvalue != null){
            documentvalue = documentvalue.trim();
            inputStream = new ByteArrayInputStream(documentvalue.getBytes());
        }else{
            inputStream = request.getInputStream();
        }

        if (inputStream != null){
            try {
                ExternalCallParser ecp = new XMLExternalCallParser(inputStream);
                ecp.parse();
                String geometry = ecp.getGeometry();
                String srs = ecp.getSRS();
                Collection<MapService> mapServices = ecp.getMapServices();

                Collection<ArtifactObject> availableFactories =
                       ArtifactDatabaseClientFactory
                          .getInstance()
                          .getArtifactDatabaseClient(getLocale(request))
                          .getArtifactFactoryMetaInformation(mapServices,
                                                             geometry,
                                                             srs);

                Collection<ArtifactObject> providedFactories =
                        ArtifactDatabaseClientFactory
                           .getInstance()
                           .getArtifactDatabaseClient(getLocale(request))
                           .getArtifactFactories();

                // Sort out which ArtifactFactories should not be used.
                Collection<ArtifactObject> usedFactories =
                       new ArrayList<ArtifactObject>(availableFactories.size());

                Iterator<ArtifactObject> it = availableFactories.iterator();
                while (it.hasNext()){
                    ArtifactObject ao = it.next();
                    if (providedFactories.contains(ao)){
                        usedFactories.add(ao);
                    }
                }

                SessionModel sm = SessionModelFactory
                                     .getInstance()
                                     .getSessionModel(request);
                sm.resetModel();
                sm.setArtifacteFactories(usedFactories);
            } catch (Exception e) {
                log.error(e,e);
            }
        }else{
            log.error("Kein Anfragedokument übergeben.");
        }
        return super.execute(mapping, form, request, response);
    }

}

http://dive4elements.wald.intevation.org