CacheReporter.java
2.88 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:
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.cq.mobile.appcache.impl;
import java.util.HashSet;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class CacheReporter {
public static final String ZIP_FULL_LISTING_NAME = "pge-package.json";
public static final String ZIP_UPDATE_LISTING_NAME = "pge-package-update.json";
public static final String KEY_FILES = "files";
private Node cacheRootNode = null;
public CacheReporter(Node cacheRootNode) {
this.cacheRootNode = cacheRootNode;
}
public JSONObject getFileListingJSON(Long lastUpdated) throws RepositoryException, JSONException {
JSONObject fileListingJSON = new JSONObject();
JSONArray fileListingJSONArray = new JSONArray();
fileListingJSON.put("files", (Object)fileListingJSONArray);
this.addFileListing(fileListingJSONArray, this.cacheRootNode, this.cacheRootNode, lastUpdated);
fileListingJSON.put("count", fileListingJSONArray.length());
return fileListingJSON;
}
private void addFileListing(JSONArray fileListingJSON, Node rootNode, Node currentDirNode, Long lastUpdated) throws RepositoryException {
NodeIterator nodeIter = currentDirNode.getNodes();
while (nodeIter.hasNext()) {
Node node = nodeIter.nextNode();
if (node.isNodeType("nt:file") && node.hasNode("jcr:content")) {
if (CacheReporter.getIgnoreSet().contains(node.getName())) continue;
Property lastModified = node.getProperty("jcr:content/jcr:lastModified");
if (lastUpdated != null && lastModified.getLong() <= lastUpdated) continue;
fileListingJSON.put((Object)CacheReporter.trimBasePath(rootNode.getPath(), node.getPath()));
continue;
}
if (!node.isNodeType("nt:folder")) continue;
this.addFileListing(fileListingJSON, rootNode, node, lastUpdated);
}
}
private static Set<String> getIgnoreSet() {
HashSet<String> ignoreSet = new HashSet<String>();
ignoreSet.add("pge-package.json");
ignoreSet.add("pge-package-update.json");
return ignoreSet;
}
private static String trimBasePath(String basePath, String fullPath) {
if (fullPath.startsWith(basePath)) {
return fullPath.substring(basePath.length() + 1);
}
return fullPath;
}
}