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            @Override
042            public String getClassName() {
043                    return FileEntry.class.getName();
044            }
045    
046            @Override
047            public String getName(Locale locale) {
048                    String portletTitle = PortalUtil.getPortletTitle(
049                            PortletKeys.DOCUMENT_LIBRARY, locale);
050    
051                    return portletTitle.concat(StringPool.SPACE).concat(
052                            LanguageUtil.get(locale, "template"));
053            }
054    
055            @Override
056            public String getResourceName() {
057                    return PortletKeys.DOCUMENT_LIBRARY;
058            }
059    
060            @Override
061            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
062                            long classPK, String language, Locale locale)
063                    throws Exception {
064    
065                    Map<String, TemplateVariableGroup> templateVariableGroups =
066                            super.getTemplateVariableGroups(classPK, language, locale);
067    
068                    TemplateVariableGroup templateVariableGroup =
069                            templateVariableGroups.get("fields");
070    
071                    templateVariableGroup.empty();
072    
073                    templateVariableGroup.addCollectionVariable(
074                            "documents", List.class, PortletDisplayTemplateConstants.ENTRIES,
075                            "document", FileEntry.class, "curFileEntry", "title");
076    
077                    String[] restrictedVariables = getRestrictedVariables(language);
078    
079                    TemplateVariableGroup documentServicesTemplateVariableGroup =
080                            new TemplateVariableGroup("document-services", restrictedVariables);
081    
082                    documentServicesTemplateVariableGroup.setAutocompleteEnabled(false);
083    
084                    documentServicesTemplateVariableGroup.addServiceLocatorVariables(
085                            DLAppLocalService.class, DLAppService.class,
086                            DLFileEntryTypeLocalService.class, DLFileEntryTypeService.class);
087    
088                    templateVariableGroups.put(
089                            documentServicesTemplateVariableGroup.getLabel(),
090                            documentServicesTemplateVariableGroup);
091    
092                    return templateVariableGroups;
093            }
094    
095            @Override
096            protected String getTemplatesConfigPath() {
097                    return PropsValues.DL_DISPLAY_TEMPLATES_CONFIG;
098            }
099    
100    }