AbstractMobileClientCloudServiceHandler.java
6.87 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.i18n.I18n
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.mobile.mobilecloudservices.impl;
import com.adobe.cq.mobile.mobilecloudservices.impl.MobileClientCloudServiceHandler;
import com.adobe.cq.mobile.platform.impl.MobileAppException;
import com.adobe.cq.mobile.platform.impl.utils.MobileCloudServiceConfigsUtil;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.i18n.I18n;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
public abstract class AbstractMobileClientCloudServiceHandler
implements MobileClientCloudServiceHandler {
protected static final String PROPERTY_CONFIG_NAME = "configName";
@Override
public abstract Resource createConfiguration(Map<String, Object> var1, I18n var2, ResourceResolver var3) throws MobileAppException;
@Override
public abstract void checkProperties(Map<String, Object> var1, I18n var2) throws MobileAppException;
@Override
public abstract String getServicePath();
@Override
public void updateConfiguration(Resource resource, Map<String, Object> properties) {
}
@Override
public void saveCloudConfigProperty(Resource resource, String propertyName, String configPath) throws MobileAppException {
Resource content = resource.getChild("jcr:content");
if (content == null || ResourceUtil.isNonExistingResource((Resource)content)) {
throw new MobileAppException("Invalid Resource specified to write Cloud Configuration to: " + resource.getPath());
}
if (StringUtils.isNotBlank((CharSequence)propertyName)) {
ModifiableValueMap modifiableValueMap = (ModifiableValueMap)content.adaptTo(ModifiableValueMap.class);
modifiableValueMap.put((Object)propertyName, (Object)configPath);
}
MobileCloudServiceConfigsUtil.setCloudConfigProperty(resource, configPath);
try {
resource.getResourceResolver().commit();
}
catch (PersistenceException perEx) {
throw new MobileAppException("Could not save Cloud Configuration property: " + configPath, (Throwable)perEx);
}
}
@Override
public void unlinkCloudConfigProperty(Resource resource, String propertyName) throws MobileAppException {
MobileCloudServiceConfigsUtil.unlinkCloudConfigProperty(resource, propertyName, this.getServicePath());
try {
resource.getResourceResolver().commit();
}
catch (PersistenceException perEx) {
throw new MobileAppException("Could not unlink Cloud Configuration from: " + resource.getPath(), (Throwable)perEx);
}
}
protected String getValidPageName(String str) {
if (str == null) {
return null;
}
return JcrUtil.createValidName((String)str, (String[])JcrUtil.HYPHEN_LABEL_CHAR_MAPPING);
}
protected String getStringProperty(Map<String, Object> properties, String propertyName) {
String value;
block4 : {
if (!properties.containsKey(propertyName)) {
return null;
}
value = null;
try {
value = (String)properties.get(propertyName);
if (StringUtils.isBlank((CharSequence)value)) {
value = null;
}
}
catch (ClassCastException ex) {
String[] propertyArray = (String[])properties.get(propertyName);
if (propertyArray.length != 1) break block4;
value = propertyArray[0];
}
}
return value;
}
protected void putProperty(ModifiableValueMap mvp, String field, String value) {
if (StringUtils.isNotBlank((CharSequence)value) && StringUtils.isNotBlank((CharSequence)field)) {
mvp.put((Object)field, (Object)value);
}
}
protected String getName(Map<String, Object> properties, String defaultName) {
String pageName = null;
if (properties.keySet().contains("configName") && StringUtils.isNotBlank((CharSequence)this.getStringProperty(properties, "configName"))) {
String pageTitle = this.getStringProperty(properties, "configName");
pageName = this.getValidPageName(pageTitle);
} else {
pageName = this.getValidPageName(defaultName);
if (StringUtils.isBlank((CharSequence)pageName)) {
pageName = defaultName;
}
}
return pageName;
}
protected void saveConfigurationPublicNode(Resource parent) throws MobileAppException {
if (parent == null || ResourceUtil.isNonExistingResource((Resource)parent)) {
return;
}
ResourceResolver resolver = parent.getResourceResolver();
Session session = (Session)resolver.adaptTo(Session.class);
String publicPath = "";
String title = null;
Resource content = parent.getChild("jcr:content");
if (content != null) {
title = (String)content.getValueMap().get("jcr:title", String.class);
}
if (StringUtils.isBlank((CharSequence)title)) {
title = parent.getName();
}
String targetPath = content == null ? parent.getPath() : content.getPath();
try {
publicPath = targetPath + "/public";
Node publicNode = JcrUtil.createPath((String)publicPath, (String)"nt:unstructured", (Session)session);
ModifiableValueMap mvp = (ModifiableValueMap)resolver.getResource(publicNode.getPath()).adaptTo(ModifiableValueMap.class);
mvp.put((Object)"jcr:title", (Object)title);
}
catch (RepositoryException repEx) {
throw new MobileAppException("Could not create public note for " + parent.getPath() + ". " + repEx.getMessage());
}
try {
if (session.hasPendingChanges()) {
session.save();
}
}
catch (RepositoryException repEx) {
throw new MobileAppException("Could not save the public node properly: " + publicPath);
}
}
}