001    /**
002     * Copyright (c) 2000-2012 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            public String getClassName() {
052                    return DLFileShortcut.class.getName();
053            }
054    
055            public long getClassPK() {
056                    return _fileShortcut.getPrimaryKey();
057            }
058    
059            @Override
060            public String getIconPath(ThemeDisplay themeDisplay) {
061                    return themeDisplay.getPathThemeImages() + "/file_system/small/" +
062                            _fileEntry.getIcon() + ".png";
063            }
064    
065            public String getPortletId() {
066                    return PortletKeys.DOCUMENT_LIBRARY;
067            }
068    
069            public String getSummary(Locale locale) {
070                    return HtmlUtil.stripHtml(_fileEntry.getDescription());
071            }
072    
073            public String getTitle(Locale locale) {
074                    return LanguageUtil.format(
075                            locale, "shortcut-to-x", _fileShortcut.getToTitle());
076            }
077    
078            public String getType() {
079                    return TYPE;
080            }
081    
082            @Override
083            public String render(
084                            RenderRequest renderRequest, RenderResponse renderResponse,
085                            String template)
086                    throws Exception {
087    
088                    if (template.equals(AssetRenderer.TEMPLATE_ABSTRACT) ||
089                            template.equals(AssetRenderer.TEMPLATE_FULL_CONTENT)) {
090    
091                            renderRequest.setAttribute(
092                                    WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY, _fileEntry);
093    
094                            return "/html/portlet/document_library/asset/" + template + ".jsp";
095                    }
096    
097                    return null;
098            }
099    
100            private FileEntry _fileEntry;
101            private DLFileShortcut _fileShortcut;
102    
103    }