DocumentFragmentCFViewQuery.java
3.32 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.adobe.icc.helper.util.CMAssetsQuery
* com.day.cq.wcm.core.contentfinder.Hit
* com.day.cq.wcm.core.contentfinder.ViewQuery
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.adaddon.internal.servlet;
import com.adobe.icc.helper.util.CMAssetsQuery;
import com.day.cq.wcm.core.contentfinder.Hit;
import com.day.cq.wcm.core.contentfinder.ViewQuery;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DocumentFragmentCFViewQuery
implements ViewQuery {
private static Logger logger = LoggerFactory.getLogger(DocumentFragmentCFViewQuery.class);
private final SlingHttpServletRequest request;
private final CMAssetsQuery query;
private final Session session;
private static final String DAM_ASSET = "dam:Asset";
private static final String NAME_PROP = "name";
private static final String PATH_PROP = "path";
private static final String DESC_PROP = "desc";
private static final String THUMBNAIL_PATH_PROP = "thumbnail_path";
private static final String CM_ASSET_THUMBNAIL_SUFFIX = "/renditions/thumbnail.319.319.png";
private static final String DAM_ASSET_THUMBNAIL_SUFFIX = ".thumb.319.319.png";
public DocumentFragmentCFViewQuery(SlingHttpServletRequest request, Session session, CMAssetsQuery query) {
this.request = request;
this.query = query;
this.session = session;
}
public Collection<Hit> execute() {
try {
return this.executeQuery(this.request.getResourceResolver(), this.session, this.query);
}
catch (RepositoryException e) {
logger.error("Error executing query " + (Object)this.query, (Throwable)e);
return new ArrayList<Hit>();
}
}
private List<Hit> executeQuery(ResourceResolver resolver, Session session, CMAssetsQuery query) throws RepositoryException {
ArrayList<Hit> hits = new ArrayList<Hit>();
List qr = query.execute();
for (Properties props : qr) {
Hit hit;
if (props == null || (hit = this.createHit(props)) == null) continue;
hits.add(hit);
}
return hits;
}
private Hit createHit(Properties props) {
if (props != null) {
Hit hit = new Hit();
hit.set("name", props.get("name"));
hit.set("desc", props.get("desc"));
String path = (String)props.get("id");
hit.set("path", (Object)path);
if (this.isImage(path)) {
hit.set("thumbnail_path", (Object)(path + ".thumb.319.319.png"));
} else {
hit.set("thumbnail_path", (Object)(path + "/renditions/thumbnail.319.319.png"));
}
return hit;
}
return null;
}
private boolean isImage(String path) {
return path.startsWith("/content/dam");
}
}