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.kernel.util.ParamUtil;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.portal.util.PortalUtil;
026: import com.liferay.portal.util.WebKeys;
027: import com.liferay.portlet.wiki.NoSuchPageException;
028: import com.liferay.portlet.wiki.model.WikiNode;
029: import com.liferay.portlet.wiki.model.WikiPage;
030: import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
031: import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
032: import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
033:
034: import javax.portlet.ActionRequest;
035: import javax.portlet.RenderRequest;
036:
037: import javax.servlet.http.HttpServletRequest;
038:
039: /**
040: * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
041: *
042: * @author Brian Wing Shun Chan
043: *
044: */
045: public class ActionUtil {
046:
047: public static void getNode(ActionRequest req) throws Exception {
048: HttpServletRequest httpReq = PortalUtil
049: .getHttpServletRequest(req);
050:
051: getNode(httpReq);
052: }
053:
054: public static void getNode(RenderRequest req) throws Exception {
055: HttpServletRequest httpReq = PortalUtil
056: .getHttpServletRequest(req);
057:
058: getNode(httpReq);
059: }
060:
061: public static void getNode(HttpServletRequest req) throws Exception {
062: long nodeId = ParamUtil.getLong(req, "nodeId");
063:
064: WikiNode node = null;
065:
066: if (nodeId > 0) {
067: node = WikiNodeServiceUtil.getNode(nodeId);
068: }
069:
070: req.setAttribute(WebKeys.WIKI_NODE, node);
071: }
072:
073: public static void getPage(ActionRequest req) throws Exception {
074: HttpServletRequest httpReq = PortalUtil
075: .getHttpServletRequest(req);
076:
077: getPage(httpReq);
078: }
079:
080: public static void getPage(RenderRequest req) throws Exception {
081: HttpServletRequest httpReq = PortalUtil
082: .getHttpServletRequest(req);
083:
084: getPage(httpReq);
085: }
086:
087: public static void getPage(HttpServletRequest req) throws Exception {
088: long nodeId = ParamUtil.getLong(req, "nodeId");
089: String title = ParamUtil.getString(req, "title");
090: double version = ParamUtil.getDouble(req, "version");
091:
092: if (nodeId == 0) {
093: WikiNode node = (WikiNode) req
094: .getAttribute(WebKeys.WIKI_NODE);
095:
096: if (node != null) {
097: nodeId = node.getNodeId();
098: }
099: }
100:
101: if (Validator.isNull(title)) {
102: title = WikiPageImpl.FRONT_PAGE;
103: }
104:
105: WikiPage page = null;
106:
107: try {
108: page = WikiPageServiceUtil.getPage(nodeId, title, version);
109: } catch (NoSuchPageException nspe) {
110: if (version == 0) {
111: page = WikiPageServiceUtil.addPage(nodeId, title);
112: }
113: }
114:
115: req.setAttribute(WebKeys.WIKI_PAGE, page);
116: }
117:
118: }
|