S7Preset.java
2.75 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.PathNotFoundException
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.tenant.Tenant
*/
package com.day.cq.dam.commons.preset;
import com.day.cq.dam.commons.preset.PresetType;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.tenant.Tenant;
public class S7Preset {
private static final String DEFAULT_PRESET_ROOT_PATH = "/etc/dam/";
private static final String TENANTS_BASE_PATH = "tenants/";
private static final String PRESET_BASE_PATH = "/presets/";
private static final String JCR_PRESET_ROOT_PATH = "/etc/dam/dynamicmediaconfig";
private static final String JCR_PRESET_ROOT_PROP = "dynamicMediaPresetRoot";
private PresetType presetType = null;
private String tenantId = "";
private String presetRootPath = "";
public S7Preset(String presetTypeName, ResourceResolver resourceResolver) {
Tenant tenant;
this.presetType = PresetType.getPresetTypeByName(presetTypeName);
this.presetRootPath = "/etc/dam/";
if (resourceResolver != null && (tenant = (Tenant)resourceResolver.adaptTo(Tenant.class)) != null) {
this.tenantId = tenant.getId();
this.presetRootPath = this.getPresetRootPath(resourceResolver);
}
}
private String getPresetRootPath(ResourceResolver resourceResolver) {
String presetRootPath = "/etc/dam/";
try {
Session session = (Session)resourceResolver.adaptTo(Session.class);
Node jcrRootPathNode = session.getNode("/etc/dam/dynamicmediaconfig");
if (jcrRootPathNode != null && jcrRootPathNode.hasProperty("dynamicMediaPresetRoot") && !(presetRootPath = jcrRootPathNode.getProperty("dynamicMediaPresetRoot").getString()).endsWith("/")) {
presetRootPath = presetRootPath + "/";
}
}
catch (PathNotFoundException pnfe) {
}
catch (RepositoryException re) {
// empty catch block
}
return presetRootPath;
}
public String getPresetPath() {
StringBuilder path = new StringBuilder(this.presetRootPath);
if (!this.tenantId.isEmpty()) {
path.append("tenants/");
path.append(this.tenantId);
path.append("/presets/");
path.append(this.presetType.getName());
} else {
path.append(this.presetType.getDefaultPresetPath());
}
return path.toString();
}
}