ClassificationImpl.java
2.65 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.commerce.impl.classification;
import com.adobe.cq.commerce.api.CommerceException;
import com.adobe.cq.commerce.api.classification.Classification;
import com.adobe.cq.commerce.api.classification.ClassificationCategory;
import com.adobe.cq.commerce.impl.classification.ClassificationCategoryImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ClassificationImpl
implements Classification {
protected static final String NN_ROOT_CATEGORY = "rootcategory";
protected final Logger log = LoggerFactory.getLogger(ClassificationImpl.class);
protected Resource resource;
protected ValueMap properties;
public ClassificationImpl(Resource resource) throws CommerceException {
if (!this.isClassification(resource)) {
throw new CommerceException("Resource is not a Classification.");
}
this.resource = resource;
this.properties = (ValueMap)resource.adaptTo(ValueMap.class);
}
@Override
public String getTitle() {
return (String)this.properties.get("jcr:title", (Object)"");
}
@Override
public String getDescription() {
return (String)this.properties.get("jcr:description", (Object)"");
}
@Override
public String getPath() {
return this.resource.getPath();
}
@Override
public ClassificationCategory getRootCategory() {
ClassificationCategoryImpl rootCategory = null;
Resource rootCategoryRes = this.resource.getChild("rootcategory");
try {
rootCategory = new ClassificationCategoryImpl(rootCategoryRes);
}
catch (CommerceException e) {
this.log.error("The resource at " + rootCategoryRes.getPath() + " is not a category", (Throwable)e);
}
return rootCategory;
}
private boolean isClassification(Resource resource) {
return this.isCommerceType(resource, "classification");
}
private boolean isCommerceType(Resource res, String value) {
if (res == null) {
return false;
}
ValueMap properties = (ValueMap)res.adaptTo(ValueMap.class);
String commerceType = (String)properties.get("cq:commerceType", String.class);
return StringUtils.equals((String)commerceType, (String)value);
}
}