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            @Override
052            public String getIconPath(ThemeDisplay themeDisplay) {
053                    return themeDisplay.getPathThemeImages() + "/file_system/small/" +
054                            _fileEntry.getIcon() + ".png";
055            }
056    
057            public String getPortletId() {
058                    return PortletKeys.DOCUMENT_LIBRARY;
059            }
060    
061            @Override
062            public String getRestorePath(RenderRequest renderRequest) {
063                    if (_fileShortcut.isInTrashFolder()) {
064                            renderRequest.setAttribute(
065                                    WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY, _fileEntry);
066                            renderRequest.setAttribute(
067                                    WebKeys.DOCUMENT_LIBRARY_FILE_SHORTCUT, _fileShortcut);
068    
069                            return
070                                    "/html/portlet/document_library/trash/file_entry_restore.jsp";
071                    }
072    
073                    return null;
074            }
075    
076            public String getSummary(Locale locale) {
077                    return HtmlUtil.stripHtml(_fileEntry.getDescription());
078            }
079    
080            public String getTitle(Locale locale) {
081                    return LanguageUtil.format(
082                            locale, "shortcut-to-x", _fileShortcut.getToTitle());
083            }
084    
085            public String getType() {
086                    return TYPE;
087            }
088    
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    }