AbstractDPSObjectImpl.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.foundation.Image
* javax.jcr.Node
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.mobile.dps.impl.metadata;
import com.adobe.cq.mobile.dps.DPSObject;
import com.adobe.cq.mobile.dps.impl.utils.DPSUtil;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.foundation.Image;
import java.util.Calendar;
import java.util.Date;
import javax.jcr.Node;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public abstract class AbstractDPSObjectImpl
implements DPSObject {
protected Page page = null;
protected AbstractDPSObjectImpl(Page page) {
this.page = page;
}
@Override
public String getPath() {
return this.page.getPath();
}
public String getDescription() {
return (String)this.page.getProperties().get("jcr:description", String.class);
}
@Override
public String getDPSResourceType() {
return (String)this.page.getProperties().get("dps-resourceType", String.class);
}
@Override
public Date getLastCQModified() {
Calendar lastModified = this.page.getLastModified();
return lastModified == null ? null : lastModified.getTime();
}
@Override
public String getLastCQModifiedBy() {
return this.page.getLastModifiedBy();
}
@Override
public Date getCreated() {
return (Date)this.page.getProperties().get("jcr:created", Date.class);
}
@Override
public String getCreatedBy() {
return (String)this.page.getProperties().get("jcr:createdBy", String.class);
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (Node.class == type) {
return (AdapterType)this.page.adaptTo(Node.class);
}
if (Resource.class == type) {
return (AdapterType)this.page.adaptTo(Resource.class);
}
if (ResourceResolver.class == type) {
Resource resource = (Resource)this.page.adaptTo(Resource.class);
return (AdapterType)resource.getResourceResolver();
}
if (Page.class == type) {
return (AdapterType)this.page;
}
return null;
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof AbstractDPSObjectImpl)) {
return false;
}
AbstractDPSObjectImpl dpsObject = (AbstractDPSObjectImpl)object;
return this.getPath().equals(dpsObject.getPath());
}
public int hashCode() {
return this.getPath().hashCode();
}
protected String getImagePath(String imageRelPath) {
String path = null;
Resource imageResourceImage = this.page.getContentResource(imageRelPath);
if (DPSUtil.isImageSet(imageResourceImage)) {
path = this.getImageRenderURI(imageResourceImage);
}
return path;
}
protected String getImageRenderURI(Resource resourceToRender) {
Image img = new Image(resourceToRender);
img.setItemName("file", "image");
img.setItemName("fileReference", "imageReference");
img.setSelector("img");
return img.getHref();
}
@Override
public abstract String getProjectId();
}