2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
23 package com.pentila.entSavoie.cahierDeTexte.action;
\r
25 import java.io.InputStream;
\r
26 import java.util.Map;
\r
28 import javax.portlet.ActionRequest;
\r
29 import javax.portlet.ActionResponse;
\r
30 import javax.portlet.PortletConfig;
\r
31 import javax.servlet.http.HttpServletRequest;
\r
32 import javax.servlet.http.HttpServletResponse;
\r
34 import org.apache.struts.action.ActionForm;
\r
35 import org.apache.struts.action.ActionForward;
\r
36 import org.apache.struts.action.ActionMapping;
\r
38 import com.liferay.portal.kernel.util.ParamUtil;
\r
39 import com.liferay.portal.struts.ActionConstants;
\r
40 import com.liferay.portal.struts.PortletAction;
\r
41 import com.liferay.portal.util.PortalUtil;
\r
42 import com.liferay.portlet.documentlibrary.conversion.util.ENTDocumentConversionServiceUtil;
\r
43 import com.pentila.entSavoie.servlet.FLVPseudoStreamer;
\r
44 import com.pentila.entSavoie.servlet.ServletResponseServiceUtil;
\r
45 import com.pentila.entSavoie.utils.URIFormat;
\r
48 * <a href="GetMessageAttachmentAction.java.html"><b><i>View Source</i></b></a>
\r
50 * @author Brian Wing Shun Chan
\r
53 public class GetEventCDTAttachmentAction extends PortletAction {
\r
55 public ActionForward strutsExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
\r
58 long evtId = ParamUtil.getLong(request, "evtId");
\r
59 long companyId = ParamUtil.getLong(request, "companyId");
\r
60 String fileName = ParamUtil.getString(request, "attachment");
\r
62 fileName = URIFormat.decodeURIComponent(fileName);
\r
64 //on recupere le targetExtension
\r
65 String targetExtension = ParamUtil.getString(request, "targetExtension", "");
\r
67 getFile(evtId, companyId, fileName, targetExtension, response, request);
\r
71 catch (Exception e) {
\r
72 PortalUtil.sendError(e, request, response);
\r
78 public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
\r
81 long evtId = ParamUtil.getLong(actionRequest, "evtId");
\r
82 long companyId = ParamUtil.getLong(actionRequest, "companyId");
\r
83 String fileName = ParamUtil.getString(actionRequest, "attachment");
\r
85 fileName = URIFormat.decodeURIComponent(fileName);
\r
87 //on recupere le targetExtension
\r
88 String targetExtension = ParamUtil.getString(actionRequest, "targetExtension", "");
\r
90 HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
\r
91 HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
\r
93 getFile(evtId, companyId, fileName, targetExtension, response, request);
\r
95 setForward(actionRequest, ActionConstants.COMMON_NULL);
\r
97 catch (Exception e) {
\r
98 PortalUtil.sendError(e, actionRequest, actionResponse);
\r
102 protected void getFile(long evtId, long companyId, String fileName, String targetExtension, HttpServletResponse response, HttpServletRequest request) throws Exception {
\r
104 InputStream is = null;
\r
106 String path = "cahierdetexte/" + evtId + "/" + fileName;
\r
108 // réalise la conversion du fichier ou nous retourne celui-ci si pas de conversion voulu
\r
109 Map<String, Object> fais = ENTDocumentConversionServiceUtil.getFileAsInputStream(
\r
115 String contentType = (String)fais.get("contentType");
\r
116 int contentLength = (Integer)fais.get("contentLength");
\r
117 fileName = (String)fais.get("fileName");
\r
118 is = (InputStream)fais.get("stream");
\r
120 String ppos = request.getParameter("start");
\r
121 long pos = ppos == null || ppos.length() == 0 ? 0 : Long.parseLong(ppos);
\r
123 String forceContentDisposition = ParamUtil.getString(request, "contentDispo");
\r
124 String fcd = forceContentDisposition == null ? "" : forceContentDisposition;
\r
126 if (pos!=0 && contentType.equals("application/x-shockwave-flash") && fcd.isEmpty()) {
\r
127 FLVPseudoStreamer flvPseudoStreamer = new FLVPseudoStreamer();
\r
128 flvPseudoStreamer.service(request, response, fileName, is, contentLength, contentType);
\r
131 ServletResponseServiceUtil.sendFile(
\r
132 response, fileName, is, contentLength, contentType, fcd);
\r
143 protected boolean isCheckMethodOnProcessAction() {
\r
144 return _CHECK_METHOD_ON_PROCESS_ACTION;
\r
147 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
\r