BlueprintManagerImpl.java
3.36 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.Blueprint
* com.day.cq.wcm.msm.api.BlueprintManager
* com.day.cq.wcm.msm.api.RolloutConfigManager
* com.day.text.Text
* javax.jcr.RepositoryException
* org.apache.sling.api.SlingException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.Blueprint;
import com.day.cq.wcm.msm.api.BlueprintManager;
import com.day.cq.wcm.msm.api.RolloutConfigManager;
import com.day.cq.wcm.msm.impl.BlueprintImpl;
import com.day.cq.wcm.msm.impl.BlueprintManagerFactoryImpl;
import com.day.text.Text;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import javax.jcr.RepositoryException;
import org.apache.sling.api.SlingException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BlueprintManagerImpl
implements BlueprintManager {
private final Logger log = LoggerFactory.getLogger(BlueprintManagerImpl.class);
private final RolloutConfigManager rolloutConfigManager;
private final BlueprintManagerFactoryImpl factory;
private final ResourceResolver resourceResolver;
BlueprintManagerImpl(ResourceResolver resolver, RolloutConfigManager rolloutConfigManager, BlueprintManagerFactoryImpl factory) {
this.resourceResolver = resolver;
this.rolloutConfigManager = rolloutConfigManager;
this.factory = factory;
}
public Collection<Blueprint> getBlueprints() {
HashSet<BlueprintImpl> res = new HashSet<BlueprintImpl>();
try {
for (String path : this.factory.getBlueprintPaths()) {
Page page = this.getPage(path);
if (page == null) continue;
res.add(new BlueprintImpl(page, this.rolloutConfigManager));
}
}
catch (RepositoryException e) {
throw new SlingException(e.getMessage(), (Throwable)e);
}
return Collections.unmodifiableSet(res);
}
public BlueprintImpl getBlueprint(String absPath) {
try {
Page page;
if (this.factory.getBlueprintPaths().contains(absPath) && (page = this.getPage(absPath)) != null) {
return new BlueprintImpl(page, this.rolloutConfigManager);
}
}
catch (RepositoryException e) {
this.log.error("Failed to retrieve Blueprint {}", (Throwable)e);
}
return null;
}
public BlueprintImpl getContainingBlueprint(String path) {
for (Blueprint blueprint : this.getBlueprints()) {
if (blueprint.getSitePath() == null || !Text.isDescendantOrEqual((String)blueprint.getSitePath(), (String)path)) continue;
return (BlueprintImpl)blueprint;
}
return null;
}
private Page getPage(String absPath) {
Resource resource = this.resourceResolver.getResource(absPath);
if (resource == null) {
return null;
}
return (Page)resource.adaptTo(Page.class);
}
}