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