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.myplaces.action;
022:
023: import com.liferay.portal.NoSuchLayoutSetException;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.model.Layout;
026: import com.liferay.portal.model.impl.LayoutImpl;
027: import com.liferay.portal.service.LayoutLocalServiceUtil;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portal.theme.ThemeDisplay;
030: import com.liferay.portal.util.PortalUtil;
031: import com.liferay.portal.util.WebKeys;
032: import com.liferay.util.servlet.SessionErrors;
033:
034: import java.util.List;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.ActionResponse;
038: import javax.portlet.PortletConfig;
039: import javax.portlet.RenderRequest;
040: import javax.portlet.RenderResponse;
041:
042: import javax.servlet.http.HttpServletRequest;
043: import javax.servlet.http.HttpServletResponse;
044:
045: import org.apache.struts.action.ActionForm;
046: import org.apache.struts.action.ActionForward;
047: import org.apache.struts.action.ActionMapping;
048:
049: /**
050: * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
051: *
052: * @author Brian Wing Shun Chan
053: *
054: */
055: public class ViewAction extends PortletAction {
056:
057: public ActionForward strutsExecute(ActionMapping mapping,
058: ActionForm form, HttpServletRequest req,
059: HttpServletResponse res) throws Exception {
060:
061: ThemeDisplay themeDisplay = (ThemeDisplay) req
062: .getAttribute(WebKeys.THEME_DISPLAY);
063:
064: long groupId = ParamUtil.getLong(req, "groupId");
065: boolean privateLayout = ParamUtil.getBoolean(req,
066: "privateLayout");
067:
068: List layouts = LayoutLocalServiceUtil.getLayouts(groupId,
069: privateLayout, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID, 0,
070: 1);
071:
072: String redirect = themeDisplay.getPathMain();
073:
074: if (layouts.size() > 0) {
075: Layout layout = (Layout) layouts.get(0);
076:
077: redirect = PortalUtil.getLayoutURL(layout, themeDisplay);
078: } else {
079: redirect = ParamUtil.getString(req, "redirect");
080:
081: SessionErrors.add(req, NoSuchLayoutSetException.class
082: .getName(), new NoSuchLayoutSetException(
083: "{groupId=" + groupId + ",privateLayout="
084: + privateLayout + "}"));
085: }
086:
087: // Send redirect
088:
089: res.sendRedirect(redirect);
090:
091: return null;
092: }
093:
094: public void processAction(ActionMapping mapping, ActionForm form,
095: PortletConfig config, ActionRequest req, ActionResponse res)
096: throws Exception {
097:
098: ThemeDisplay themeDisplay = (ThemeDisplay) req
099: .getAttribute(WebKeys.THEME_DISPLAY);
100:
101: long groupId = ParamUtil.getLong(req, "groupId");
102: boolean privateLayout = ParamUtil.getBoolean(req,
103: "privateLayout");
104:
105: List layouts = LayoutLocalServiceUtil.getLayouts(groupId,
106: privateLayout, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID, 0,
107: 1);
108:
109: String redirect = themeDisplay.getPathMain();
110:
111: if (layouts.size() > 0) {
112: Layout layout = (Layout) layouts.get(0);
113:
114: redirect = PortalUtil.getLayoutURL(layout, themeDisplay);
115: } else {
116: redirect = ParamUtil.getString(req, "redirect");
117:
118: SessionErrors.add(req, NoSuchLayoutSetException.class
119: .getName(), new NoSuchLayoutSetException(
120: "{groupId=" + groupId + ",privateLayout="
121: + privateLayout + "}"));
122: }
123:
124: // Send redirect
125:
126: res.sendRedirect(redirect);
127: }
128:
129: public ActionForward render(ActionMapping mapping, ActionForm form,
130: PortletConfig config, RenderRequest req, RenderResponse res)
131: throws Exception {
132:
133: return mapping.findForward("portlet.my_places.view");
134: }
135:
136: protected boolean isCheckMethodOnProcessAction() {
137: return _CHECK_METHOD_ON_PROCESS_ACTION;
138: }
139:
140: private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
141:
142: }
|