001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
034     * @author Brian Wing Shun Chan
035     */
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    }