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.blogEntryInfos.action;
\r
25 import java.io.ByteArrayInputStream;
\r
26 import java.io.File;
\r
27 import java.io.FileInputStream;
\r
28 import java.io.IOException;
\r
29 import java.io.InputStream;
\r
30 import java.net.URLDecoder;
\r
32 import javax.portlet.ActionRequest;
\r
33 import javax.portlet.ActionResponse;
\r
34 import javax.portlet.PortletConfig;
\r
35 import javax.servlet.http.HttpServletRequest;
\r
36 import javax.servlet.http.HttpServletResponse;
\r
38 import org.apache.struts.action.ActionForm;
\r
39 import org.apache.struts.action.ActionForward;
\r
40 import org.apache.struts.action.ActionMapping;
\r
42 import com.liferay.portal.kernel.util.Base64;
\r
43 import com.liferay.portal.kernel.util.FileUtil;
\r
44 import com.liferay.portal.kernel.util.MimeTypesOverrideUtil;
\r
45 import com.liferay.portal.kernel.util.ParamUtil;
\r
46 import com.liferay.portal.kernel.util.StringPool;
\r
47 import com.liferay.portal.kernel.util.SystemProperties;
\r
48 import com.liferay.portal.model.CompanyConstants;
\r
49 import com.liferay.portal.struts.ActionConstants;
\r
50 import com.liferay.portal.struts.PortletAction;
\r
51 import com.liferay.portal.util.PortalUtil;
\r
52 import com.liferay.portlet.blogs.model.BlogsEntry;
\r
53 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
\r
54 import com.liferay.portlet.documentlibrary.conversion.util.ENTDocumentConversionServiceUtil;
\r
55 import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
\r
56 import com.pentila.entSavoie.blogEntryInfos.model.BlogEntryInfos;
\r
57 import com.pentila.entSavoie.blogEntryInfos.service.BlogEntryInfosLocalServiceUtil;
\r
58 import com.pentila.entSavoie.servlet.FLVPseudoStreamer;
\r
59 import com.pentila.entSavoie.servlet.ServletResponseServiceUtil;
\r
62 * <a href="GetBlogEntryInfosAttachmentAction.java.html"><b><i>View Source</i></b></a>
\r
64 * @author Brian Wing Shun Chan
\r
67 public class GetBlogEntryInfosFlashFileAction extends PortletAction {
\r
69 public ActionForward strutsExecute(
\r
70 ActionMapping mapping, ActionForm form, HttpServletRequest request,
\r
71 HttpServletResponse response)
\r
75 long blogEntryInfosId = ParamUtil.getLong(request, "blogEntryInfosId");
\r
76 String fileName = ParamUtil.getString(request, "flashFile");
\r
78 fileName = URLDecoder.decode(fileName);
\r
80 getFile(blogEntryInfosId, fileName, response, request);
\r
84 catch (Exception e) {
\r
85 e.printStackTrace();
\r
86 PortalUtil.sendError(e, request, response);
\r
92 public void processAction(
\r
93 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
\r
94 ActionRequest actionRequest, ActionResponse actionResponse)
\r
98 long blogEntryInfosId = ParamUtil.getLong(actionRequest, "blogEntryInfosId");
\r
99 String fileName = ParamUtil.getString(actionRequest, "flashFile");
\r
101 fileName = URLDecoder.decode(fileName);
\r
103 HttpServletResponse response = PortalUtil.getHttpServletResponse(
\r
105 HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
\r
107 getFile(blogEntryInfosId, fileName, response, request);
\r
109 setForward(actionRequest, ActionConstants.COMMON_NULL);
\r
111 catch (Exception e) {
\r
112 e.printStackTrace();
\r
113 PortalUtil.sendError(e, actionRequest, actionResponse);
\r
117 protected void getFile(
\r
118 long blogEntryInfosId, String fileName, HttpServletResponse response, HttpServletRequest request)
\r
121 InputStream is = null;
\r
124 BlogEntryInfos bei = BlogEntryInfosLocalServiceUtil.getBlogEntryInfos(blogEntryInfosId);
\r
126 BlogsEntry be = BlogsEntryLocalServiceUtil.getBlogsEntry(bei.getBlogEntryId());
\r
128 String path = BlogEntryInfosLocalServiceUtil.getFlashFileDir(bei) + "/" + fileName;
\r
130 InputStream isForId = DLStoreUtil.getFileAsStream(
\r
131 be.getCompanyId(), CompanyConstants.SYSTEM, path);
\r
132 String idSecure = ENTDocumentConversionServiceUtil.getFileChecksum(isForId);
\r
135 is = DLStoreUtil.getFileAsStream(
\r
136 be.getCompanyId(), CompanyConstants.SYSTEM, path);
\r
138 int contentLength = (int) DLStoreUtil.getFileSize(be.getCompanyId(), CompanyConstants.SYSTEM, path);
\r
140 String contentType = MimeTypesOverrideUtil.getContentType(fileName);
\r
142 String ppos = request.getParameter("start");
\r
143 long pos = ppos == null || ppos.length() == 0 ? 0 : Long.parseLong(ppos);
\r
145 String forceContentDisposition = ParamUtil.getString(request, "contentDispo");
\r
146 String fcd = forceContentDisposition == null ? "" : forceContentDisposition;
\r
149 if (pos!=0 && contentType.equals("application/x-shockwave-flash") && fcd.isEmpty()) {
\r
150 FLVPseudoStreamer flvPseudoStreamer = new FLVPseudoStreamer();
\r
151 flvPseudoStreamer.service(request, response, fileName, is, contentLength, contentType);
\r
154 ServletResponseServiceUtil.sendFile(
\r
155 response, fileName, is, contentLength, contentType, fcd);
\r
165 protected boolean isCheckMethodOnProcessAction() {
\r
166 return _CHECK_METHOD_ON_PROCESS_ACTION;
\r
169 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
\r