1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.words.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.util.Constants;
19  import com.liferay.portal.kernel.util.ParamUtil;
20  import com.liferay.portal.struts.PortletAction;
21  import com.liferay.portal.util.WebKeys;
22  import com.liferay.portlet.words.ScramblerException;
23  import com.liferay.portlet.words.util.WordsUtil;
24  
25  import javax.portlet.PortletConfig;
26  import javax.portlet.RenderRequest;
27  import javax.portlet.RenderResponse;
28  
29  import org.apache.struts.action.ActionForm;
30  import org.apache.struts.action.ActionForward;
31  import org.apache.struts.action.ActionMapping;
32  
33  /**
34   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   */
38  public class ViewAction extends PortletAction {
39  
40      public ActionForward render(
41              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
42              RenderRequest renderRequest, RenderResponse renderResponse)
43          throws Exception {
44  
45          try {
46              String cmd = ParamUtil.getString(renderRequest, Constants.CMD);
47  
48              if (cmd.equals(Constants.SEARCH)) {
49                  String word = ParamUtil.getString(renderRequest, "word");
50                  boolean scramble = ParamUtil.getBoolean(
51                      renderRequest, "scramble");
52  
53                  String[] words = null;
54  
55                  if (scramble) {
56                      words = WordsUtil.scramble(word);
57                  }
58                  else {
59                      words = WordsUtil.unscramble(word);
60                  }
61  
62                  renderRequest.setAttribute(WebKeys.WORDS_LIST, words);
63              }
64          }
65          catch (ScramblerException se) {
66              SessionErrors.add(renderRequest, se.getClass().getName());
67          }
68  
69          return mapping.findForward("portlet.words.view");
70      }
71  
72  }