1
22
23 package com.liferay.portlet.words.action;
24
25 import com.liferay.portal.kernel.util.Constants;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.struts.PortletAction;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.words.ScramblerException;
30 import com.liferay.portlet.words.util.WordsUtil;
31 import com.liferay.util.servlet.SessionErrors;
32
33 import javax.portlet.PortletConfig;
34 import javax.portlet.RenderRequest;
35 import javax.portlet.RenderResponse;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40
41
47 public class ViewAction extends PortletAction {
48
49 public ActionForward render(
50 ActionMapping mapping, ActionForm form, PortletConfig config,
51 RenderRequest req, RenderResponse res)
52 throws Exception {
53
54 try {
55 String cmd = ParamUtil.getString(req, Constants.CMD);
56
57 if (cmd.equals(Constants.SEARCH)) {
58 String word = ParamUtil.getString(req, "word");
59 boolean scramble = ParamUtil.getBoolean(req, "scramble");
60
61 String[] words = null;
62
63 if (scramble) {
64 words = WordsUtil.scramble(word);
65 }
66 else {
67 words = WordsUtil.unscramble(word);
68 }
69
70 req.setAttribute(WebKeys.WORDS_LIST, words);
71 }
72 }
73 catch (ScramblerException se) {
74 SessionErrors.add(req, se.getClass().getName());
75 }
76
77 return mapping.findForward("portlet.words.view");
78 }
79
80 }