DeviceConfigImpl.java
1.97 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.text.Text
* javax.annotation.Nonnull
* javax.jcr.Node
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.screens.device.impl;
import com.adobe.cq.screens.device.DeviceConfig;
import com.day.cq.wcm.api.Page;
import com.day.text.Text;
import javax.annotation.Nonnull;
import javax.jcr.Node;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
public class DeviceConfigImpl
implements DeviceConfig {
private final Resource pageResource;
private final Resource contentResource;
public DeviceConfigImpl(Resource resource) {
if ("jcr:content".equals(resource.getName())) {
this.contentResource = resource;
this.pageResource = resource.getParent();
} else {
this.contentResource = resource.getChild("jcr:content");
this.pageResource = resource;
}
}
@Override
public String getPath() {
return this.pageResource.getPath();
}
@Nonnull
@Override
public String getDisplayPath() {
return Text.getRelativeParent((String)this.getPath(), (int)1);
}
@Override
public String getAssignedDeviceId() {
return (String)((ValueMap)this.contentResource.adaptTo(ValueMap.class)).get("deviceId", String.class);
}
public <AdapterType> AdapterType adaptTo(@Nonnull Class<AdapterType> type) {
if (type == Page.class) {
return (AdapterType)this.pageResource.adaptTo(type);
}
if (type == ValueMap.class) {
return (AdapterType)this.contentResource.adaptTo(type);
}
if (type == Resource.class) {
return (AdapterType)this.contentResource;
}
if (type == Node.class) {
return (AdapterType)this.pageResource.adaptTo(type);
}
return null;
}
}