001
014
015 package com.liferay.portlet.words.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.Constants;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.struts.PortletAction;
021 import com.liferay.portal.util.WebKeys;
022 import com.liferay.portlet.words.ScramblerException;
023 import com.liferay.portlet.words.util.WordsUtil;
024
025 import javax.portlet.PortletConfig;
026 import javax.portlet.RenderRequest;
027 import javax.portlet.RenderResponse;
028
029 import org.apache.struts.action.ActionForm;
030 import org.apache.struts.action.ActionForward;
031 import org.apache.struts.action.ActionMapping;
032
033
036 public class ViewAction extends PortletAction {
037
038 public ActionForward render(
039 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
040 RenderRequest renderRequest, RenderResponse renderResponse)
041 throws Exception {
042
043 try {
044 String cmd = ParamUtil.getString(renderRequest, Constants.CMD);
045
046 if (cmd.equals(Constants.SEARCH)) {
047 String word = ParamUtil.getString(renderRequest, "word");
048 boolean scramble = ParamUtil.getBoolean(
049 renderRequest, "scramble");
050
051 String[] words = null;
052
053 if (scramble) {
054 words = WordsUtil.scramble(word);
055 }
056 else {
057 words = WordsUtil.unscramble(word);
058 }
059
060 renderRequest.setAttribute(WebKeys.WORDS_LIST, words);
061 }
062 }
063 catch (ScramblerException se) {
064 SessionErrors.add(renderRequest, se.getClass().getName());
065 }
066
067 return mapping.findForward("portlet.words.view");
068 }
069
070 }