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            public String getClassName() {
048                    return AssetEntry.class.getName();
049            }
050    
051            public String getName(Locale locale) {
052                    String portletTitle = PortalUtil.getPortletTitle(
053                            PortletKeys.ASSET_PUBLISHER, locale);
054    
055                    return portletTitle.concat(StringPool.SPACE).concat(
056                            LanguageUtil.get(locale, "template"));
057            }
058    
059            public String getResourceName() {
060                    return "com.liferay.portlet.assetpublisher";
061            }
062    
063            @Override
064            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
065                            long classPK, Locale locale)
066                    throws Exception {
067    
068                    Map<String, TemplateVariableGroup> templateVariableGroups =
069                            super.getTemplateVariableGroups(classPK, locale);
070    
071                    TemplateVariableGroup assetPublisherUtilTemplateVariableGroup =
072                            new TemplateVariableGroup("asset-publisher-util");
073    
074                    assetPublisherUtilTemplateVariableGroup.addVariable(
075                            "asset-publisher-helper", AssetPublisherHelper.class,
076                            PortletDisplayTemplateConstants.ASSET_PUBLISHER_HELPER);
077    
078                    templateVariableGroups.put(
079                            "asset-publisher-util", assetPublisherUtilTemplateVariableGroup);
080    
081                    TemplateVariableGroup fieldsTemplateVariableGroup =
082                            templateVariableGroups.get("fields");
083    
084                    fieldsTemplateVariableGroup.empty();
085    
086                    fieldsTemplateVariableGroup.addCollectionVariable(
087                            "asset-entries", List.class,
088                            PortletDisplayTemplateConstants.ENTRIES, "asset-entry",
089                            AssetEntry.class, "curEntry");
090                    fieldsTemplateVariableGroup.addVariable(
091                            "asset-entry", AssetEntry.class,
092                            PortletDisplayTemplateConstants.ENTRY);
093    
094                    TemplateVariableGroup assetServicesTemplateVariableGroup =
095                            new TemplateVariableGroup("asset-services");
096    
097                    assetServicesTemplateVariableGroup.setAutocompleteEnabled(false);
098    
099                    assetServicesTemplateVariableGroup.addServiceLocatorVariables(
100                            AssetEntryLocalService.class, AssetEntryService.class,
101                            AssetVocabularyLocalService.class, AssetVocabularyService.class,
102                            AssetCategoryLocalService.class, AssetCategoryService.class,
103                            AssetTagLocalService.class, AssetTagService.class,
104                            AssetTagStatsLocalService.class);
105    
106                    templateVariableGroups.put(
107                            assetServicesTemplateVariableGroup.getLabel(),
108                            assetServicesTemplateVariableGroup);
109    
110                    return templateVariableGroups;
111            }
112    
113            @Override
114            protected String getTemplatesConfigPath() {
115                    return PropsValues.ASSET_PUBLISHER_DISPLAY_TEMPLATES_CONFIG;
116            }
117    
118    }