001    /**
002     * Copyright (c) 2000-2012 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            @Override
034            public void processAction(
035                            ActionRequest actionRequest, ActionResponse actionResponse)
036                    throws PortletException {
037    
038                    try {
039                            String translationId = ParamUtil.getString(actionRequest, "id");
040                            String fromText = ParamUtil.getString(actionRequest, "text");
041    
042                            if (Validator.isNotNull(fromText)) {
043                                    Translation translation = TranslatorUtil.getTranslation(
044                                            translationId, fromText);
045    
046                                    actionRequest.setAttribute(
047                                            WebKeys.TRANSLATOR_TRANSLATION, translation);
048                            }
049                    }
050                    catch (Exception e) {
051                            throw new PortletException(e);
052                    }
053            }
054    
055    }