MobilePagesUpdateHandler.java
3.59 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.contentsync.config.ConfigEntry
* com.day.cq.wcm.api.Page
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
*/
package com.adobe.cq.mobile.platform.impl.contentsync.handler;
import com.adobe.cq.mobile.platform.impl.contentsync.handler.AbstractPagesUpdateHandler;
import com.day.cq.contentsync.config.ConfigEntry;
import com.day.cq.wcm.api.Page;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
@Component(metatype=1, factory="com.day.cq.contentsync.handler.ContentUpdateHandler/mobileapppages", inherit=1)
public class MobilePagesUpdateHandler
extends AbstractPagesUpdateHandler {
protected static final int MAX_DEPTH_NONE = -1;
protected static final int MAX_DEPTH_DEFAULT = -1;
protected static final String PN_MAX_DEPTH = "modificationCheckMaxDepth";
@Override
protected boolean isModified(Page page, String uri, Long lastUpdated, ConfigEntry configEntry, String configCacheRoot, Session session) throws RepositoryException {
boolean modified = true;
if (this.includeOnlyModifiedPages(configEntry)) {
if (!session.nodeExists(configCacheRoot + uri)) {
return true;
}
modified = this.isModified(page, lastUpdated, 0, this.getMaxDepth(configEntry));
}
return modified;
}
private int getMaxDepth(ConfigEntry configEntry) {
int maxDepth = -1;
String maxDepthStr = configEntry.getValue("modificationCheckMaxDepth");
if (maxDepthStr != null) {
try {
maxDepth = Integer.parseInt(maxDepthStr);
}
catch (NumberFormatException e) {
// empty catch block
}
}
return maxDepth;
}
protected boolean isModified(Page page, Long lastUpdated, int currentDepth, int maxDepth) throws RepositoryException {
boolean modified = false;
if (page.getContentResource().getResourceType() == null || page.getContentResource().getResourceType().equals("cq:PageContent")) {
this.log.debug("No sling resource type detected, ignoring page" + page.getPath());
} else {
Calendar cal = page.getLastModified();
if (cal == null) {
this.log.debug("No lastmodified set on page: " + page.getPath());
cal = (Calendar)page.getProperties().get("jcr:created", Calendar.class);
}
if (cal != null) {
long lastModified = cal.getTime().getTime();
boolean bl = modified = lastUpdated < lastModified || lastModified == -1;
if (modified) {
return modified;
}
}
}
if (maxDepth == -1 || currentDepth < maxDepth) {
Iterator children = page.listChildren();
while (children.hasNext()) {
Page childPage = (Page)children.next();
boolean bl = this.isModified(childPage, lastUpdated, currentDepth + 1, maxDepth) || modified;
modified = bl;
if (!modified) continue;
return modified;
}
}
return modified;
}
}