ClassificationAttributeImpl.java
2.22 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
/*
* 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.ClassificationAttribute;
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 ClassificationAttributeImpl
implements ClassificationAttribute {
protected final Logger log = LoggerFactory.getLogger(ClassificationAttributeImpl.class);
protected Resource resource;
protected ValueMap properties;
public ClassificationAttributeImpl(Resource resource) throws CommerceException {
if (!this.isAttribute(resource)) {
throw new CommerceException("Resource is not a Classification.");
}
this.resource = resource;
this.properties = (ValueMap)resource.adaptTo(ValueMap.class);
}
@Override
public String getPath() {
return this.resource.getPath();
}
@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 getName() {
return (String)this.properties.get("name", (Object)"");
}
@Override
public String getUnit() {
return (String)this.properties.get("unit", (Object)"");
}
private boolean isAttribute(Resource resource) {
return this.isCommerceType(resource, "classification.attribute");
}
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);
}
}