001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.communities.action;
022:
023: import com.liferay.portal.NoSuchGroupException;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.security.auth.PrincipalException;
026: import com.liferay.portal.service.LayoutServiceUtil;
027: import com.liferay.portal.struts.ActionConstants;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portlet.ActionResponseImpl;
030: import com.liferay.util.servlet.ServletResponseUtil;
031: import com.liferay.util.servlet.SessionErrors;
032:
033: import javax.portlet.ActionRequest;
034: import javax.portlet.ActionResponse;
035: import javax.portlet.PortletConfig;
036: import javax.portlet.RenderRequest;
037: import javax.portlet.RenderResponse;
038:
039: import javax.servlet.http.HttpServletResponse;
040:
041: import org.apache.commons.logging.Log;
042: import org.apache.commons.logging.LogFactory;
043: import org.apache.struts.action.ActionForm;
044: import org.apache.struts.action.ActionForward;
045: import org.apache.struts.action.ActionMapping;
046:
047: /**
048: * <a href="ExportPagesAction.java.html"><b><i>View Source</i></b></a>
049: *
050: * @author Alexander Chow
051: * @author Raymond Augé
052: *
053: */
054: public class ExportPagesAction extends PortletAction {
055:
056: public void processAction(ActionMapping mapping, ActionForm form,
057: PortletConfig config, ActionRequest req, ActionResponse res)
058: throws Exception {
059:
060: try {
061: long groupId = ParamUtil.getLong(req, "groupId");
062: boolean privateLayout = ParamUtil.getBoolean(req,
063: "privateLayout");
064: String fileName = ParamUtil
065: .getString(req, "exportFileName");
066:
067: byte[] byteArray = LayoutServiceUtil.exportLayouts(groupId,
068: privateLayout, req.getParameterMap());
069:
070: HttpServletResponse httpRes = ((ActionResponseImpl) res)
071: .getHttpServletResponse();
072:
073: ServletResponseUtil.sendFile(httpRes, fileName, byteArray);
074:
075: setForward(req, ActionConstants.COMMON_NULL);
076: } catch (Exception e) {
077: _log.error(e, e);
078: }
079: }
080:
081: public ActionForward render(ActionMapping mapping, ActionForm form,
082: PortletConfig config, RenderRequest req, RenderResponse res)
083: throws Exception {
084:
085: try {
086: ActionUtil.getGroup(req);
087: } catch (Exception e) {
088: if (e instanceof NoSuchGroupException
089: || e instanceof PrincipalException) {
090:
091: SessionErrors.add(req, e.getClass().getName());
092:
093: return mapping.findForward("portlet.communities.error");
094: } else {
095: throw e;
096: }
097: }
098:
099: return mapping.findForward(getForward(req,
100: "portlet.communities.export_pages"));
101: }
102:
103: private static Log _log = LogFactory
104: .getLog(ExportPagesAction.class);
105:
106: }
|