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.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.json.JSONObject;
018    
019    import java.util.Locale;
020    import java.util.Map;
021    
022    import javax.portlet.ActionRequest;
023    import javax.portlet.PortletPreferences;
024    import javax.portlet.PortletRequest;
025    
026    /**
027     * <p>
028     * This class is used to localize values stored in XML and is often used to add
029     * localization behavior to value objects.
030     * </p>
031     *
032     * <p>
033     * Caching of the localized values is done in this class rather than in the
034     * value object since value objects get flushed from cache fairly quickly.
035     * Though lookups performed on a key based on an XML file is slower than lookups
036     * done at the value object level in general, the value object will get flushed
037     * at a rate which works against the performance gain. The cache is a soft hash
038     * map which prevents memory leaks within the system while enabling the cache to
039     * live longer than in a weak hash map.
040     * </p>
041     *
042     * @author Alexander Chow
043     * @author Jorge Ferrer
044     * @author Mauro Mariuzzo
045     * @author Julio Camarero
046     * @author Brian Wing Shun Chan
047     */
048    public interface Localization {
049    
050            public Object deserialize(JSONObject jsonObject);
051    
052            public String[] getAvailableLocales(String xml);
053    
054            public String getDefaultLocale(String xml);
055    
056            public String getLocalization(String xml, String requestedLanguageId);
057    
058            public String getLocalization(
059                    String xml, String requestedLanguageId, boolean useDefault);
060    
061            public Map<Locale, String> getLocalizationMap(
062                    PortletRequest portletRequest, String parameter);
063    
064            public Map<Locale, String> getLocalizationMap(String xml);
065    
066            /**
067             * @deprecated Use <code>getLocalizationMap</code>.
068             */
069            public Map<Locale, String> getLocalizedParameter(
070                    PortletRequest portletRequest, String parameter);
071    
072            public String getPreferencesValue(
073                    PortletPreferences preferences, String key, String languageId);
074    
075            public String getPreferencesValue(
076                    PortletPreferences preferences, String key, String languageId,
077                    boolean useDefault);
078    
079            public String[] getPreferencesValues(
080                    PortletPreferences preferences, String key, String languageId);
081    
082            public String[] getPreferencesValues(
083                    PortletPreferences preferences, String key, String languageId,
084                    boolean useDefault);
085    
086            public String removeLocalization(
087                    String xml, String key, String requestedLanguageId);
088    
089            public String removeLocalization(
090                    String xml, String key, String requestedLanguageId, boolean cdata);
091    
092            public void setLocalizedPreferencesValues (
093                            ActionRequest actionRequest, PortletPreferences preferences,
094                            String parameter)
095                    throws Exception;
096    
097            public void setPreferencesValue(
098                            PortletPreferences preferences, String key, String languageId,
099                            String value)
100                    throws Exception;
101    
102            public void setPreferencesValues(
103                            PortletPreferences preferences, String key, String languageId,
104                            String[] values)
105                    throws Exception;
106    
107            public String updateLocalization(String xml, String key, String value);
108    
109            public String updateLocalization(
110                    String xml, String key, String value, String requestedLanguageId);
111    
112            public String updateLocalization(
113                    String xml, String key, String value, String requestedLanguageId,
114                    String defaultLanguageId);
115    
116            public String updateLocalization(
117                    String xml, String key, String value, String requestedLanguageId,
118                    String defaultLanguageId, boolean cdata);
119    
120    }