DeviceImpl.java
2.12 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.annotation.CheckForNull
* javax.annotation.Nonnull
* org.apache.jackrabbit.api.security.user.User
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.screens.device.impl;
import com.adobe.cq.screens.device.Device;
import com.adobe.cq.screens.device.DeviceConfig;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public class DeviceImpl
implements Device {
private Resource resource;
private String id;
public DeviceImpl(Resource resource, String id) {
this.resource = resource;
this.id = id;
}
@Override
public String getPath() {
return this.resource.getPath();
}
@Override
public String getId() {
return this.id;
}
@Override
public DeviceConfig getDeviceConfig() {
Resource profile = this.getProfile();
String cfgPath = profile == null ? null : (String)profile.getValueMap().get("configPath", String.class);
Resource r = cfgPath == null ? null : this.resource.getResourceResolver().getResource(cfgPath);
return r == null ? null : (DeviceConfig)r.adaptTo(DeviceConfig.class);
}
@CheckForNull
private Resource getProfile() {
return this.resource.getChild("profile_screens");
}
public <AdapterType> AdapterType adaptTo(@Nonnull Class<AdapterType> type) {
if (type == User.class) {
return (AdapterType)this.resource.adaptTo(type);
}
if (type == ValueMap.class) {
Resource profile = this.getProfile();
return (AdapterType)(profile == null ? ValueMap.EMPTY : (ValueMap)profile.adaptTo(ValueMap.class));
}
if (type == Resource.class) {
return (AdapterType)this.resource;
}
return null;
}
}