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.Constants;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.kernel.util.StringUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portlet.tags.TagsEntryException;
030: import com.liferay.portlet.wiki.NoSuchNodeException;
031: import com.liferay.portlet.wiki.NoSuchPageException;
032: import com.liferay.portlet.wiki.PageContentException;
033: import com.liferay.portlet.wiki.PageTitleException;
034: import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
035: import com.liferay.util.servlet.SessionErrors;
036:
037: import javax.portlet.ActionRequest;
038: import javax.portlet.ActionResponse;
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="EditPageAction.java.html"><b><i>View Source</i></b></a>
049: *
050: * @author Brian Wing Shun Chan
051: *
052: */
053: public class EditPageAction extends PortletAction {
054:
055: public void processAction(ActionMapping mapping, ActionForm form,
056: PortletConfig config, ActionRequest req, ActionResponse res)
057: throws Exception {
058:
059: String cmd = ParamUtil.getString(req, Constants.CMD);
060:
061: try {
062: if (cmd.equals(Constants.ADD)
063: || cmd.equals(Constants.UPDATE)) {
064: updatePage(req);
065: } else if (cmd.equals(Constants.DELETE)) {
066: deletePage(req);
067: } else if (cmd.equals(Constants.REVERT)) {
068: revertPage(req);
069: }
070:
071: if (Validator.isNotNull(cmd)) {
072: sendRedirect(req, res);
073: }
074: } catch (Exception e) {
075: if (e instanceof NoSuchNodeException
076: || e instanceof NoSuchPageException
077: || e instanceof PrincipalException) {
078:
079: SessionErrors.add(req, e.getClass().getName());
080:
081: setForward(req, "portlet.wiki.error");
082: } else if (e instanceof PageContentException
083: || e instanceof PageTitleException) {
084:
085: SessionErrors.add(req, e.getClass().getName());
086: } else if (e instanceof TagsEntryException) {
087: SessionErrors.add(req, e.getClass().getName(), e);
088: } else {
089: throw e;
090: }
091: }
092: }
093:
094: public ActionForward render(ActionMapping mapping, ActionForm form,
095: PortletConfig config, RenderRequest req, RenderResponse res)
096: throws Exception {
097:
098: try {
099: ActionUtil.getNode(req);
100: ActionUtil.getPage(req);
101: } catch (Exception e) {
102: if (e instanceof NoSuchNodeException
103: || e instanceof NoSuchPageException
104: || e instanceof PageTitleException
105: || e instanceof PrincipalException) {
106:
107: SessionErrors.add(req, e.getClass().getName());
108:
109: return mapping.findForward("portlet.wiki.error");
110: } else {
111: throw e;
112: }
113: }
114:
115: return mapping.findForward(getForward(req,
116: "portlet.wiki.edit_page"));
117: }
118:
119: protected void deletePage(ActionRequest req) throws Exception {
120: long nodeId = ParamUtil.getLong(req, "nodeId");
121: String title = ParamUtil.getString(req, "title");
122:
123: WikiPageServiceUtil.deletePage(nodeId, title);
124: }
125:
126: protected void revertPage(ActionRequest req) throws Exception {
127: long nodeId = ParamUtil.getLong(req, "nodeId");
128: String title = ParamUtil.getString(req, "title");
129: double version = ParamUtil.getDouble(req, "version");
130:
131: WikiPageServiceUtil.revertPage(nodeId, title, version);
132: }
133:
134: protected void updatePage(ActionRequest req) throws Exception {
135: long nodeId = ParamUtil.getLong(req, "nodeId");
136: String title = ParamUtil.getString(req, "title");
137:
138: String content = ParamUtil.getString(req, "content");
139: String format = ParamUtil.getString(req, "format");
140:
141: String[] tagsEntries = StringUtil.split(ParamUtil.getString(
142: req, "tagsEntries"));
143:
144: WikiPageServiceUtil.updatePage(nodeId, title, content, format,
145: tagsEntries);
146: }
147:
148: }
|