S7ConfigImpl.java
7.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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.inherit.InheritanceValueMap
* com.day.cq.wcm.webservicesupport.Configuration
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Value
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.scene7.impl.model;
import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.dam.scene7.api.S7Config;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.io.InvalidObjectException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class S7ConfigImpl
implements S7Config {
private Configuration configuration;
private InheritanceValueMap map;
private String region;
private String basePath = "";
private String email;
private String password;
private boolean shared;
private static final Logger LOG = LoggerFactory.getLogger(S7ConfigImpl.class);
public S7ConfigImpl(Configuration configuration) throws InvalidObjectException {
if (configuration == null) {
throw new InvalidObjectException("The configuration object cannot be null");
}
this.configuration = configuration;
this.map = configuration.getProperties();
this.region = (String)this.map.get((Object)"region");
}
public S7ConfigImpl(Configuration configuration, boolean shared) throws InvalidObjectException {
this(configuration);
this.shared = shared;
}
public S7ConfigImpl(String email, String password, String region) throws InvalidObjectException {
this.email = email;
this.password = password;
this.region = region;
}
@Override
public String getCloudConfigPath() {
return this.configuration.getPath();
}
@Override
public String getEmail() {
return this.email == null ? (String)this.map.get((Object)"email") : this.email;
}
@Override
public String getPassword() {
return this.password == null ? (String)this.map.get((Object)"password") : this.password;
}
@Override
public String getRegion() {
return this.region;
}
@Override
public String getUserHandle() {
return (String)this.map.get("userHandle", String.class);
}
@Override
public String getCompanyHandle() {
return this.shared ? "Shared" : (String)this.map.get("companyHandle", String.class);
}
@Override
public String getRootPath() {
return this.shared ? "Scene7SharedAssets/" : (String)this.map.get("rootPath", String.class);
}
@Override
public String isSyncEnabled() {
return this.shared ? "off" : (String)this.map.get("syncEnabled", String.class);
}
@Override
public String isPublishEnabled() {
return this.shared ? "off" : (String)this.map.get("publishEnabled", String.class);
}
@Override
public String getBasePath() {
String cqRootPath;
int index;
if (this.basePath.equals("") && (cqRootPath = this.getRootPath()) != null && (index = cqRootPath.indexOf("/")) != -1) {
this.basePath = cqRootPath.substring(0, index + 1);
}
return this.basePath;
}
@Override
public String get(String prop) {
String value = null;
value = "email".equals(prop) ? this.getEmail() : ("region".equals(prop) ? this.getRegion() : ("password".equals(prop) ? this.getPassword() : ("companyHandle".equals(prop) ? this.getCompanyHandle() : ("rootPath".equals(prop) ? this.getRootPath() : ("cqRootPath".equals(prop) ? this.getBasePath() : ("userHandle".equals(prop) ? this.getUserHandle() : ("syncEnabled".equals(prop) ? this.isSyncEnabled() : ("publishEnabled".equals(prop) ? this.isPublishEnabled() : (String)this.map.get(prop, String.class)))))))));
return value;
}
@Override
public InheritanceValueMap getPropertiesMap() {
return this.map;
}
@Override
public String getPublishServer() {
return (String)this.map.get("publishServer", String.class);
}
@Override
public String getPreviewServer() {
return (String)this.map.get("previewServer", String.class);
}
@Override
public String getFlashTemplatesServer() {
return (String)this.map.get("flashTemplatesServer", String.class);
}
@Override
public String getTargetPath() {
return (String)this.map.get("targetPath", String.class);
}
@Override
public boolean isDefault() {
Boolean defaultProperty = (Boolean)this.map.get("defaultConfiguration", (Object)Boolean.FALSE);
return defaultProperty;
}
@Override
public String getMimeTypeJobParams(String mimeType) {
if (mimeType == null || mimeType.length() == 0) {
return "";
}
mimeType = mimeType.toLowerCase();
mimeType = mimeType.replace("/", "_");
mimeType = mimeType.replace("*", "");
Resource confResource = this.configuration.getResource();
ResourceResolver rr = confResource.getResourceResolver();
String path = confResource.getPath() + "/" + "jcr:content" + "/" + "mimeTypes";
Resource mimeTypesResource = rr.getResource(path);
Node mimeTypesNode = (Node)mimeTypesResource.adaptTo(Node.class);
try {
if (mimeTypesNode != null && mimeTypesNode.hasNode(mimeType)) {
Node mimeTypeNode = mimeTypesNode.getNode(mimeType);
Property jobParam = mimeTypeNode.getProperty("jobParam");
if (jobParam != null) {
return jobParam.getValue().toString();
}
} else if (mimeTypesNode != null) {
NodeIterator iterator = mimeTypesNode.getNodes();
while (iterator.hasNext()) {
Property jobParam;
Node childNode = iterator.nextNode();
if (!mimeType.startsWith(childNode.getName()) || (jobParam = childNode.getProperty("jobParam")) == null) continue;
return jobParam.getValue().toString();
}
}
}
catch (RepositoryException e) {
LOG.error(e.getLocalizedMessage());
}
return "";
}
public boolean equals(Object obj) {
if (obj != null && obj instanceof S7Config) {
S7Config anotherS7Config = (S7Config)obj;
return this.getCloudConfigPath().equals(anotherS7Config.getCloudConfigPath());
}
return false;
}
@Override
public String getFXGServer() {
return (String)this.map.get("fxgServer", String.class);
}
@Override
public String getAdhocFolder() {
return (String)this.map.get("adhocFolder", String.class);
}
@Override
public String getImportQueueName() {
return (String)this.map.get("importQueueName", String.class);
}
@Override
public String getImportQueueTopic() {
return (String)this.map.get("importQueueTopic", String.class);
}
}