001
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
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 }