ConfigurationImpl.java
5.01 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.inherit.InheritanceValueMap
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.Template
* javax.jcr.Node
* javax.jcr.RepositoryException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
*/
package com.day.cq.wcm.webservicesupport.impl;
import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.Template;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.impl.MergedInheritanceValueMap;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
public class ConfigurationImpl
implements Configuration {
private static final String[] MERGED_PATH_SEGMENTS = new String[]{"jcr:content", "jcr:content/public"};
private Resource resource;
private Node node;
public ConfigurationImpl(Resource resource) {
this.resource = "jcr:content".equals(resource.getName()) ? resource.getParent() : resource;
this.node = (Node)this.resource.adaptTo(Node.class);
}
@Override
public String getTitle() {
return (String)this.getProperties().get("jcr:title", String.class);
}
@Override
public String getDescription() {
return (String)this.getProperties().get("jcr:description", String.class);
}
@Override
public String getName() {
return this.resource.getName();
}
@Override
public String getPath() {
return this.resource.getPath();
}
@Override
public Long getLastModified() {
Calendar mod = (Calendar)this.getProperties().get("cq:lastModified", Calendar.class);
if (mod != null) {
return mod.getTimeInMillis();
}
mod = (Calendar)this.getProperties().get("jcr:lastModified", Calendar.class);
return mod != null ? mod.getTimeInMillis() : 0;
}
@Override
public String getIconPath() {
try {
if (this.node.hasNode("icon.png")) {
return this.getPath() + "/" + "icon.png";
}
}
catch (RepositoryException var1_1) {
// empty catch block
}
return null;
}
@Override
public String getThumbnailPath() {
try {
if (this.node.hasNode("thumbnail.png")) {
return this.getPath() + "/" + "thumbnail.png";
}
}
catch (RepositoryException var1_1) {
// empty catch block
}
return null;
}
@Override
public Template getTemplate() {
Page page = (Page)this.resource.adaptTo(Page.class);
return page != null ? page.getTemplate() : null;
}
@Override
public Resource getParent() {
return this.resource.getParent();
}
@Override
public Resource getResource() {
return this.resource;
}
@Override
public Resource getContentResource() {
Resource contentResource = this.resource.getResourceResolver().getResource(this.resource, "jcr:content");
if (contentResource == null && this.isPublicOnlyConfiguration()) {
return this.resource;
}
return contentResource;
}
@Override
public InheritanceValueMap getProperties() {
return this.getInheritanceValueMap(this.getPath());
}
@Override
public <T> T get(String name, T defaultValue) {
InheritanceValueMap props = this.getProperties();
if (props == null) {
return defaultValue;
}
return (T)props.get(name, defaultValue);
}
@Override
public <T> T getInherited(String name, T defaultValue) {
InheritanceValueMap props = this.getProperties();
if (props == null) {
return defaultValue;
}
return (T)props.getInherited(name, defaultValue);
}
@Override
public Iterator<Configuration> listChildren() {
HashSet<Configuration> entries = new HashSet<Configuration>();
Iterator iter = this.resource.listChildren();
while (iter.hasNext()) {
Configuration cfg = (Configuration)((Resource)iter.next()).adaptTo(Configuration.class);
if (cfg == null) continue;
entries.add(cfg);
}
return entries.iterator();
}
private boolean isPublicOnlyConfiguration() {
return this.resource.getName().equals("public");
}
private InheritanceValueMap getInheritanceValueMap(String path) {
if (ResourceUtil.getName((String)path).equals("public")) {
path = ResourceUtil.getParent((String)path, (int)2);
}
return new MergedInheritanceValueMap(this.resource.getResourceResolver(), path, MERGED_PATH_SEGMENTS, "/etc/cloudservices");
}
}