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.wiki.action;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.StringPool;
026: import com.liferay.portal.security.auth.PrincipalException;
027: import com.liferay.portal.struts.PortletAction;
028: import com.liferay.portal.theme.ThemeDisplay;
029: import com.liferay.portal.util.PropsUtil;
030: import com.liferay.portal.util.WebKeys;
031: import com.liferay.portlet.wiki.NoSuchNodeException;
032: import com.liferay.portlet.wiki.NoSuchPageException;
033: import com.liferay.portlet.wiki.model.WikiNode;
034: import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
035: import com.liferay.util.servlet.SessionErrors;
036:
037: import java.util.List;
038:
039: import javax.portlet.PortletConfig;
040: import javax.portlet.RenderRequest;
041: import javax.portlet.RenderResponse;
042:
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="ViewPageAction.java.html"><b><i>View Source</i></b></a>
049: *
050: * @author Brian Wing Shun Chan
051: * @author Jorge Ferrer
052: *
053: */
054: public class ViewPageAction extends PortletAction {
055:
056: public ActionForward render(ActionMapping mapping, ActionForm form,
057: PortletConfig config, RenderRequest req, RenderResponse res)
058: throws Exception {
059:
060: try {
061: ActionUtil.getNode(req);
062:
063: checkNode(req);
064:
065: ActionUtil.getPage(req);
066: } catch (Exception e) {
067: if (e instanceof NoSuchNodeException
068: || e instanceof NoSuchPageException
069: || e instanceof PrincipalException) {
070:
071: SessionErrors.add(req, e.getClass().getName());
072:
073: return mapping.findForward("portlet.wiki.error");
074: } else {
075: throw e;
076: }
077: }
078:
079: return mapping.findForward(getForward(req,
080: "portlet.wiki.view_page"));
081: }
082:
083: private void checkNode(RenderRequest req) throws PortalException,
084: SystemException {
085:
086: WikiNode node = (WikiNode) req.getAttribute(WebKeys.WIKI_NODE);
087:
088: if (node == null) {
089: ThemeDisplay themeDisplay = (ThemeDisplay) req
090: .getAttribute(WebKeys.THEME_DISPLAY);
091:
092: List nodes = WikiNodeLocalServiceUtil.getNodes(themeDisplay
093: .getLayout().getGroupId(), 0, 1);
094:
095: if (nodes.size() == 0) {
096: String nodeName = PropsUtil
097: .get(PropsUtil.WIKI_INITIAL_NODE_NAME);
098:
099: node = WikiNodeLocalServiceUtil.addNode(themeDisplay
100: .getUserId(), themeDisplay.getPlid(), nodeName,
101: StringPool.BLANK, true, true);
102: } else {
103: node = (WikiNode) nodes.get(0);
104: }
105:
106: req.setAttribute(WebKeys.WIKI_NODE, node);
107: }
108: }
109:
110: }
|