ProjectBreadcrumbResolver.java 2.54 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.projects.api.Project
 *  com.adobe.granite.taskmanagement.Task
 *  com.day.cq.i18n.I18n
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 */
package com.adobe.cq.projects.ui.impl.navigation;

import com.adobe.cq.projects.api.Project;
import com.adobe.cq.projects.ui.Breadcrumb;
import com.adobe.cq.projects.ui.impl.navigation.BreadcrumbResolver;
import com.adobe.granite.taskmanagement.Task;
import com.day.cq.i18n.I18n;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;

public class ProjectBreadcrumbResolver
implements BreadcrumbResolver {
    private static final String PROJECTS_CONTENT_ROOT = "/content/projects";
    private static final String RT_PROJECT_FOLDER = "cq/gui/components/projects/admin/card/foldercard";

    @Override
    public List<Breadcrumb> resolve(I18n i18n, Resource resource) {
        List<Breadcrumb> breadcrumbs = this.getProjectBreadcrumbs(i18n, resource);
        Collections.reverse(breadcrumbs);
        return breadcrumbs;
    }

    protected List<Breadcrumb> getProjectBreadcrumbs(I18n i18n, Resource resource) {
        ArrayList<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();
        Resource currentResource = resource;
        if (currentResource != null && currentResource.getPath().startsWith("/content/projects")) {
            while (currentResource != null && !"/content/projects".equals(currentResource.getPath())) {
                Project project = (Project)currentResource.adaptTo(Project.class);
                if (project != null) {
                    breadcrumbs.add(new Breadcrumb(project.getTitle(), "/projects/details.html" + currentResource.getPath()));
                } else if ("cq/gui/components/projects/admin/card/foldercard".equals(currentResource.getResourceType())) {
                    String title = (String)currentResource.getValueMap().get("jcr:title", (Object)currentResource.getName());
                    breadcrumbs.add(new Breadcrumb(title, "/projects.html" + currentResource.getPath()));
                }
                currentResource = currentResource.getParent();
            }
        }
        breadcrumbs.add(new Breadcrumb(i18n.get("Projects"), "/projects.html/content/projects"));
        return breadcrumbs;
    }

    @Override
    public boolean canResolve(Resource resource) {
        return resource.adaptTo(Task.class) == null;
    }
}