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.repository.model.Folder;
018    import com.liferay.portal.kernel.trash.BaseTrashRenderer;
019    import com.liferay.portal.kernel.util.HtmlUtil;
020    import com.liferay.portal.kernel.workflow.WorkflowConstants;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
023    import com.liferay.portlet.asset.model.AssetRendererFactory;
024    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
025    import com.liferay.portlet.documentlibrary.model.DLFolder;
026    import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;
027    import com.liferay.portlet.trash.util.TrashUtil;
028    
029    import java.util.Locale;
030    
031    /**
032     * @author Alexander Chow
033     */
034    public class DLFolderTrashRenderer extends BaseTrashRenderer {
035    
036            public static final String TYPE = "folder";
037    
038            public DLFolderTrashRenderer(Folder folder) {
039                    _folder = folder;
040            }
041    
042            public String getClassName() {
043                    return DLFolder.class.getName();
044            }
045    
046            public long getClassPK() {
047                    return _folder.getPrimaryKey();
048            }
049    
050            @Override
051            public String getIconPath(ThemeDisplay themeDisplay) {
052                    int foldersCount = 0;
053                    int fileEntriesAndFileShortcutsCount = 0;
054    
055                    try {
056                            foldersCount = DLAppServiceUtil.getFoldersCount(
057                                    _folder.getRepositoryId(), _folder.getFolderId());
058    
059                            fileEntriesAndFileShortcutsCount =
060                                    DLAppServiceUtil.getFileEntriesAndFileShortcutsCount(
061                                            _folder.getRepositoryId(), _folder.getFolderId(),
062                                            WorkflowConstants.STATUS_APPROVED);
063                    }
064                    catch (Exception e) {
065                    }
066    
067                    if ((foldersCount + fileEntriesAndFileShortcutsCount) > 0) {
068                            return themeDisplay.getPathThemeImages() +
069                                    "/common/folder_full_document.png";
070                    }
071    
072                    return themeDisplay.getPathThemeImages() + "/common/folder_empty.png";
073            }
074    
075            public String getPortletId() {
076                    AssetRendererFactory assetRendererFactory =
077                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
078                                    DLFileEntry.class.getName());
079    
080                    return assetRendererFactory.getPortletId();
081            }
082    
083            public String getSummary(Locale locale) {
084                    return HtmlUtil.stripHtml(_folder.getDescription());
085            }
086    
087            public String getTitle(Locale locale) {
088                    return TrashUtil.getOriginalTitle(_folder.getName());
089            }
090    
091            public String getType() {
092                    return TYPE;
093            }
094    
095            private Folder _folder;
096    
097    }