001
014
015 package com.liferay.portlet.wikidisplay.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.security.auth.PrincipalException;
022 import com.liferay.portal.struts.PortletAction;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.WebKeys;
025 import com.liferay.portlet.wiki.NoSuchNodeException;
026 import com.liferay.portlet.wiki.NoSuchPageException;
027 import com.liferay.portlet.wiki.model.WikiNode;
028 import com.liferay.portlet.wiki.model.WikiPage;
029 import com.liferay.portlet.wiki.model.WikiPageConstants;
030 import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
031 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
032
033 import javax.portlet.PortletConfig;
034 import javax.portlet.PortletPreferences;
035 import javax.portlet.RenderRequest;
036 import javax.portlet.RenderResponse;
037
038 import org.apache.struts.action.ActionForm;
039 import org.apache.struts.action.ActionForward;
040 import org.apache.struts.action.ActionMapping;
041
042
045 public class ViewAction extends PortletAction {
046
047 public ActionForward render(
048 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
049 RenderRequest renderRequest, RenderResponse renderResponse)
050 throws Exception {
051
052 try {
053 PortletPreferences preferences = renderRequest.getPreferences();
054
055 ThemeDisplay themeDisplay =
056 (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
057
058 long nodeId = GetterUtil.getLong(
059 preferences.getValue("node-id", StringPool.BLANK));
060 String title = ParamUtil.getString(
061 renderRequest, "title",
062 preferences.getValue("title", WikiPageConstants.FRONT_PAGE));
063
064 WikiNode node = WikiNodeServiceUtil.getNode(nodeId);
065
066 if (node.getGroupId() != themeDisplay.getScopeGroupId()) {
067 throw new NoSuchNodeException();
068 }
069
070 WikiPage wikiPage = null;
071
072 try {
073 wikiPage = WikiPageServiceUtil.getPage(nodeId, title);
074 }
075 catch (NoSuchPageException nspe) {
076 wikiPage = WikiPageServiceUtil.getPage(
077 nodeId, WikiPageConstants.FRONT_PAGE);
078 }
079
080 renderRequest.setAttribute(WebKeys.WIKI_NODE, node);
081 renderRequest.setAttribute(WebKeys.WIKI_PAGE, wikiPage);
082
083 return mapping.findForward("portlet.wiki_display.view");
084 }
085 catch (NoSuchNodeException nsne) {
086 return mapping.findForward("/portal/portlet_not_setup");
087 }
088 catch (NoSuchPageException nsne) {
089 return mapping.findForward("/portal/portlet_not_setup");
090 }
091 catch (PrincipalException pe) {
092 SessionErrors.add(renderRequest, pe.getClass().getName());
093
094 return mapping.findForward("portlet.wiki_display.error");
095 }
096 }
097
098 }