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