JcrPaymentMethodImpl.java
3.39 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
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.ImageResource
* com.day.cq.wcm.api.Page
* org.apache.commons.lang.StringUtils
* org.apache.sling.adapter.SlingAdaptable
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
*/
package com.adobe.cq.commerce.impl;
import com.adobe.cq.commerce.api.CommerceException;
import com.adobe.cq.commerce.api.PaymentMethod;
import com.day.cq.commons.ImageResource;
import com.day.cq.wcm.api.Page;
import java.util.Iterator;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.adapter.SlingAdaptable;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
public class JcrPaymentMethodImpl
extends SlingAdaptable
implements PaymentMethod {
public static final String RESOURCE_TYPE = "commerce/components/paymentmethod";
protected Page page;
protected Resource resource;
public JcrPaymentMethodImpl(Resource resource) throws CommerceException {
this.page = (Page)resource.adaptTo(Page.class);
if (this.page == null || !ResourceUtil.isA((Resource)resource.getChild("jcr:content"), (String)"commerce/components/paymentmethod")) {
throw new CommerceException("Resource is not a commerce/components/paymentmethod");
}
this.resource = this.page.getContentResource();
}
@Override
public String getPath() {
return this.page.getPath();
}
@Override
public String getPredicate() {
return (String)ResourceUtil.getValueMap((Resource)this.resource).get("predicate", (Object)"payment");
}
@Override
public String getTitle() {
return this.page.getTitle();
}
@Override
public String getDescription() {
return this.page.getDescription();
}
@Override
public String getImageUrl(String selector) {
Resource image = this.resource.getChild("image");
if (image != null) {
if (image.getChild("file") != null) {
selector = StringUtils.isEmpty((String)selector) ? ".thumb" : (selector.startsWith(".") ? ".thumb" + selector : ".thumb." + selector);
return this.page.getPath() + selector + ".png";
}
ImageResource imageResource = new ImageResource(image);
if (StringUtils.isNotEmpty((String)selector)) {
imageResource.setSelector(selector);
}
return imageResource.getHref();
}
return null;
}
@Override
public String getUIPath() {
Resource parsys = this.resource.getChild("par");
if (parsys != null && parsys.listChildren().hasNext()) {
return parsys.getPath();
}
return null;
}
@Override
public String getRedirectUrl() {
return (String)ResourceUtil.getValueMap((Resource)this.resource).get("redirect", String.class);
}
@Override
public <T> T getProperty(String name, Class<T> type) {
return (T)ResourceUtil.getValueMap((Resource)this.resource).get(name, type);
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (type == Resource.class) {
return (AdapterType)this.resource;
}
Object ret = super.adaptTo(type);
if (ret == null) {
ret = this.resource.adaptTo(type);
}
return (AdapterType)ret;
}
}