GraniteAssetWrapper.java
3.47 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.Asset
* com.scene7.is.util.callbacks.Option
* javax.jcr.RepositoryException
* org.apache.sling.api.adapter.Adaptable
* org.apache.sling.api.resource.Resource
*/
package com.adobe.cq.dam.s7imaging.impl.jcr.adapters;
import com.adobe.cq.dam.s7imaging.impl.catalog.JcrUtil;
import com.adobe.cq.dam.s7imaging.impl.jcr.adapters.Relation;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.JcrProps;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropExtractor;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropKey;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.StandardExtractors;
import com.adobe.granite.asset.api.Asset;
import com.scene7.is.util.callbacks.Option;
import java.util.ArrayList;
import java.util.Iterator;
import javax.jcr.RepositoryException;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
public class GraniteAssetWrapper {
private static final String SLING_COLLECTION = "sling/collection";
private static final String SLING_MEMBERS = "sling:members";
private static final String RELATIONS_PATH = "jcr:content/related";
private static final String SLING_RESOURCES = "sling:resources";
private static final PropKey<Option<String>> SlingResourceType = PropKey.optional("sling:resourceType", StandardExtractors.toString);
private static final PropKey<String[]> References = PropKey.optional("sling:resources", new String[0], StandardExtractors.toStringArray);
private final Asset asset;
public static Option<GraniteAssetWrapper> graniteAssetWrapper(Adaptable asset) {
Iterator i$ = JcrUtil.adaptTo(Asset.class, asset).iterator();
if (i$.hasNext()) {
Asset a = (Asset)i$.next();
return Option.some((Object)GraniteAssetWrapper.graniteAssetWrapper(a));
}
return Option.none();
}
public static GraniteAssetWrapper graniteAssetWrapper(Asset asset) {
return new GraniteAssetWrapper(asset);
}
public Iterable<Asset> related(final String name) {
return new Iterable<Asset>(){
@Override
public Iterator<Asset> iterator() {
return GraniteAssetWrapper.this.asset.listRelated(name);
}
};
}
public Iterable<Relation> relatedRefs(String name) throws RepositoryException {
ArrayList<Relation> refs = new ArrayList<Relation>();
for (Resource relations : JcrUtil.getChild((Resource)this.asset, "jcr:content/related/" + name)) {
JcrProps props = JcrProps.jcrProps(relations);
if (Option.some((Object)"sling/collection").equals(props.get(SlingResourceType))) {
for (Resource members : JcrUtil.getChild(relations, "sling:members")) {
reference i$ = (reference)members.getChildren().iterator();
while (i$.hasNext()) {
Resource child = (Resource)i$.next();
for (Relation relation : Relation.relation((Adaptable)child)) {
refs.add(relation);
}
}
}
continue;
}
for (String ref : JcrProps.jcrProps((Resource)this.asset).get(References)) {
refs.add(Relation.relation(ref));
}
}
return refs;
}
private GraniteAssetWrapper(Asset asset) {
this.asset = asset;
}
}