DefaultPageStatusProvider.java
13.6 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.xss.XSSAPI
* com.day.cq.wcm.api.LanguageManager
* com.day.cq.wcm.api.LanguageManager$Info
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageInfoProvider
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.Revision
* com.day.cq.wcm.api.Template
* com.day.cq.wcm.api.designer.Design
* com.day.cq.wcm.api.designer.Designer
* com.day.cq.wcm.commons.Constants
* com.day.cq.workflow.WorkflowException
* com.day.cq.workflow.WorkflowService
* com.day.cq.workflow.WorkflowSession
* com.day.cq.workflow.exec.Workflow
* com.day.cq.workflow.metadata.MetaDataMap
* com.day.cq.workflow.model.WorkflowModel
* com.day.cq.workflow.status.WorkflowStatus
* javax.jcr.PathNotFoundException
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.commons.lang.time.FastDateFormat
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* 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.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.core.impl;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.wcm.api.LanguageManager;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageInfoProvider;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.Revision;
import com.day.cq.wcm.api.Template;
import com.day.cq.wcm.api.designer.Design;
import com.day.cq.wcm.api.designer.Designer;
import com.day.cq.wcm.commons.Constants;
import com.day.cq.wcm.core.impl.components.ComponentCache;
import com.day.cq.wcm.core.utils.PageInfoUtils;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowService;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.Workflow;
import com.day.cq.workflow.metadata.MetaDataMap;
import com.day.cq.workflow.model.WorkflowModel;
import com.day.cq.workflow.status.WorkflowStatus;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
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.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONArray;
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)
@Property(name="service.description", value={"Export meta data related to a pages"})
@Service(value={PageInfoProvider.class})
public class DefaultPageStatusProvider
implements PageInfoProvider {
private static final Logger log = LoggerFactory.getLogger(DefaultPageStatusProvider.class);
private static final String SKIP_WORKFLOW = "skipWorkflow";
@Reference
private LanguageManager langMgr = null;
@Reference
private WorkflowService workflowService = null;
@Reference
private ComponentCache componentCache = null;
@Reference
private XSSAPI xssAPI;
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
Template template;
String skipWorkflowModels = request.getParameter("skipWorkflow");
String path = resource.getPath();
Page page = (Page)resource.adaptTo(Page.class);
ResourceResolver resolver = resource.getResourceResolver();
PageManager pageMgr = (PageManager)resolver.adaptTo(PageManager.class);
Designer designer = (Designer)resolver.adaptTo(Designer.class);
Design design = designer == null ? null : designer.getDesign(page);
Session session = (Session)resolver.adaptTo(Session.class);
JSONObject status = new JSONObject();
info.put("status", (Object)status);
status.put("path", (Object)path);
info.put("isPage", page != null);
if (page != null) {
info.put("pageResourceType", (Object)page.getContentResource().getResourceType());
info.put("pageResourceSuperType", (Object)page.getContentResource().getResourceSuperType());
status.put("isLocked", page.isLocked());
status.put("lockOwner", (Object)(page.getLockOwner() == null ? "" : page.getLockOwner()));
status.put("canUnlock", page.canUnlock());
Calendar lastModified = page.getLastModified();
status.put("lastModified", lastModified != null ? lastModified.getTimeInMillis() : 0);
status.put("lastModifiedBy", (Object)page.getLastModifiedBy());
Calendar onTime = page.getOnTime();
Calendar offTime = page.getOffTime();
status.put("timeUntilValid", page.timeUntilValid());
status.put("onTime", onTime != null ? onTime.getTimeInMillis() : 0);
status.put("offTime", offTime != null ? offTime.getTimeInMillis() : 0);
status.put("replication", (Object)PageInfoUtils.getReplicationStateObject(resource, this.xssAPI));
try {
if (design != null) {
status.put("isDesignable", session.hasPermission(design.getPath() + "/testProp", "set_property"));
}
}
catch (RepositoryException e) {
log.warn("Failed to check permission on design: {}", (Throwable)e);
}
try {
status.put("isDeveloper", session.hasPermission("/apps", "add_node"));
}
catch (RepositoryException e) {
log.warn("Failed to check permission on application: {}", (Throwable)e);
}
}
JSONObject workflow = new JSONObject();
info.put("workflow", (Object)workflow);
Workflow wf = null;
WorkflowStatus wfState = (WorkflowStatus)resource.adaptTo(WorkflowStatus.class);
if (wfState != null) {
workflow.put("isRunning", wfState.isInRunningWorkflow());
wf = wfState.getWorkflow();
if (wf != null) {
workflow.put("id", (Object)wf.getId());
workflow.put("state", (Object)wf.getState());
}
}
if (skipWorkflowModels == null || skipWorkflowModels.equals("false")) {
JSONObject workflows = new JSONObject();
info.put("workflows", (Object)workflows);
try {
WorkflowSession wfSession = this.workflowService.getWorkflowSession(session);
WorkflowModel[] models = wfSession.getModels();
JSONObject wcm = new JSONObject();
workflows.put("wcm", (Object)wcm);
JSONArray jModels = new JSONArray();
for (WorkflowModel model : models) {
if (!this.doInclude(model, new String[]{"wcm"}, false)) continue;
JSONObject jModel = new JSONObject();
jModel.put("wid", (Object)model.getId());
jModel.put("label", (Object)model.getTitle());
if (this.xssAPI != null) {
jModel.put("label_xss", (Object)this.xssAPI.filterHTML(model.getTitle()));
}
jModels.put((Object)jModel);
}
wcm.put("models", (Object)jModels);
JSONArray tjModels = new JSONArray();
for (WorkflowModel model2 : models) {
if (!this.doInclude(model2, new String[]{"wcm.translation"}, false)) continue;
JSONObject jModel = new JSONObject();
jModel.put("wid", (Object)model2.getId());
jModel.put("label", (Object)model2.getTitle());
if (this.xssAPI != null) {
jModel.put("label_xss", (Object)this.xssAPI.filterHTML(model2.getTitle()));
}
tjModels.put((Object)jModel);
}
JSONObject translation = new JSONObject();
workflows.put("translation", (Object)translation);
translation.put("models", (Object)tjModels);
}
catch (WorkflowException e) {
if (e.getCause() instanceof PathNotFoundException) {
log.info("Can't access workflow models; maybe missing or due to access restrictions.");
}
log.error("Error while retrieving workflow models.", (Throwable)e);
}
}
JSONObject translation = new JSONObject();
info.put("translation", (Object)translation);
if (wf != null) {
try {
String srcPath = (String)wf.getMetaDataMap().get("srcPath", String.class);
if (srcPath == null) {
Map infos = this.langMgr.getAdjacentLanguageInfo(resolver, path);
if (infos == null || infos.isEmpty()) {
log.warn("resource {} not below language root?.", (Object)path);
} else {
srcPath = ((LanguageManager.Info)infos.values().iterator().next()).getPath();
}
}
if (srcPath != null && pageMgr.getPage(srcPath) != null) {
Collection revisions = pageMgr.getRevisions(srcPath, null);
JSONObject original = new JSONObject();
translation.put("original", (Object)original);
original.put("path", (Object)srcPath);
JSONArray versions = new JSONArray();
original.put("versions", (Object)versions);
for (Revision r : revisions) {
JSONObject rev = new JSONObject();
versions.put((Object)rev);
rev.put("id", (Object)r.getId());
rev.put("label", (Object)r.getLabel());
rev.put("name", (Object)r.getName());
rev.put("title", (Object)r.getTitle());
rev.put("comment", (Object)r.getComment());
Calendar createdDate = r.getCreated();
rev.put("created", (Object)Constants.DATE_DEFAULT.format(createdDate.getTime()));
rev.put("deleted", r.isDeleted());
}
}
}
catch (Exception e) {
log.error("Error while retrieving translation info.", (Throwable)e);
}
}
if (design != null) {
Calendar lm = design.getLastModified();
JSONObject obj = new JSONObject();
obj.put("path", (Object)design.getPath());
obj.put("lastModified", lm == null ? 0 : lm.getTimeInMillis());
info.put("design", (Object)obj);
}
if (page != null && (template = page.getTemplate()) != null && template.hasStructureSupport()) {
Calendar lm = design.getLastModified();
JSONObject obj = new JSONObject();
obj.put("path", (Object)(template.getPath() + "/policies"));
obj.put("lastModified", lm == null ? 0 : lm.getTimeInMillis());
info.put("design", (Object)obj);
}
info.put("componentsRef", (Object)("/libs/wcm/core/content/components." + this.componentCache.getLastModified() + ".json"));
}
private boolean doInclude(WorkflowModel model, String[] tags, boolean doStrict) {
String[] tagStrSplits;
if (tags.length == 0) {
return true;
}
MetaDataMap metaData = model.getMetaDataMap();
String tagStr = (String)metaData.get("tags", String.class);
String[] arrstring = tagStrSplits = tagStr != null && !tagStr.equals("") ? tagStr.trim().split(",") : new String[]{};
if (tagStrSplits.length == 0 && !doStrict) {
return true;
}
for (String tag : tagStrSplits) {
for (String checkTag : tags) {
if (!checkTag.equals(tag)) continue;
return true;
}
}
return false;
}
protected void bindLangMgr(LanguageManager languageManager) {
this.langMgr = languageManager;
}
protected void unbindLangMgr(LanguageManager languageManager) {
if (this.langMgr == languageManager) {
this.langMgr = null;
}
}
protected void bindWorkflowService(WorkflowService workflowService) {
this.workflowService = workflowService;
}
protected void unbindWorkflowService(WorkflowService workflowService) {
if (this.workflowService == workflowService) {
this.workflowService = null;
}
}
protected void bindComponentCache(ComponentCache componentCache) {
this.componentCache = componentCache;
}
protected void unbindComponentCache(ComponentCache componentCache) {
if (this.componentCache == componentCache) {
this.componentCache = null;
}
}
protected void bindXssAPI(XSSAPI xSSAPI) {
this.xssAPI = xSSAPI;
}
protected void unbindXssAPI(XSSAPI xSSAPI) {
if (this.xssAPI == xSSAPI) {
this.xssAPI = null;
}
}
}