DamLayout.java
8.67 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.scalautil.javautil.Tuple
* com.scene7.is.util.callbacks.Option
* scala.Tuple2
* scala.Tuple3
*/
package com.adobe.cq.dam.aod.replication;
import com.scene7.is.scalautil.javautil.Tuple;
import com.scene7.is.util.callbacks.Option;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import scala.Tuple2;
import scala.Tuple3;
public class DamLayout {
public static final String DefaultContentRoot = "/content/dam";
public static final String DefaultCatalogPath = "/etc/dam/imageserver/configuration/jcr:content/settings";
public static final String DefaultMacroPath = "/etc/dam/imageserver/macros";
public static final String DefaultViewerPresetRoot = "/etc/dam/presets/viewer";
public static final String TenantConfRoot = "/etc/dam/tenants";
public static final String TenantContentRoot = "/content/dam/mac";
public static final String CatalogSuffix = "imageserver/configuration/jcr:content/settings";
public static final String ViewerPresetSuffix = "presets/viewer";
public static final String ImagePresetSuffix = "presets/image";
private static final String PathSeg = "[^/]+";
public static String viewerPresetRoot(String tenantId) {
if (tenantId.isEmpty()) {
return "/etc/dam/presets/viewer";
}
return "/etc/dam/tenants/" + tenantId;
}
public static String contentRoot(String tenantId) {
if (tenantId.isEmpty()) {
return "/content/dam";
}
return "/content/dam/mac/" + tenantId;
}
public static boolean isRenditionPath(String path) {
return RenditionPath.unapply(path).isDefined();
}
public static boolean isRelationPath(String path) {
return RelationPath.unapply(path).isDefined();
}
public static boolean isCatalogPath(String path) {
return CatalogPath.unapply(path).isDefined();
}
public static boolean isMacroPath(String path) {
return MacroPath.unapply(path).isDefined();
}
public static String catalogTenantId(String path) {
Iterator i$ = CatalogPath.unapply(path).iterator();
if (i$.hasNext()) {
String v = (String)i$.next();
return v;
}
throw new IllegalArgumentException("Not a catalog path: '" + path + '\'');
}
public static Tuple2<String, String> macroParts(String path) {
Iterator i$ = MacroPath.unapply(path).iterator();
if (i$.hasNext()) {
Tuple2 v = (Tuple2)i$.next();
return v;
}
throw new IllegalArgumentException("Not a macro path: '" + path + '\'');
}
public static Tuple2<String, String> assetParts(String path) {
Iterator i$ = AssetParts.unapply(path).iterator();
if (i$.hasNext()) {
Tuple3 v = (Tuple3)i$.next();
String tenantId = (String)v._1();
String assetId = (String)v._3();
return Tuple.tuple((Object)tenantId, (Object)assetId);
}
throw new IllegalArgumentException("Not an asset path: '" + path + '\'');
}
public static String imagePresetRoot(String tenantId) {
if (tenantId.isEmpty()) {
return "/etc/dam/imageserver/macros";
}
return "/etc/dam/tenants/" + tenantId + '/' + "presets/image";
}
private static Option<Matcher> match(Pattern pattern, String str) {
Matcher result = pattern.matcher(str);
if (result.matches()) {
return Option.some((Object)result);
}
return Option.none();
}
private DamLayout() {
}
private static class RelationPath {
private static final Pattern regex = Pattern.compile("^(/.+)/jcr:content/related/([^/]+)$");
private RelationPath() {
}
public static Option<Tuple2<String, String>> unapply(String path) {
Iterator i$ = DamLayout.match(regex, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
return Option.some((Object)Tuple.tuple((Object)v.group(1), (Object)v.group(2)));
}
return Option.none();
}
}
private static class AssetParts {
private static final Pattern regex = Pattern.compile("^((?:/etc/dam/tenants)|(?:/content/dam/mac))/([^/]+)/(.*)?$");
public static Option<Tuple3<String, String, String>> unapply(String path) {
Iterator i$ = DamLayout.match(regex, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
String prefix = v.group(1);
String tenantId = v.group(2);
String recordId = v.group(3);
String rootId = (prefix + '/' + tenantId).substring(1);
return Option.some((Object)Tuple.tuple((Object)tenantId, (Object)rootId, (Object)recordId));
}
assert (path.startsWith("/"));
return Option.some((Object)Tuple.tuple((Object)"", (Object)"", (Object)path.substring(1)));
}
private AssetParts() {
}
}
public static class CatalogPath {
private static final Pattern regex = Pattern.compile("^/etc/dam/tenants/([^/]+)/imageserver/configuration/jcr:content/settings$");
public static String fromTenantId(String tenantId) {
if (tenantId.isEmpty()) {
return "/etc/dam/imageserver/configuration/jcr:content/settings";
}
return "/etc/dam/tenants/" + tenantId + '/' + "imageserver/configuration/jcr:content/settings";
}
public static Option<String> unapply(String path) {
if (path.equals("/etc/dam/imageserver/configuration/jcr:content/settings")) {
return Option.some((Object)"");
}
Iterator i$ = DamLayout.match(regex, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
return Option.some((Object)v.group(1));
}
return Option.none();
}
}
private static class MacroPath {
private static final Pattern Default = Pattern.compile("/etc/dam/imageserver/macros/([^/]+)$");
private static final Pattern Tenant = Pattern.compile("^/etc/dam/tenants/([^/]+)/presets/image/([^/]+)$");
private MacroPath() {
}
public static String fromTenantId(String tenantId, String name) {
if (tenantId.isEmpty()) {
return "/etc/dam/imageserver/macros/" + name;
}
return DamLayout.imagePresetRoot(tenantId) + '/' + name;
}
public static Option<Tuple2<String, String>> unapply(String path) {
Iterator i$ = DamLayout.match(Default, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
String name = v.group(1);
return Option.some((Object)Tuple.tuple((Object)"", (Object)name));
}
i$ = DamLayout.match(Tenant, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
String tenant = v.group(1);
String name = v.group(2);
return Option.some((Object)Tuple.tuple((Object)tenant, (Object)name));
}
return Option.none();
}
}
private static class RenditionPath {
private static final Pattern regex = Pattern.compile("^(/.+)/jcr:content/renditions/([^/]+)$");
private RenditionPath() {
}
public static Option<Tuple2<String, String>> unapply(String path) {
Iterator i$ = DamLayout.match(regex, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
String asset = v.group(1);
String name = v.group(2);
return Option.some((Object)Tuple.tuple((Object)asset, (Object)name));
}
return Option.none();
}
}
public static class TenantDomainPath {
private static final Pattern regex = Pattern.compile("^((?:/etc/dam/tenants)|(?:/content/dam/mac))/([^/]+)(/.*)?$");
public static Option<Tuple3<String, String, Option<String>>> unapply(String path) {
Iterator i$ = DamLayout.match(regex, path).iterator();
if (i$.hasNext()) {
Matcher v = (Matcher)i$.next();
String rootPath = v.group(1);
String tenant = v.group(2);
Option suffix = Option.some((Object)v.group(3));
return Option.some((Object)Tuple.tuple((Object)tenant, (Object)rootPath, (Object)suffix));
}
return Option.none();
}
}
}