DynamicMediaConfig.java
5.73 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.replication.AgentConfig
* com.scene7.is.util.callbacks.Option
* javax.jcr.RepositoryException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* scala.Tuple3
*/
package com.adobe.cq.dam.s7imaging.config;
import com.adobe.cq.dam.aod.replication.DamLayout;
import com.adobe.cq.dam.s7imaging.impl.catalog.JcrUtil;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropExtractor;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropKey;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.StandardExtractors;
import com.day.cq.replication.AgentConfig;
import com.scene7.is.util.callbacks.Option;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import scala.Tuple3;
public class DynamicMediaConfig {
private static final Pattern validTenantIdChars = Pattern.compile("[\\w\\s.\\-]+");
private static final PropKey<String> CompanyName = PropKey.required("companyName", StandardExtractors.toString);
private static final String DefaultMacroPath = "/etc/dam/imageserver/macros";
private static final String TenantMacroSuffix = "presets/image";
private static final String TenantCatalogSuffix = "imageserver/configuration/jcr:content/settings";
public static Option<String> defaultCompanyName(AgentConfig config) {
return Option.some((Object)((String)config.getProperties().get((Object)"companyName")));
}
public static String tenantId(ResourceResolver resolver, String path) {
assert (path.startsWith("/"));
assert (path.equals("/") || !path.endsWith("/"));
Iterator i$ = DamLayout.TenantDomainPath.unapply(path).iterator();
if (i$.hasNext()) {
Tuple3 v = (Tuple3)i$.next();
return (String)v._1();
}
return "";
}
public static Option<Resource> imagePresets(Resource catalogSettings) {
String path = catalogSettings.getPath();
Iterator i$ = DamLayout.CatalogPath.unapply(path).iterator();
if (i$.hasNext()) {
String tenantId = (String)i$.next();
return JcrUtil.getResource(catalogSettings.getResourceResolver(), DamLayout.imagePresetRoot(tenantId));
}
throw new AssertionError((Object)("Invalid catalog settings path: '" + path + '\''));
}
public static Option<Resource> catalog(ResourceResolver resolver, String _rootId) throws RepositoryException {
String rootId = DynamicMediaConfig.fixNetPath(_rootId);
assert (!rootId.startsWith("/"));
assert (!rootId.endsWith("/"));
Iterator i$ = DamLayout.TenantDomainPath.unapply("" + '/' + rootId).iterator();
if (i$.hasNext()) {
Tuple3 v = (Tuple3)i$.next();
String tenant = (String)v._1();
Iterator i$2 = ((Option)v._3()).iterator();
if (i$2.hasNext()) {
String suffix = (String)i$2.next();
assert (!suffix.isEmpty());
return Option.none();
}
return Option.some((Object)DynamicMediaConfig.tenantCatalog(resolver, tenant));
}
if (rootId.isEmpty()) {
return JcrUtil.getResource(resolver, DynamicMediaConfig.catalogPath(""));
}
return Option.none();
}
public static List<String> tenantRootIds(String tenantId) {
assert (!tenantId.isEmpty());
return Arrays.asList(DamLayout.contentRoot(tenantId).substring(1), DamLayout.viewerPresetRoot(tenantId).substring(1));
}
public static String imagePresetPath(String tenantId) {
if (tenantId.isEmpty()) {
return "/etc/dam/imageserver/macros";
}
return "/etc/dam/tenants/" + tenantId + '/' + "presets/image";
}
private static String fixNetPath(String path) {
return path.replaceAll(" / +$ ", " ");
}
private static Resource tenantCatalog(ResourceResolver resolver, String tenantId) throws RepositoryException {
String path = DynamicMediaConfig.catalogPath(tenantId);
Iterator i$ = JcrUtil.getResource(resolver, path).iterator();
if (i$.hasNext()) {
Resource resource = (Resource)i$.next();
return resource;
}
String m = "Catalog for '" + tenantId + "' does not exist. Publish catalog settings at '" + path + "'";
throw new RepositoryException(m);
}
private static String catalogPath(String tenantId) {
if (tenantId.isEmpty()) {
return "/etc/dam/imageserver/configuration/jcr:content/settings";
}
return "/etc/dam/tenants/" + tenantId + '/' + "imageserver/configuration/jcr:content/settings";
}
private static void validateTenantId(String id) {
if (id.equals("..")) {
DynamicMediaConfig.illegalId(id, "must not be '..'");
}
if (id.startsWith(" ")) {
DynamicMediaConfig.illegalId(id, "must not start with white space");
}
if (id.endsWith(" ")) {
DynamicMediaConfig.illegalId(id, "must not end with white space");
}
if (!validTenantIdChars.matcher(id).matches()) {
DynamicMediaConfig.illegalId(id, "can only contain numbers, letters, white space, '.', '-' and '_'");
}
}
private static Option<String> illegalId(String id, String message) {
throw new IllegalArgumentException("Illegal tenant ID (" + message + ") but was: '" + id + "'");
}
private DynamicMediaConfig() {
}
}