001    /**
002     * Copyright (c) 2000-present 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.trash;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.language.LanguageUtil;
019    import com.liferay.portal.kernel.repository.model.FileEntry;
020    import com.liferay.portal.kernel.repository.model.FileShortcut;
021    import com.liferay.portal.kernel.trash.BaseTrashRenderer;
022    import com.liferay.portal.kernel.util.HtmlUtil;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.asset.model.AssetRenderer;
027    import com.liferay.portlet.documentlibrary.model.DLFileShortcutConstants;
028    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
029    import com.liferay.portlet.documentlibrary.util.DLUtil;
030    
031    import java.util.Locale;
032    
033    import javax.portlet.PortletRequest;
034    import javax.portlet.PortletResponse;
035    
036    /**
037     * @author Zsolt Berentey
038     */
039    public class DLFileShortcutTrashRenderer extends BaseTrashRenderer {
040    
041            public static final String TYPE = "shortcut";
042    
043            public DLFileShortcutTrashRenderer(FileShortcut fileShortcut)
044                    throws PortalException {
045    
046                    _fileShortcut = fileShortcut;
047    
048                    _fileEntry = DLAppLocalServiceUtil.getFileEntry(
049                            fileShortcut.getToFileEntryId());
050            }
051    
052            @Override
053            public String getClassName() {
054                    return DLFileShortcutConstants.getClassName();
055            }
056    
057            @Override
058            public long getClassPK() {
059                    return _fileShortcut.getPrimaryKey();
060            }
061    
062            @Override
063            public String getIconCssClass() {
064                    return DLUtil.getFileIconCssClass(_fileEntry.getExtension());
065            }
066    
067            @Override
068            public String getIconPath(ThemeDisplay themeDisplay) {
069                    return themeDisplay.getPathThemeImages() + "/file_system/small/" +
070                            _fileEntry.getIcon() + ".png";
071            }
072    
073            @Override
074            public String getPortletId() {
075                    return PortletKeys.DOCUMENT_LIBRARY;
076            }
077    
078            @Override
079            public String getSummary(
080                    PortletRequest portletRequest, PortletResponse portletResponse) {
081    
082                    return HtmlUtil.stripHtml(_fileEntry.getDescription());
083            }
084    
085            @Override
086            public String getTitle(Locale locale) {
087                    return LanguageUtil.format(
088                            locale, "shortcut-to-x", _fileShortcut.getToTitle(), false);
089            }
090    
091            @Override
092            public String getType() {
093                    return TYPE;
094            }
095    
096            @Override
097            public String render(
098                            PortletRequest portletRequest, PortletResponse portletResponse,
099                            String template)
100                    throws Exception {
101    
102                    if (template.equals(AssetRenderer.TEMPLATE_ABSTRACT) ||
103                            template.equals(AssetRenderer.TEMPLATE_FULL_CONTENT)) {
104    
105                            portletRequest.setAttribute(
106                                    WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY, _fileEntry);
107    
108                            return "/html/portlet/document_library/asset/" + template + ".jsp";
109                    }
110    
111                    return null;
112            }
113    
114            private final FileEntry _fileEntry;
115            private final FileShortcut _fileShortcut;
116    
117    }