ProjectBreadcrumbResolver.java
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* 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;
}
}