com.adobe.cq.social.filelibrary.client.api.AbstractAsset Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2012 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.cq.social.filelibrary.client.api;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.cq.social.commons.comments.api.AbstractComment;
import com.adobe.cq.social.commons.comments.listing.CommentSocialComponentListProviderManager;
import com.adobe.cq.social.scf.ClientUtilities;
import com.adobe.cq.social.scf.CollectionPagination;
import com.adobe.cq.social.commons.comments.api.PageInfo;
import com.adobe.cq.social.scf.QueryRequestInfo;
import com.adobe.cq.social.scf.SocialComponent;
import com.adobe.cq.social.scf.core.DefaultResourceID;
import com.adobe.cq.social.scf.core.ResourceID;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public abstract class AbstractAsset extends AbstractComment implements
Asset {
private static final String TOPIC_HTML_SUFFIX = ".asset.html";
private final String name;
private final Resource parent;
protected ValueMap properties;
protected final boolean isFolder;
protected PageInfo pageInfo;
private CommentSocialComponentListProviderManager listProviderManager;
private static final Logger LOG = LoggerFactory.getLogger(AbstractAsset.class);
public AbstractAsset(final Resource resource, final ClientUtilities clientUtils,
final CommentSocialComponentListProviderManager listProviderManager) throws RepositoryException {
this(resource, clientUtils, QueryRequestInfo.DEFAULT_QUERY_INFO_FACTORY.create(), listProviderManager);
}
/**
* Constructor of an asset.
* @param resource the specified resource
* @param clientUtils the client utilities instance
* @param queryInfo {@link QueryRequestInfo}
* @param listProviderManager {@link CommentSocialComponentListProviderManager}
* @throws RepositoryException if an error occurs
*/
public AbstractAsset(final Resource resource, final ClientUtilities clientUtils,
final QueryRequestInfo queryInfo, final CommentSocialComponentListProviderManager listProviderManager)
throws RepositoryException {
super(resource, clientUtils, queryInfo, listProviderManager);
if (queryInfo.isSortRequest()) {
this.pageInfo = new PageInfo(this, clientUtils, queryInfo.getPagination());
} else {
this.pageInfo = super.getPageInfo();
}
properties = ResourceUtil.getValueMap(resource);
name = properties.get(Asset.PN_NAME, String.class);
parent = FileLibraryUtils.getParent(resource, false);
isFolder = resource.getResourceResolver().isResourceType(resource, FileLibrary.RESOURCE_TYPE_FOLDER);
this.listProviderManager = listProviderManager;
}
public List getBreadcrumbs() {
final List breadcrumbs = new ArrayList();
buildBreadcrumbs(resource, breadcrumbs, true);
Collections.reverse(breadcrumbs);
return breadcrumbs;
}
private void buildBreadcrumbs(final Resource resource, final List breadcrumbs,
final boolean current) {
if (resource != null
&& (resource.isResourceType(FileLibrary.RESOURCE_TYPE_DOCUMENT) || resource
.isResourceType(FileLibrary.RESOURCE_TYPE_FOLDER))) {
breadcrumbs.add(new FileLibraryBreadcrumb(resource, current));
buildBreadcrumbs(resource.getParent(), breadcrumbs, false);
}
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isFolder() {
return isFolder;
}
/**
* {@inheritDoc}
*/
@Override
public String getFileLibraryId() {
return getParentId();
}
@Override
public boolean isFileLibraryClosed() {
return false;
}
@Override
public String getFriendlyUrl() {
final String pagePath = clientUtils.getSocialUtils().getContainingPage(parent).getPath();
ResourceID urlid = this.id;
if (!isFolder()) {
urlid = new DefaultResourceID(getResource());
}
// TODO:
return clientUtils.externalLink(pagePath, false) + TOPIC_HTML_SUFFIX + urlid + ".html";
}
@Override
public void setPagination(final CollectionPagination pagination) {
super.setPagination(pagination);
}
@Override
public T createConfiguration(final Resource resource, final Resource cs) {
return (T) new AbstractFileLibraryConfiguration(cs);
}
@Override
public String getParentName() {
final SocialComponent parent = this.getParentComponent();
if (parent == null || !(parent instanceof Asset)) {
return null;
}
final Asset parentAsset = (Asset) this.getParentComponent();
return parentAsset.getName();
}
@Override
public String getParentFriendlyUrl() {
final SocialComponent parent = this.getParentComponent();
if (parent == null) {
return null;
}
return parent.getFriendlyUrl();
}
@Override
public PageInfo getPageInfo() {
return this.pageInfo;
}
}