001    /**
002     * Copyright (c) 2000-present 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.language.template;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
019    import com.liferay.portal.kernel.template.TemplateVariableGroup;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portal.util.PropsValues;
024    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
025    
026    import java.util.List;
027    import java.util.Locale;
028    import java.util.Map;
029    
030    /**
031     * @author Eduardo Garcia
032     */
033    public class LanguagePortletDisplayTemplateHandler
034            extends BasePortletDisplayTemplateHandler {
035    
036            @Override
037            public String getClassName() {
038                    return Locale.class.getName();
039            }
040    
041            @Override
042            public String getName(Locale locale) {
043                    String portletTitle = PortalUtil.getPortletTitle(
044                            PortletKeys.LANGUAGE, locale);
045    
046                    return portletTitle.concat(StringPool.SPACE).concat(
047                            LanguageUtil.get(locale, "template"));
048            }
049    
050            @Override
051            public String getResourceName() {
052                    return PortletKeys.LANGUAGE;
053            }
054    
055            @Override
056            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
057                            long classPK, String language, Locale locale)
058                    throws Exception {
059    
060                    Map<String, TemplateVariableGroup> templateVariableGroups =
061                            super.getTemplateVariableGroups(classPK, language, locale);
062    
063                    TemplateVariableGroup templateVariableGroup =
064                            templateVariableGroups.get("fields");
065    
066                    templateVariableGroup.empty();
067    
068                    templateVariableGroup.addCollectionVariable(
069                            "languages", List.class, PortletDisplayTemplateConstants.ENTRIES,
070                            "language", Locale.class, "curLanguage", "displayName");
071    
072                    String[] restrictedVariables = getRestrictedVariables(language);
073    
074                    TemplateVariableGroup documentServicesTemplateVariableGroup =
075                            new TemplateVariableGroup("document-services", restrictedVariables);
076    
077                    documentServicesTemplateVariableGroup.setAutocompleteEnabled(false);
078    
079                    templateVariableGroups.put(
080                            documentServicesTemplateVariableGroup.getLabel(),
081                            documentServicesTemplateVariableGroup);
082    
083                    return templateVariableGroups;
084            }
085    
086            @Override
087            protected String getTemplatesConfigPath() {
088                    return PropsValues.LANGUAGE_DISPLAY_TEMPLATES_CONFIG;
089            }
090    
091    }