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.portal.kernel.util;
16  
17  import com.liferay.portal.kernel.json.JSONObject;
18  
19  import java.util.Locale;
20  import java.util.Map;
21  
22  import javax.portlet.ActionRequest;
23  import javax.portlet.PortletPreferences;
24  import javax.portlet.PortletRequest;
25  
26  /**
27   * <a href="Localization.java.html"><b><i>View Source</i></b></a>
28   *
29   * <p>
30   * This class is used to localize values stored in XML and is often used to add
31   * localization behavior to value objects.
32   * </p>
33   *
34   * <p>
35   * Caching of the localized values is done in this class rather than in the
36   * value object since value objects get flushed from cache fairly quickly.
37   * Though lookups performed on a key based on an XML file is slower than lookups
38   * done at the value object level in general, the value object will get flushed
39   * at a rate which works against the performance gain. The cache is a soft hash
40   * map which prevents memory leaks within the system while enabling the cache to
41   * live longer than in a weak hash map.
42   * </p>
43   *
44   * @author Alexander Chow
45   * @author Jorge Ferrer
46   * @author Mauro Mariuzzo
47   * @author Julio Camarero
48   * @author Brian Wing Shun Chan
49   */
50  public interface Localization {
51  
52      public Object deserialize(JSONObject jsonObject);
53  
54      public String[] getAvailableLocales(String xml);
55  
56      public String getDefaultLocale(String xml);
57  
58      public String getLocalization(String xml, String requestedLanguageId);
59  
60      public String getLocalization(
61          String xml, String requestedLanguageId, boolean useDefault);
62  
63      public Map<Locale, String> getLocalizationMap(
64          PortletRequest portletRequest, String parameter);
65  
66      public Map<Locale, String> getLocalizationMap(String xml);
67  
68      /**
69       * @deprecated Use <code>getLocalizationMap</code>.
70       */
71      public Map<Locale, String> getLocalizedParameter(
72          PortletRequest portletRequest, String parameter);
73  
74      public String getPreferencesValue(
75          PortletPreferences preferences, String key, String languageId);
76  
77      public String getPreferencesValue(
78          PortletPreferences preferences, String key, String languageId,
79          boolean useDefault);
80  
81      public String[] getPreferencesValues(
82          PortletPreferences preferences, String key, String languageId);
83  
84      public String[] getPreferencesValues(
85          PortletPreferences preferences, String key, String languageId,
86          boolean useDefault);
87  
88      public String removeLocalization(
89          String xml, String key, String requestedLanguageId);
90  
91      public String removeLocalization(
92          String xml, String key, String requestedLanguageId, boolean cdata);
93  
94      public void setLocalizedPreferencesValues (
95              ActionRequest actionRequest, PortletPreferences preferences,
96              String parameter)
97          throws Exception;
98  
99      public void setPreferencesValue(
100             PortletPreferences preferences, String key, String languageId,
101             String value)
102         throws Exception;
103 
104     public void setPreferencesValues(
105             PortletPreferences preferences, String key, String languageId,
106             String[] values)
107         throws Exception;
108 
109     public String updateLocalization(String xml, String key, String value);
110 
111     public String updateLocalization(
112         String xml, String key, String value, String requestedLanguageId);
113 
114     public String updateLocalization(
115         String xml, String key, String value, String requestedLanguageId,
116         String defaultLanguageId);
117 
118     public String updateLocalization(
119         String xml, String key, String value, String requestedLanguageId,
120         String defaultLanguageId, boolean cdata);
121 
122 }