1
22
23 package com.liferay.portlet.wiki.action;
24
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.kernel.util.Validator;
27 import com.liferay.portal.util.PortalUtil;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.wiki.NoSuchPageException;
30 import com.liferay.portlet.wiki.model.WikiNode;
31 import com.liferay.portlet.wiki.model.WikiPage;
32 import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
33 import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
34 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
35
36 import javax.portlet.ActionRequest;
37 import javax.portlet.RenderRequest;
38
39 import javax.servlet.http.HttpServletRequest;
40
41
47 public class ActionUtil {
48
49 public static void getNode(ActionRequest req) throws Exception {
50 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
51
52 getNode(httpReq);
53 }
54
55 public static void getNode(RenderRequest req) throws Exception {
56 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
57
58 getNode(httpReq);
59 }
60
61 public static void getNode(HttpServletRequest req) throws Exception {
62 long nodeId = ParamUtil.getLong(req, "nodeId");
63
64 WikiNode node = null;
65
66 if (nodeId > 0) {
67 node = WikiNodeServiceUtil.getNode(nodeId);
68 }
69
70 req.setAttribute(WebKeys.WIKI_NODE, node);
71 }
72
73 public static void getPage(ActionRequest req) throws Exception {
74 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
75
76 getPage(httpReq);
77 }
78
79 public static void getPage(RenderRequest req) throws Exception {
80 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
81
82 getPage(httpReq);
83 }
84
85 public static void getPage(HttpServletRequest req) throws Exception {
86 long nodeId = ParamUtil.getLong(req, "nodeId");
87 String title = ParamUtil.getString(req, "title");
88 double version = ParamUtil.getDouble(req, "version");
89
90 if (nodeId == 0) {
91 WikiNode node = (WikiNode)req.getAttribute(WebKeys.WIKI_NODE);
92
93 if (node != null) {
94 nodeId = node.getNodeId();
95 }
96 }
97
98 if (Validator.isNull(title)) {
99 title = WikiPageImpl.FRONT_PAGE;
100 }
101
102 WikiPage page = null;
103
104 try {
105 page = WikiPageServiceUtil.getPage(nodeId, title, version);
106 }
107 catch (NoSuchPageException nspe) {
108 if (version == 0) {
109 page = WikiPageServiceUtil.addPage(nodeId, title);
110 }
111 }
112
113 req.setAttribute(WebKeys.WIKI_PAGE, page);
114 }
115
116 }