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.translator;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.kernel.util.Validator;
19  import com.liferay.portal.util.WebKeys;
20  import com.liferay.portlet.translator.model.Translation;
21  import com.liferay.portlet.translator.util.TranslatorUtil;
22  import com.liferay.util.bridges.mvc.MVCPortlet;
23  
24  import javax.portlet.ActionRequest;
25  import javax.portlet.ActionResponse;
26  import javax.portlet.PortletException;
27  
28  /**
29   * <a href="TranslatorPortlet.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class TranslatorPortlet extends MVCPortlet {
34  
35      public void processAction(
36              ActionRequest actionRequest, ActionResponse actionResponse)
37          throws PortletException {
38  
39          try {
40              String translationId = ParamUtil.getString(actionRequest, "id");
41              String fromText = ParamUtil.getString(actionRequest, "text");
42  
43              if (Validator.isNotNull(fromText)) {
44                  Translation translation =
45                      TranslatorUtil.getTranslation(translationId, fromText);
46  
47                  actionRequest.setAttribute(
48                      WebKeys.TRANSLATOR_TRANSLATION, translation);
49              }
50          }
51          catch (Exception e) {
52              throw new PortletException(e);
53          }
54      }
55  
56  }