AnnotationsInfoProvider.java
2.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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageInfoProvider
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.day.cq.wcm.core.impl;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageInfoProvider;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
@Component(metatype=0)
@Properties(value={@Property(name="service.description", value={"Export content paths with annotations"})})
@Service
public class AnnotationsInfoProvider
implements PageInfoProvider {
public void traverse(Node node, JSONArray annotations) throws JSONException {
try {
NodeIterator nodes = node.getNodes();
while (nodes.hasNext()) {
Node n = nodes.nextNode();
if (n.getName().equals("cq:annotations")) {
try {
if (!n.getNodes().hasNext()) continue;
annotations.put((Object)node.getPath());
}
catch (RepositoryException re) {}
continue;
}
this.traverse(n, annotations);
}
}
catch (RepositoryException re) {
// empty catch block
}
}
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
Page page = (Page)resource.adaptTo(Page.class);
Resource contentResource = page.getContentResource();
JSONArray annotations = new JSONArray();
info.put("annotations", (Object)annotations);
this.traverse((Node)contentResource.adaptTo(Node.class), annotations);
}
}