DPSManifestXMLUpdateHandler.java
3.29 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.xss.XSSAPI
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.contentsync.config.ConfigEntry
* com.day.cq.contentsync.handler.ContentUpdateHandler
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.Session
* javax.jcr.ValueFactory
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.contentsync;
import com.adobe.cq.mobile.dps.impl.metadata.ManifestXMLGenerator;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.contentsync.config.ConfigEntry;
import com.day.cq.contentsync.handler.ContentUpdateHandler;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Calendar;
import java.util.Map;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
import javax.jcr.ValueFactory;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, factory="com.day.cq.contentsync.handler.ContentUpdateHandler/publish-manifest-xml")
public class DPSManifestXMLUpdateHandler
implements ContentUpdateHandler {
private static final Logger log = LoggerFactory.getLogger(DPSManifestXMLUpdateHandler.class);
@Reference
private XSSAPI xssAPI;
public boolean updateCacheEntry(ConfigEntry configEntry, Long lastUpdated, String configCacheRoot, Session admin, Session session) {
boolean changed = false;
try {
String pagePath = configEntry.getContentPath();
Node pageNode = session.getNode(pagePath);
Node cacheFolder = session.getNode(configCacheRoot);
String cachePath = cacheFolder.getPath() + "/manifest.xml";
StringWriter buf = new StringWriter();
ManifestXMLGenerator generator1 = new ManifestXMLGenerator(this.xssAPI);
generator1.generatePKGPropertiesXMLContent(pageNode.getName() + ".html", new PrintWriter(buf), ManifestXMLGenerator.getPageMetadata(cacheFolder));
String fileContent = buf.toString();
JcrUtil.createPath((String)cachePath, (String)"sling:Folder", (String)"nt:file", (Session)admin, (boolean)false);
Node cacheContentNode = JcrUtil.createPath((String)(cachePath + "/jcr:content"), (String)"nt:resource", (Session)admin);
cacheContentNode.setProperty("jcr:data", admin.getValueFactory().createBinary((InputStream)new ByteArrayInputStream(fileContent.getBytes())));
cacheContentNode.setProperty("jcr:lastModified", Calendar.getInstance());
changed = true;
admin.save();
}
catch (Exception ex) {
log.error("Unexpected error while updating cache for config: " + configEntry.getPath(), (Throwable)ex);
}
return changed;
}
protected void bindXssAPI(XSSAPI xSSAPI) {
this.xssAPI = xSSAPI;
}
protected void unbindXssAPI(XSSAPI xSSAPI) {
if (this.xssAPI == xSSAPI) {
this.xssAPI = null;
}
}
}