BlueprintImpl.java
12.3 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.Filter
* com.day.cq.tagging.Tag
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.Template
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.Blueprint
* com.day.cq.wcm.msm.api.RolloutConfig
* com.day.cq.wcm.msm.api.RolloutConfigManager
* com.day.text.Text
* javax.jcr.Node
* javax.jcr.PathNotFoundException
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.commons.lang.ArrayUtils
* org.apache.commons.lang.StringUtils
* org.apache.jackrabbit.commons.JcrUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.commons.Filter;
import com.day.cq.tagging.Tag;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.Template;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.Blueprint;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutConfigManager;
import com.day.text.Text;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
public class BlueprintImpl
implements Blueprint {
private static final String STATEMENT = "select [jcr:path] from [cq:BlueprintSyncConfig] as a where isdescendantnode(a, '%s') order by [jcr:path] asc";
private static final String[] EMPTY_STRING = new String[0];
private final Page page;
private final RolloutConfigManager rolloutConfigManager;
private final String statement;
BlueprintImpl(Page page, RolloutConfigManager rolloutConfigManager) {
this.page = page;
this.rolloutConfigManager = rolloutConfigManager;
this.statement = String.format("select [jcr:path] from [cq:BlueprintSyncConfig] as a where isdescendantnode(a, '%s') order by [jcr:path] asc", this.getSitePath());
}
public String getSitePath() {
return (String)this.getProperties().get("sitePath", String.class);
}
public List<RolloutConfig> getBlueprintRolloutConfig(String relPath, boolean exact) throws WCMException {
BlueprintImpl.checkRelPath(relPath);
String configPath = this.getAbsolutePath(relPath);
ResourceResolver resolver = this.getResourceResolver();
Resource parentResource = null;
if (exact) {
parentResource = resolver.getResource(configPath);
} else {
String path = this.getParentConfig(configPath);
if (path != null) {
parentResource = resolver.getResource(path);
}
}
List<RolloutConfig> rolloutConfig = null;
if (parentResource != null) {
Resource configResource;
if (parentResource.getChild("jcr:content") != null) {
parentResource = parentResource.getChild("jcr:content");
}
if ((configResource = parentResource.getChild("cq:BlueprintSyncConfig")) != null) {
try {
rolloutConfig = this.readRolloutConfig(configResource);
}
catch (RepositoryException e) {
throw new WCMException((Throwable)e);
}
}
}
return rolloutConfig;
}
private String getParentConfig(String absPath) throws WCMException {
String hit = null;
Iterator itr = this.getResourceResolver().queryResources(this.statement, "JCR-SQL2");
while (itr.hasNext()) {
String path = Text.getRelativeParent((String)((String)((Map)itr.next()).get("jcr:path")), (int)2);
if (Text.isDescendantOrEqual((String)path, (String)absPath)) {
hit = path;
}
if (path.length() <= absPath.length()) continue;
break;
}
return hit;
}
public String getIconPath() {
return null;
}
public String getThumbnailPath() {
Resource thumb;
Resource resource = this.page.getContentResource();
if (resource != null && (thumb = resource.getChild("thumbnail")) != null) {
return resource.getPath() + ".thumbnail.png";
}
return null;
}
public Long getRanking() {
return (Long)this.getProperties().get("ranking", (Object)100000);
}
public void write(JSONWriter jsonWriter) throws JSONException {
jsonWriter.object();
String title = this.getTitle();
if (title != null && title.length() > 0) {
jsonWriter.key("title").value((Object)title);
} else {
jsonWriter.key("title").value((Object)Text.getName((String)this.getPath()));
}
jsonWriter.key("ranking").value((Object)this.getRanking());
jsonWriter.key("hidden").value(this.getProperties().get("hidden", (Object)Boolean.FALSE));
jsonWriter.key("sitePath").value((Object)this.getSitePath());
String desc = this.getDescription();
if (desc != null && desc.length() > 0) {
jsonWriter.key("description").value((Object)desc);
} else {
jsonWriter.key("description").value((Object)"");
}
jsonWriter.key("path").value((Object)this.getPath());
if (this.getThumbnailPath() != null) {
jsonWriter.key("thumbnailPath").value((Object)this.getThumbnailPath());
}
if (this.getIconPath() != null) {
jsonWriter.key("iconPath").value((Object)this.getIconPath());
}
jsonWriter.endObject();
}
public /* varargs */ List<RolloutConfig> setRolloutConfigs(String relPath, String ... rolloutConfigs) throws WCMException {
BlueprintImpl.checkRelPath(relPath);
ResourceResolver resolver = this.getResourceResolver();
Resource toSet = resolver.getResource(this.getAbsolutePath(relPath));
try {
if (toSet == null || toSet.adaptTo(Node.class) == null) {
throw new PathNotFoundException(String.format("%s/%s", this.getSitePath(), relPath));
}
this.writeConfig((Node)toSet.adaptTo(Node.class), rolloutConfigs);
return this.readRolloutConfig(toSet);
}
catch (RepositoryException re) {
throw new WCMException((Throwable)re);
}
}
private String getAbsolutePath(String relPath) {
return StringUtils.isEmpty((String)relPath) ? this.getSitePath() : String.format("%s/%s", this.getSitePath(), relPath);
}
private ResourceResolver getResourceResolver() throws WCMException {
Resource resource = (Resource)this.page.adaptTo(Resource.class);
if (resource == null) {
throw new WCMException("Blueprint has no access to ResourceResolver");
}
return resource.getResourceResolver();
}
public String getPath() {
return this.page.getPath();
}
public String getName() {
return this.page.getName();
}
public String getTitle() {
return this.page.getTitle();
}
public String getDescription() {
return this.page.getDescription();
}
private static void checkRelPath(String relPath) {
if (relPath != null && relPath.startsWith("/")) {
throw new IllegalArgumentException("Given path is not a relative Path: " + relPath);
}
}
private List<RolloutConfig> readRolloutConfig(Resource configResource) throws RepositoryException, WCMException {
ArrayList<RolloutConfig> config = new ArrayList<RolloutConfig>();
ValueMap map = (ValueMap)configResource.adaptTo(ValueMap.class);
for (String path : (String[])map.get("cq:rolloutConfigs", (Object)EMPTY_STRING)) {
RolloutConfig rc = this.rolloutConfigManager.getRolloutConfig(path);
if (rc == null) continue;
config.add(rc);
}
return config;
}
private /* varargs */ void writeConfig(Node sourceNode, String ... rolloutConfigs) throws RepositoryException {
if (sourceNode.isNodeType("nt:hierarchyNode")) {
sourceNode = JcrUtils.getOrAddNode((Node)sourceNode, (String)"jcr:content");
}
if (ArrayUtils.isEmpty((Object[])rolloutConfigs) && sourceNode.hasNode("cq:BlueprintSyncConfig")) {
sourceNode.getNode("cq:BlueprintSyncConfig").remove();
} else if (!ArrayUtils.isEmpty((Object[])rolloutConfigs)) {
Node configNode = JcrUtils.getOrAddNode((Node)sourceNode, (String)"cq:BlueprintSyncConfig", (String)"cq:BlueprintSyncConfig");
configNode.setProperty("cq:rolloutConfigs", rolloutConfigs);
}
}
public PageManager getPageManager() {
return this.page.getPageManager();
}
public Resource getContentResource() {
return this.page.getContentResource();
}
public Resource getContentResource(String relPath) {
return this.page.getContentResource(relPath);
}
public Iterator<Page> listChildren() {
return this.page.listChildren();
}
public Iterator<Page> listChildren(Filter<Page> filter, boolean deep) {
return this.page.listChildren(filter, deep);
}
public Iterator<Page> listChildren(Filter<Page> filter) {
return this.listChildren(filter, false);
}
public boolean hasChild(String name) {
return this.page.hasChild(name);
}
public int getDepth() {
return this.page.getDepth();
}
public Page getParent() {
return this.page.getParent();
}
public Page getParent(int level) {
return this.page.getParent(level);
}
public Page getAbsoluteParent(int level) {
return this.page.getAbsoluteParent(level);
}
public ValueMap getProperties() {
return this.page.getProperties();
}
public ValueMap getProperties(String relPath) {
return this.page.getProperties(relPath);
}
public String getPageTitle() {
return this.page.getPageTitle();
}
public String getNavigationTitle() {
return this.page.getNavigationTitle();
}
public boolean isHideInNav() {
return this.page.isHideInNav();
}
public boolean hasContent() {
return this.page.hasContent();
}
public boolean isValid() {
return this.page.isValid();
}
public long timeUntilValid() {
return this.page.timeUntilValid();
}
public Calendar getOnTime() {
return this.page.getOnTime();
}
public Calendar getOffTime() {
return this.page.getOffTime();
}
public String getLastModifiedBy() {
return this.page.getLastModifiedBy();
}
public Calendar getLastModified() {
return this.page.getLastModified();
}
public String getVanityUrl() {
return this.page.getVanityUrl();
}
public Tag[] getTags() {
return this.page.getTags();
}
public void lock() throws WCMException {
this.page.lock();
}
public boolean isLocked() {
return this.page.isLocked();
}
public String getLockOwner() {
return this.page.getLockOwner();
}
public boolean canUnlock() {
return this.page.canUnlock();
}
public void unlock() throws WCMException {
this.page.unlock();
}
public Template getTemplate() {
return this.page.getTemplate();
}
public Locale getLanguage(boolean ignoreContent) {
return this.page.getLanguage(ignoreContent);
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
return (AdapterType)this.page.adaptTo(type);
}
public Calendar getDeleted() {
return this.page.getDeleted();
}
public String getDeletedBy() {
return this.page.getDeletedBy();
}
}