ProductReferenceProvider.java
2.34 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.reference.Reference
* com.day.cq.wcm.api.reference.ReferenceProvider
* javax.jcr.Node
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
*/
package com.adobe.cq.commerce.impl;
import com.adobe.cq.commerce.common.AbstractJcrProduct;
import com.day.cq.wcm.api.reference.Reference;
import com.day.cq.wcm.api.reference.ReferenceProvider;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import javax.jcr.Node;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
@Component
@Service(value={ReferenceProvider.class})
public class ProductReferenceProvider
implements ReferenceProvider {
public List<Reference> findReferences(Resource resource) {
return this.recurse(resource, new ArrayList<Reference>());
}
private List<Reference> recurse(Resource resource, ArrayList<Reference> references) {
Node node = (Node)resource.adaptTo(Node.class);
if (node == null) {
return references;
}
if (AbstractJcrProduct.isAProductOrVariant(resource)) {
Resource pimProduct;
String productDataPath = (String)ResourceUtil.getValueMap((Resource)resource).get("productData", String.class);
Resource resource2 = pimProduct = productDataPath != null ? resource.getResourceResolver().getResource(productDataPath) : null;
if (pimProduct != null) {
Calendar mod = (Calendar)ResourceUtil.getValueMap((Resource)pimProduct).get("jcr:lastModified", Calendar.class);
long lastModified = mod != null ? mod.getTimeInMillis() : -1;
references.add(new Reference("product", pimProduct.getName(), pimProduct, lastModified));
}
}
Iterator it = resource.listChildren();
while (it.hasNext()) {
this.recurse((Resource)it.next(), references);
}
return references;
}
}