001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.translator;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.util.WebKeys;
020    import com.liferay.portlet.translator.model.Translation;
021    import com.liferay.portlet.translator.util.TranslatorUtil;
022    import com.liferay.util.bridges.mvc.MVCPortlet;
023    
024    import javax.portlet.ActionRequest;
025    import javax.portlet.ActionResponse;
026    import javax.portlet.PortletException;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class TranslatorPortlet extends MVCPortlet {
032    
033            public void processAction(
034                            ActionRequest actionRequest, ActionResponse actionResponse)
035                    throws PortletException {
036    
037                    try {
038                            String translationId = ParamUtil.getString(actionRequest, "id");
039                            String fromText = ParamUtil.getString(actionRequest, "text");
040    
041                            if (Validator.isNotNull(fromText)) {
042                                    Translation translation =
043                                            TranslatorUtil.getTranslation(translationId, fromText);
044    
045                                    actionRequest.setAttribute(
046                                            WebKeys.TRANSLATOR_TRANSLATION, translation);
047                            }
048                    }
049                    catch (Exception e) {
050                            throw new PortletException(e);
051                    }
052            }
053    
054    }