GuideThemeUtils.java
7.91 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
/*
* 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
* javax.jcr.Value
* javax.jcr.ValueFormatException
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.utils;
import com.adobe.aemds.guide.service.GuideException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GuideThemeUtils {
private static Logger logger = LoggerFactory.getLogger(GuideThemeUtils.class);
public static String getThemeClientlibPath(Node resourceNode) throws GuideException {
String clientLibProperty = "./metadata/clientlibRef";
String clientLibPath = "";
try {
if (resourceNode != null && resourceNode.hasProperty(clientLibProperty)) {
clientLibPath = resourceNode.getProperty(clientLibProperty).getString() + "/" + resourceNode.getParent().getName();
}
}
catch (ValueFormatException e) {
logger.error("Exception in getClientlibNode()", (Throwable)e);
throw new GuideException((Exception)e);
}
catch (PathNotFoundException e) {
logger.error("Exception in getClientlibNode()", (Throwable)e);
throw new GuideException((Exception)e);
}
catch (RepositoryException e) {
logger.error("Exception in getClientlibNode()", (Throwable)e);
throw new GuideException((Exception)e);
}
return clientLibPath;
}
public static String getConfiguredFormPagePath(ResourceResolver resourceResolver, String themeContentPath) {
if (resourceResolver == null) {
throw new GuideException("Invalid user session.");
}
String formRef = null;
try {
String formPagePath;
Session session = (Session)resourceResolver.adaptTo(Session.class);
String formAssetPath = GuideThemeUtils.getConfiguredFormPath(resourceResolver, themeContentPath);
if (formAssetPath != null && !formAssetPath.isEmpty() && (formPagePath = StringUtils.replace((String)formAssetPath, (String)"/content/dam/formsanddocuments/", (String)"/content/forms/af/", (int)1)).startsWith("/content/forms/af/") && session.nodeExists(formPagePath)) {
formRef = formPagePath;
}
if (formRef == null) {
Resource defaultForm = resourceResolver.getResource("fd/af/themes/default");
formRef = defaultForm.getPath();
}
}
catch (RepositoryException e) {
throw new GuideException((Exception)e);
}
return formRef;
}
public static String getConfiguredFormPath(ResourceResolver resourceResolver, String themeContentPath) {
if (resourceResolver == null) {
throw new GuideException("Invalid user session.");
}
String formAssetPath = null;
try {
Node themeContentNode;
Session session = (Session)resourceResolver.adaptTo(Session.class);
if (themeContentPath != null && session.nodeExists(themeContentPath) && (themeContentNode = session.getNode(themeContentPath)).hasProperty("metadata/formRef")) {
formAssetPath = themeContentNode.getProperty("metadata/formRef").getString();
}
}
catch (RepositoryException e) {
throw new GuideException((Exception)e);
}
return formAssetPath;
}
public static String getThemeName(ResourceResolver resourceResolver, String themeContentPath) {
if (resourceResolver == null) {
throw new GuideException("Invalid user session.");
}
String themePath = null;
try {
Node themeContentNode;
Session session = (Session)resourceResolver.adaptTo(Session.class);
if (themeContentPath != null && session.nodeExists(themeContentPath) && (themeContentNode = session.getNode(themeContentPath)).hasProperty("metadata/title")) {
themePath = themeContentNode.getProperty("metadata/title").getString();
}
}
catch (RepositoryException e) {
throw new GuideException((Exception)e);
}
return themePath;
}
public static String getThemeClientlibCategory(ResourceResolver resourceResolver, String themeContentPath) {
if (resourceResolver == null) {
throw new GuideException("Invalid user session.");
}
String themeClientlibCategory = null;
try {
Node themeContentNode;
Session session = (Session)resourceResolver.adaptTo(Session.class);
if (themeContentPath != null && session.nodeExists(themeContentPath) && (themeContentNode = session.getNode(themeContentPath)).hasProperty("metadata/clientlibCategory")) {
themeClientlibCategory = themeContentNode.getProperty("metadata/clientlibCategory").getString();
}
}
catch (RepositoryException e) {
throw new GuideException((Exception)e);
}
return themeClientlibCategory;
}
public static String getBaseClientlibCategory(ResourceResolver resourceResolver, String themeContentPath) {
if (resourceResolver == null) {
throw new GuideException("Invalid user session.");
}
String baseClientlibCategory = null;
try {
Node clientlibNode;
Node themeContentNode;
String clientlibLoc;
Session session = (Session)resourceResolver.adaptTo(Session.class);
if (themeContentPath != null && session.nodeExists(themeContentPath) && (themeContentNode = session.getNode(themeContentPath)).hasProperty("metadata/clientlibRef") && (clientlibNode = session.getNode((clientlibLoc = themeContentNode.getProperty("metadata/clientlibRef").getString()) + "/" + themeContentNode.getParent().getName())).hasProperty("dependencies")) {
Value[] values = clientlibNode.getProperty("dependencies").getValues();
baseClientlibCategory = values[0].getString();
}
}
catch (RepositoryException e) {
throw new GuideException((Exception)e);
}
return baseClientlibCategory;
}
public static String getErrorSimulatorString(ValueMap properties) {
String validatePictureClauseMessage;
String mandatoryMessageAttribute = null;
boolean mandatory = (Boolean)properties.get("mandatory", (Object)false);
if (mandatory) {
String mandatoryMessage = (String)properties.get("mandatoryMessage", String.class);
mandatoryMessageAttribute = mandatoryMessage != null && !mandatoryMessage.equals("") ? mandatoryMessage : "There is an error in this field !";
} else {
String validateExpMessage = (String)properties.get("validateExpMessage", String.class);
if (validateExpMessage != null && !validateExpMessage.equals("")) {
mandatoryMessageAttribute = validateExpMessage;
}
}
if (mandatoryMessageAttribute != null && (validatePictureClauseMessage = (String)properties.get("validatePictureClauseMessage", String.class)) != null) {
mandatoryMessageAttribute = validatePictureClauseMessage;
}
return mandatoryMessageAttribute;
}
}