com.liferay.site.navigation.language.web.internal.portlet.template.SiteNavigationLanguagePortletDisplayTemplateHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.site.navigation.language.web.internal.portlet.template.SiteNavigationLanguagePortletDisplayTemplateHandler.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.site.navigation.language.web.internal.portlet.template;

import com.liferay.petra.string.StringPool;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
import com.liferay.portal.kernel.servlet.taglib.ui.LanguageEntry;
import com.liferay.portal.kernel.template.TemplateHandler;
import com.liferay.portal.kernel.template.TemplateVariableGroup;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.ResourceBundleUtil;
import com.liferay.portlet.display.template.PortletDisplayTemplateConstants;
import com.liferay.site.navigation.language.constants.SiteNavigationLanguagePortletKeys;
import com.liferay.site.navigation.language.web.configuration.SiteNavigationLanguageWebTemplateConfiguration;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;

/**
 * @author Eduardo Garcia
 */
@Component(configurationPid = "com.liferay.site.navigation.language.web.configuration.SiteNavigationLanguageWebTemplateConfiguration", configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true, property = {
        "javax.portlet.name="
                + SiteNavigationLanguagePortletKeys.SITE_NAVIGATION_LANGUAGE }, service = TemplateHandler.class)
public class SiteNavigationLanguagePortletDisplayTemplateHandler extends BasePortletDisplayTemplateHandler {

    @Override
    public String getClassName() {
        return LanguageEntry.class.getName();
    }

    @Override
    public String getDefaultTemplateKey() {
        return _siteNavigationLanguageWebTemplateConfiguration.ddmTemplateKey();
    }

    @Override
    public String getName(Locale locale) {
        ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", locale, getClass());

        String portletTitle = _portal.getPortletTitle(SiteNavigationLanguagePortletKeys.SITE_NAVIGATION_LANGUAGE,
                resourceBundle);

        return portletTitle.concat(StringPool.SPACE).concat(LanguageUtil.get(locale, "template"));
    }

    @Override
    public String getResourceName() {
        return SiteNavigationLanguagePortletKeys.SITE_NAVIGATION_LANGUAGE;
    }

    @Override
    public Map<String, TemplateVariableGroup> getTemplateVariableGroups(long classPK, String language,
            Locale locale) throws Exception {

        Map<String, TemplateVariableGroup> templateVariableGroups = super.getTemplateVariableGroups(classPK,
                language, locale);

        TemplateVariableGroup templateVariableGroup = templateVariableGroups.get("fields");

        templateVariableGroup.empty();

        templateVariableGroup.addCollectionVariable("languages", List.class,
                PortletDisplayTemplateConstants.ENTRIES, "language", LanguageEntry.class, "curLanguage",
                "longDisplayName");

        return templateVariableGroups;
    }

    @Activate
    @Modified
    protected void activate(Map<String, Object> properties) {
        _siteNavigationLanguageWebTemplateConfiguration = ConfigurableUtil
                .createConfigurable(SiteNavigationLanguageWebTemplateConfiguration.class, properties);
    }

    @Override
    protected String getTemplatesConfigPath() {
        return "com/liferay/site/navigation/language/web/portlet/template"
                + "/dependencies/portlet-display-templates.xml";
    }

    @Reference
    private Portal _portal;

    private volatile SiteNavigationLanguageWebTemplateConfiguration _siteNavigationLanguageWebTemplateConfiguration;

}