ProjectLinkImpl.java
5.25 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.projects.api.Project
* com.adobe.cq.projects.api.ProjectException
* com.adobe.cq.projects.api.ProjectLink
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.commons.lang3.StringUtils
* org.apache.sling.adapter.annotations.Adaptable
* org.apache.sling.adapter.annotations.Adapter
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ResourceWrapper
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.projects.impl;
import com.adobe.cq.projects.api.Project;
import com.adobe.cq.projects.api.ProjectException;
import com.adobe.cq.projects.api.ProjectLink;
import com.adobe.cq.projects.impl.util.ProjectUtils;
import java.io.InputStream;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adapter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ResourceWrapper;
import org.apache.sling.api.resource.ValueMap;
@Adaptable(adaptableClass=ProjectLink.class, adapters={@Adapter(value={Resource.class})})
public class ProjectLinkImpl
extends ResourceWrapper
implements ProjectLink {
private final Project parentProject;
public ProjectLinkImpl(Project parentProject, Resource resource) {
super(resource);
this.parentProject = parentProject;
}
public Project getProject() {
return this.parentProject;
}
public String getResolvedTitle() {
Resource target;
String specifiedTitle = this.getTitle();
if (!StringUtils.isBlank((CharSequence)specifiedTitle)) {
return specifiedTitle;
}
String suffix = ProjectUtils.getStringProperty((Resource)this, "suffix");
if (!StringUtils.isBlank((CharSequence)suffix) && (target = this.getResourceResolver().getResource(suffix)) != null && !ResourceUtil.isNonExistingResource((Resource)target)) {
ValueMap targetContentProperties;
ValueMap targetProperties = (ValueMap)target.adaptTo(ValueMap.class);
if (targetProperties.containsKey((Object)"jcr:title")) {
return (String)targetProperties.get("jcr:title", String.class);
}
Resource targetContent = target.getChild("jcr:content");
if (targetContent != null && !ResourceUtil.isNonExistingResource((Resource)targetContent) && (targetContentProperties = (ValueMap)targetContent.adaptTo(ValueMap.class)).containsKey((Object)"jcr:title")) {
return (String)targetContentProperties.get("jcr:title", String.class);
}
}
return "";
}
public String getTarget() {
return ProjectUtils.getStringProperty((Resource)this, "suffix");
}
public void setTarget(String target) {
try {
ProjectUtils.setStringProperty((Resource)this, "suffix", target);
}
catch (RepositoryException e) {
throw new ProjectException("Failed to update link target", (Throwable)e);
}
}
public String getTitle() {
return ProjectUtils.getStringProperty((Resource)this, "jcr:title");
}
public void setTitle(String title) {
try {
ProjectUtils.setStringProperty((Resource)this, "jcr:title", title);
}
catch (RepositoryException e) {
throw new ProjectException("Failed to update link title", (Throwable)e);
}
}
public String getDescription() {
return ProjectUtils.getStringProperty((Resource)this, "jcr:description");
}
public void setDescription(String description) {
try {
ProjectUtils.setStringProperty((Resource)this, "jcr:description", description);
}
catch (RepositoryException e) {
throw new ProjectException("Failed to update link title", (Throwable)e);
}
}
public void setCoverImage(String mimeType, InputStream stream) {
ProjectUtils.setCoverImage((Resource)this, this.getProject(), mimeType, stream, this.getName());
this.save();
}
public Resource getCoverImage() {
Resource imageResource;
String coverPath = ProjectUtils.getStringProperty((Resource)this, "coverUrl");
if (!StringUtils.isBlank((CharSequence)coverPath) && (imageResource = this.getResourceResolver().getResource(coverPath)) != null && !ResourceUtil.isNonExistingResource((Resource)imageResource)) {
return imageResource;
}
return null;
}
private void save() {
try {
((Session)this.getResourceResolver().adaptTo(Session.class)).save();
}
catch (RepositoryException e) {
throw new ProjectException("Unable to save the link.", (Throwable)e);
}
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (Resource.class == type) {
return (AdapterType)this.getResource();
}
return (AdapterType)super.adaptTo(type);
}
}