001    /**
002     * Copyright (c) 2000-2013 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.assetpublisher.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.asset.model.AssetEntry;
025    import com.liferay.portlet.asset.service.AssetCategoryLocalService;
026    import com.liferay.portlet.asset.service.AssetCategoryService;
027    import com.liferay.portlet.asset.service.AssetEntryLocalService;
028    import com.liferay.portlet.asset.service.AssetEntryService;
029    import com.liferay.portlet.asset.service.AssetTagLocalService;
030    import com.liferay.portlet.asset.service.AssetTagService;
031    import com.liferay.portlet.asset.service.AssetTagStatsLocalService;
032    import com.liferay.portlet.asset.service.AssetVocabularyLocalService;
033    import com.liferay.portlet.asset.service.AssetVocabularyService;
034    import com.liferay.portlet.assetpublisher.util.AssetPublisherHelper;
035    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
036    
037    import java.util.List;
038    import java.util.Locale;
039    import java.util.Map;
040    
041    /**
042     * @author Juan Fern??ndez
043     */
044    public class AssetPublisherPortletDisplayTemplateHandler
045            extends BasePortletDisplayTemplateHandler {
046    
047            @Override
048            public String getClassName() {
049                    return AssetEntry.class.getName();
050            }
051    
052            @Override
053            public String getName(Locale locale) {
054                    String portletTitle = PortalUtil.getPortletTitle(
055                            PortletKeys.ASSET_PUBLISHER, locale);
056    
057                    return portletTitle.concat(StringPool.SPACE).concat(
058                            LanguageUtil.get(locale, "template"));
059            }
060    
061            @Override
062            public String getResourceName() {
063                    return PortletKeys.ASSET_PUBLISHER;
064            }
065    
066            @Override
067            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
068                            long classPK, String language, Locale locale)
069                    throws Exception {
070    
071                    Map<String, TemplateVariableGroup> templateVariableGroups =
072                            super.getTemplateVariableGroups(classPK, language, locale);
073    
074                    String[] restrictedVariables = getRestrictedVariables(language);
075    
076                    TemplateVariableGroup assetPublisherUtilTemplateVariableGroup =
077                            new TemplateVariableGroup(
078                                    "asset-publisher-util", restrictedVariables);
079    
080                    assetPublisherUtilTemplateVariableGroup.addVariable(
081                            "asset-publisher-helper", AssetPublisherHelper.class,
082                            PortletDisplayTemplateConstants.ASSET_PUBLISHER_HELPER);
083    
084                    templateVariableGroups.put(
085                            "asset-publisher-util", assetPublisherUtilTemplateVariableGroup);
086    
087                    TemplateVariableGroup fieldsTemplateVariableGroup =
088                            templateVariableGroups.get("fields");
089    
090                    fieldsTemplateVariableGroup.empty();
091    
092                    fieldsTemplateVariableGroup.addCollectionVariable(
093                            "asset-entries", List.class,
094                            PortletDisplayTemplateConstants.ENTRIES, "asset-entry",
095                            AssetEntry.class, "curEntry", "getTitle(locale)");
096                    fieldsTemplateVariableGroup.addVariable(
097                            "asset-entry", AssetEntry.class,
098                            PortletDisplayTemplateConstants.ENTRY, "getTitle(locale)");
099    
100                    TemplateVariableGroup assetServicesTemplateVariableGroup =
101                            new TemplateVariableGroup("asset-services", restrictedVariables);
102    
103                    assetServicesTemplateVariableGroup.setAutocompleteEnabled(false);
104    
105                    assetServicesTemplateVariableGroup.addServiceLocatorVariables(
106                            AssetEntryLocalService.class, AssetEntryService.class,
107                            AssetVocabularyLocalService.class, AssetVocabularyService.class,
108                            AssetCategoryLocalService.class, AssetCategoryService.class,
109                            AssetTagLocalService.class, AssetTagService.class,
110                            AssetTagStatsLocalService.class);
111    
112                    templateVariableGroups.put(
113                            assetServicesTemplateVariableGroup.getLabel(),
114                            assetServicesTemplateVariableGroup);
115    
116                    return templateVariableGroups;
117            }
118    
119            @Override
120            protected String getTemplatesConfigPath() {
121                    return PropsValues.ASSET_PUBLISHER_DISPLAY_TEMPLATES_CONFIG;
122            }
123    
124    }