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.gestionPlans.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.gestionPlans.service.PlanLocalServiceUtil;
\r
44 import com.pentila.entSavoie.servlet.FLVPseudoStreamer;
\r
45 import com.pentila.entSavoie.servlet.ServletResponseServiceUtil;
\r
48 * <a href="GetBlogEntryInfosAttachmentAction.java.html"><b><i>View Source</i></b></a>
\r
50 * @author Brian Wing Shun Chan
\r
53 public class GetConditionsDeParticipationAction extends PortletAction {
\r
55 public ActionForward strutsExecute(
\r
56 ActionMapping mapping, ActionForm form, HttpServletRequest request,
\r
57 HttpServletResponse response)
\r
61 int plan = ParamUtil.getInteger(request, "plan");
\r
62 String fileName = ParamUtil.getString(request, "conditionsDeParticipationFile");
\r
63 long companyId = PortalUtil.getUser(request).getCompanyId();
\r
65 String targetExtension = ParamUtil.getString(request, "targetExtension");
\r
67 getFile(companyId, plan, fileName, targetExtension, response, request);
\r
71 catch (Exception e) {
\r
72 e.printStackTrace();
\r
73 PortalUtil.sendError(e, request, response);
\r
79 public void processAction(
\r
80 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
\r
81 ActionRequest actionRequest, ActionResponse actionResponse)
\r
85 int plan = ParamUtil.getInteger(actionRequest, "plan");
\r
86 String fileName = ParamUtil.getString(actionRequest, "conditionsDeParticipationFile");
\r
87 long companyId = PortalUtil.getUser(actionRequest).getCompanyId();
\r
89 String targetExtension = ParamUtil.getString(actionRequest, "targetExtension");
\r
91 HttpServletResponse response = PortalUtil.getHttpServletResponse(
\r
93 HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
\r
95 getFile(companyId, plan, fileName, targetExtension, response, request);
\r
97 setForward(actionRequest, ActionConstants.COMMON_NULL);
\r
99 catch (Exception e) {
\r
100 e.printStackTrace();
\r
101 PortalUtil.sendError(e, actionRequest, actionResponse);
\r
105 protected void getFile( long companyId,
\r
106 int plan, String fileName, String targetExtension, HttpServletResponse response, HttpServletRequest request)
\r
109 InputStream is = null;
\r
113 String path = PlanLocalServiceUtil.getConditionsDeParticipationDir(plan) + "/" + fileName;
\r
115 // réalise la conversion du fichier ou nous retourne celui-ci si pas de conversion voulu
\r
116 Map<String, Object> fais = ENTDocumentConversionServiceUtil.getFileAsInputStream(
\r
122 String contentType = (String)fais.get("contentType");
\r
123 int contentLength = (Integer)fais.get("contentLength");
\r
124 fileName = (String)fais.get("fileName");
\r
125 is = (InputStream)fais.get("stream");
\r
127 fileName = convertNonAscii(fileName);
\r
131 String ppos = request.getParameter("start");
\r
132 long pos = ppos == null || ppos.length() == 0 ? 0 : Long.parseLong(ppos);
\r
134 String forceContentDisposition = ParamUtil.getString(request, "contentDispo");
\r
135 String fcd = forceContentDisposition == null ? "" : forceContentDisposition;
\r
137 if (pos!=0 && contentType.equals("application/x-shockwave-flash") && fcd.isEmpty()) {
\r
138 FLVPseudoStreamer flvPseudoStreamer = new FLVPseudoStreamer();
\r
139 flvPseudoStreamer.service(request, response, fileName, is, contentLength, contentType);
\r
142 ServletResponseServiceUtil.sendFile(
\r
143 response, fileName, is, contentLength, contentType, fcd);
\r
155 private static final String PLAIN_ASCII =
\r
156 "AaEeIiOoUu" // grave
\r
157 + "AaEeIiOoUuYy" // acute
\r
158 + "AaEeIiOoUuYy" // circumflex
\r
159 + "AaOoNn" // tilde
\r
160 + "AaEeIiOoUuYy" // umlaut
\r
163 + "OoUu" // double acute
\r
166 private static final String UNICODE =
\r
167 "\u00C0\u00E0\u00C8\u00E8\u00CC\u00EC\u00D2\u00F2\u00D9\u00F9"
\r
168 + "\u00C1\u00E1\u00C9\u00E9\u00CD\u00ED\u00D3\u00F3\u00DA\u00FA\u00DD\u00FD"
\r
169 + "\u00C2\u00E2\u00CA\u00EA\u00CE\u00EE\u00D4\u00F4\u00DB\u00FB\u0176\u0177"
\r
170 + "\u00C3\u00E3\u00D5\u00F5\u00D1\u00F1"
\r
171 + "\u00C4\u00E4\u00CB\u00EB\u00CF\u00EF\u00D6\u00F6\u00DC\u00FC\u0178\u00FF"
\r
174 + "\u0150\u0151\u0170\u0171"
\r
177 // remove accentued from a string and replace with ascii equivalent
\r
178 public static String convertNonAscii(String s) {
\r
179 if (s == null) return null;
\r
180 StringBuilder sb = new StringBuilder();
\r
181 int n = s.length();
\r
182 for (int i = 0; i < n; i++) {
\r
183 char c = s.charAt(i);
\r
184 int pos = UNICODE.indexOf(c);
\r
186 sb.append(PLAIN_ASCII.charAt(pos));
\r
192 return sb.toString();
\r
195 protected boolean isCheckMethodOnProcessAction() {
\r
196 return _CHECK_METHOD_ON_PROCESS_ACTION;
\r
199 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
\r