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.theme.ThemeDisplay;
28 import com.liferay.portal.util.PortalUtil;
29 import com.liferay.portal.util.WebKeys;
30 import com.liferay.portlet.wiki.NoSuchPageException;
31 import com.liferay.portlet.wiki.model.WikiNode;
32 import com.liferay.portlet.wiki.model.WikiPage;
33 import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
34 import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
35 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
36
37 import javax.portlet.ActionRequest;
38 import javax.portlet.RenderRequest;
39
40 import javax.servlet.http.HttpServletRequest;
41
42
49 public class ActionUtil {
50
51 public static void getNode(ActionRequest req) throws Exception {
52 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
53
54 getNode(httpReq);
55 }
56
57 public static void getNode(RenderRequest req) throws Exception {
58 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
59
60 getNode(httpReq);
61 }
62
63 public static void getNode(HttpServletRequest req) throws Exception {
64 ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
65 WebKeys.THEME_DISPLAY);
66
67 long nodeId = ParamUtil.getLong(req, "nodeId");
68 String nodeName = ParamUtil.getString(req, "nodeName");
69
70 WikiNode node = null;
71
72 if (nodeId > 0) {
73 node = WikiNodeServiceUtil.getNode(nodeId);
74 }
75 else if (Validator.isNotNull(nodeName)) {
76 node = WikiNodeServiceUtil.getNode(
77 themeDisplay.getPortletGroupId(), nodeName);
78 }
79
80 req.setAttribute(WebKeys.WIKI_NODE, node);
81 }
82
83 public static void getPage(ActionRequest req) throws Exception {
84 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
85
86 getPage(httpReq);
87 }
88
89 public static void getPage(RenderRequest req) throws Exception {
90 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
91
92 getPage(httpReq);
93 }
94
95 public static void getPage(HttpServletRequest req) throws Exception {
96 long nodeId = ParamUtil.getLong(req, "nodeId");
97 String title = ParamUtil.getString(req, "title");
98 double version = ParamUtil.getDouble(req, "version");
99
100 if (nodeId == 0) {
101 WikiNode node = (WikiNode)req.getAttribute(WebKeys.WIKI_NODE);
102
103 if (node != null) {
104 nodeId = node.getNodeId();
105 }
106 }
107
108 if (Validator.isNull(title)) {
109 title = WikiPageImpl.FRONT_PAGE;
110 }
111
112 WikiPage page = null;
113
114 try {
115 page = WikiPageServiceUtil.getPage(nodeId, title, version);
116 }
117 catch (NoSuchPageException nspe) {
118 if (title.equals(WikiPageImpl.FRONT_PAGE) && (version == 0)) {
119 page = WikiPageServiceUtil.addPage(nodeId, title, null, null);
120 }
121 else {
122 throw nspe;
123 }
124 }
125
126 req.setAttribute(WebKeys.WIKI_PAGE, page);
127 }
128
129 }