Java tutorial
/** * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portlet.journal.action; import com.liferay.portal.kernel.servlet.SessionErrors; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.security.auth.PrincipalException; import com.liferay.portal.struts.PortletAction; import com.liferay.portlet.journal.ArticleIdException; import com.liferay.portlet.journal.DuplicateArticleIdException; import com.liferay.portlet.journal.NoSuchArticleException; import com.liferay.portlet.journal.service.JournalArticleServiceUtil; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * @author Brian Wing Shun Chan */ public class CopyArticleAction extends PortletAction { @Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try { copyArticle(actionRequest); sendRedirect(actionRequest, actionResponse); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(actionRequest, e.getClass().getName()); setForward(actionRequest, "portlet.journal.error"); } else if (e instanceof DuplicateArticleIdException || e instanceof ArticleIdException) { SessionErrors.add(actionRequest, e.getClass().getName()); } else { throw e; } } } @Override public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { return mapping.findForward(getForward(renderRequest, "portlet.journal.copy_article")); } protected void copyArticle(ActionRequest actionRequest) throws Exception { long groupId = ParamUtil.getLong(actionRequest, "groupId"); String oldArticleId = ParamUtil.getString(actionRequest, "oldArticleId"); String newArticleId = ParamUtil.getString(actionRequest, "newArticleId"); boolean autoArticleId = ParamUtil.getBoolean(actionRequest, "autoArticleId"); double version = ParamUtil.getDouble(actionRequest, "version"); JournalArticleServiceUtil.copyArticle(groupId, oldArticleId, newArticleId, autoArticleId, version); } }