DPSTOCUpdateHandler.java
3.13 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.contentsync.config.ConfigEntry
* com.day.cq.contentsync.handler.AbstractSlingResourceUpdateHandler
* com.day.cq.wcm.foundation.Image
* javax.jcr.Node
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.jcr.resource.JcrResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.contentsync;
import com.adobe.cq.mobile.dps.impl.utils.DPSUtil;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.contentsync.config.ConfigEntry;
import com.day.cq.contentsync.handler.AbstractSlingResourceUpdateHandler;
import com.day.cq.wcm.foundation.Image;
import java.util.Calendar;
import java.util.Date;
import javax.jcr.Node;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, factory="com.day.cq.contentsync.handler.ContentUpdateHandler/publish-toc")
public class DPSTOCUpdateHandler
extends AbstractSlingResourceUpdateHandler {
private static final Logger log = LoggerFactory.getLogger(DPSTOCUpdateHandler.class);
public boolean updateCacheEntry(ConfigEntry configEntry, Long lastUpdated, String configCacheRoot, Session admin, Session session) {
try {
boolean changed = false;
ResourceResolver resolver = this.resolverFactory.getResourceResolver(admin);
String nodeContainingImageNodePath = configEntry.getContentPath() + "/jcr:content";
String imageNodePath = nodeContainingImageNodePath + "/image";
if (DPSUtil.isImageSet(resolver.getResource(imageNodePath))) {
Image img = new Image(resolver.getResource(nodeContainingImageNodePath));
img.setItemName("file", "image");
img.setItemName("fileReference", "imageReference");
img.setSelector("img");
if (img.getLastModified() == null || lastUpdated < img.getLastModified().getTime().getTime()) {
this.renderResource(img.getHref(), configCacheRoot, admin, session);
admin.save();
changed = true;
}
} else {
String defaultTOCImagePath = "/libs/media/publishing/content/defaultFolioContent/toc.png";
JcrUtil.copy((Node)admin.getNode(defaultTOCImagePath), (Node)admin.getNode(configCacheRoot), (String)"toc.png", (boolean)true);
changed = true;
}
return changed;
}
catch (Exception ex) {
log.error("Unexpected error while updating cache for config: " + configEntry.getPath(), (Throwable)ex);
return false;
}
}
protected String getTargetPath(String path) {
return "/toc.png";
}
}