/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.document.library.web.asset;
import com.liferay.asset.kernel.model.AssetRenderer;
import com.liferay.asset.kernel.model.AssetRendererFactory;
import com.liferay.asset.kernel.model.BaseAssetRendererFactory;
import com.liferay.document.library.kernel.model.DLFolder;
import com.liferay.document.library.kernel.service.DLAppLocalService;
import com.liferay.document.library.web.constants.DLPortletKeys;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.portlet.LiferayPortletURL;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
import com.liferay.trash.TrashHelper;
import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;
import javax.portlet.WindowState;
import javax.portlet.WindowStateException;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Alexander Chow
*/
@Component(
immediate = true,
property = {"javax.portlet.name=" + DLPortletKeys.DOCUMENT_LIBRARY},
service = AssetRendererFactory.class
)
public class DLFolderAssetRendererFactory
extends BaseAssetRendererFactory<Folder> {
public static final String TYPE = "document_folder";
public DLFolderAssetRendererFactory() {
setCategorizable(false);
setPortletId(DLPortletKeys.DOCUMENT_LIBRARY);
setSearchable(true);
}
@Override
public AssetRenderer<Folder> getAssetRenderer(long classPK, int type)
throws PortalException {
Folder folder = _dlAppLocalService.getFolder(classPK);
DLFolderAssetRenderer dlFolderAssetRenderer = new DLFolderAssetRenderer(
folder, _trashHelper);
dlFolderAssetRenderer.setAssetRendererType(type);
return dlFolderAssetRenderer;
}
@Override
public String getClassName() {
return DLFolder.class.getName();
}
@Override
public String getIconCssClass() {
return "folder";
}
@Override
public String getType() {
return TYPE;
}
@Override
public PortletURL getURLView(
LiferayPortletResponse liferayPortletResponse,
WindowState windowState) {
LiferayPortletURL liferayPortletURL =
liferayPortletResponse.createLiferayPortletURL(
DLPortletKeys.DOCUMENT_LIBRARY, PortletRequest.RENDER_PHASE);
try {
liferayPortletURL.setWindowState(windowState);
}
catch (WindowStateException wse) {
}
return liferayPortletURL;
}
@Override
public boolean hasPermission(
PermissionChecker permissionChecker, long classPK, String actionId)
throws Exception {
Folder folder = _dlAppLocalService.getFolder(classPK);
return DLFolderPermission.contains(permissionChecker, folder, actionId);
}
@Reference(unbind = "-")
protected void setDLAppLocalService(DLAppLocalService dlAppLocalService) {
_dlAppLocalService = dlAppLocalService;
}
private DLAppLocalService _dlAppLocalService;
@Reference
private TrashHelper _trashHelper;
}