EmulatorInfoProvider.java
3.85 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.PageInfoProvider
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.emulator.impl;
import com.day.cq.wcm.api.PageInfoProvider;
import com.day.cq.wcm.emulator.Emulator;
import com.day.cq.wcm.emulator.EmulatorGroup;
import com.day.cq.wcm.emulator.EmulatorService;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={PageInfoProvider.class})
public class EmulatorInfoProvider
implements PageInfoProvider {
private static final Logger log = LoggerFactory.getLogger(EmulatorInfoProvider.class);
@Reference
private EmulatorService emulatorService;
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
JSONObject entries = new JSONObject();
List<EmulatorGroup> emulatorGroups = this.emulatorService.getEmulatorGroups(resource);
if (!emulatorGroups.isEmpty()) {
JSONObject groups = new JSONObject();
for (EmulatorGroup emulatorGroup : emulatorGroups) {
String path = emulatorGroup.getPath();
JSONObject group = new JSONObject();
group.put("title", (Object)emulatorGroup.getTitle());
group.put("description", (Object)emulatorGroup.getDescription());
group.put("path", (Object)(StringUtils.isNotBlank((String)path) ? path : JSONObject.NULL));
for (Emulator emulator : emulatorGroup.getEmulators()) {
if (null == emulator) continue;
JSONObject entry = new JSONObject();
entry.put("text", (Object)emulator.getTitle());
String desc = emulator.getDescription();
if (desc != null) {
entry.put("description", (Object)desc);
}
entry.put("action", (Object)"start");
entry.put("path", (Object)emulator.getPath());
entry.put("canRotate", emulator.canRotate());
entry.put("hasTouchScrolling", emulator.hasTouchScrolling());
entry.put("contentCssPath", (Object)(request.getContextPath() + emulator.getContentCssPath()));
entry.put("width", emulator.getWidth());
entry.put("height", emulator.getHeight());
entry.put("device-pixel-ratio", emulator.getPixelRatio());
group.put(emulator.getName(), (Object)entry);
groups.put(emulatorGroup.getName(), (Object)group);
}
entries.put("groups", (Object)groups);
}
}
info.put("emulators", (Object)entries);
}
protected void bindEmulatorService(EmulatorService emulatorService) {
this.emulatorService = emulatorService;
}
protected void unbindEmulatorService(EmulatorService emulatorService) {
if (this.emulatorService == emulatorService) {
this.emulatorService = null;
}
}
}