Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java @ 562:4df3347d6d1d
Removed trailing and leading Whitespaces from the Parametervalue which
contains the XML-Document to avoid XML-Parsingerrors.
gnv/trunk@668 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 09 Feb 2010 13:09:45 +0000 |
parents | df78178e1180 |
children | a634d5ee961d |
line wrap: on
line source
/** * */ package de.intevation.gnv.action; import de.intevation.gnv.action.sessionmodel.SessionModel; import de.intevation.gnv.action.sessionmodel.SessionModelFactory; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter; import de.intevation.gnv.artifactdatabase.objects.InputParameter; import de.intevation.gnv.artifactdatabase.objects.OutputMode; import de.intevation.gnv.artifactdatabase.objects.OutputParameter; import java.io.OutputStream; 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; /** * @author Tim Englich <tim.englich@intevation.de> * */ public class DoOutputAction extends ArtifactDatabaseActionBase { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(DoOutputAction.class); /** * Constructor */ public DoOutputAction() { 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("DoOutputAction.execute"); try { String target = request.getParameter("target"); String mimeType = request.getParameter("mimetype"); log.debug("Target: " + target); log.debug("MimeType: " + mimeType); // TODO Check if is propper; SessionModel sm = SessionModelFactory.getInstance() .getSessionModel(request); OutputMode outputMode = sm.getOutputMode(target); if (outputMode != null && outputMode.getMimeType().equals(mimeType)) { Collection<OutputParameter> inputParameter = outputMode .getOutputParameters(); Collection<InputParameter> ips = null; if (inputParameter != null) { ips = new ArrayList<InputParameter>(inputParameter.size()); Iterator<OutputParameter> it = inputParameter.iterator(); while (it.hasNext()) { String name = it.next().getName(); String[] values = request.getParameterValues(name); InputParameter ip = new DefaultInputParameter(name, values); ips.add(ip); } } ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory .getInstance() .getArtifactDatabaseClient(getLocale(request)); this.setHeaders(target, mimeType, response, request); OutputStream outputStream = response.getOutputStream(); adc.doOutput(sm.getSelectedArtifactFactory(), sm .getCurrentArtifact(), outputStream, target, mimeType, ips); outputStream.flush(); outputStream.close(); } else { if (outputMode == null) { log.error("Outputmode is not supported."); } else if (!outputMode.getMimeType().equals(mimeType)) { log.error("MimeType " + mimeType + " wis not supported."); } // TODO FIXME: Fehlerbehandlung } return super.execute(mapping, form, request, response); } catch (Exception e) { log.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e .getMessage()); return super.getExceptionForward(mapping); } } protected void setHeaders(String target, String mimeType, HttpServletResponse response, HttpServletRequest request) { response.setHeader("Content-Type", mimeType); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :