GuidePropertyProviderUtils.java
39.9 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.expeditor.service.ExpressionEditorService
* com.adobe.forms.common.service.DataXMLProvider
* com.adobe.forms.common.service.FormDataXMLProviderRegistry
* com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
* com.adobe.granite.xss.XSSAPI
* com.day.cq.i18n.I18n
* com.day.cq.wcm.api.Template
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.Service
* com.day.cq.widget.HtmlLibraryManager
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.utils;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideLCServiceConnector;
import com.adobe.aemds.guide.service.GuideProgressiveStrategyManager;
import com.adobe.aemds.guide.taglibs.GuideELUtils;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.JSONArrayIterator;
import com.adobe.aemds.guide.utils.NodeStructureUtils;
import com.adobe.aemfd.expeditor.service.ExpressionEditorService;
import com.adobe.forms.common.service.DataXMLProvider;
import com.adobe.forms.common.service.FormDataXMLProviderRegistry;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.Template;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.widget.HtmlLibraryManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Service(value={GuidePropertyProviderUtils.class})
@Component
public class GuidePropertyProviderUtils {
private static final String COMPONENT_PATH = "component-path";
private final Logger logger = LoggerFactory.getLogger(GuidePropertyProviderUtils.class);
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private GuideLCServiceConnector guideLCServiceConnector;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.MANDATORY_UNARY)
private GuideProgressiveStrategyManager guideProgressiveStrategyManager;
@Reference
private ExpressionEditorService expressionEditorService;
@Reference
private HtmlLibraryManager htmlLibraryManager;
@Reference
ResourceResolverHelper resourceResolverHelper;
@Reference
FormDataXMLProviderRegistry prefillRegistry;
private static String SUBMITACTION = "submitAction";
public JSONArray queryAppearance(String[] searchPaths, Map<String, String> options) {
try {
String guideNodeClass = options.get("guideNodeClass");
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONArray response = new JSONArray();
JSONObject firstObj = new JSONObject();
firstObj.put("text", (Object)"none");
firstObj.put("value", JSONObject.NULL);
response.put((Object)firstObj);
if (guideNodeClass != null && !guideNodeClass.isEmpty() && GuideUtils.listContains(GuideConstants.GUIDE_FIELDS_CLASS_NAMES, guideNodeClass, Boolean.TRUE).booleanValue()) {
for (int i = 0; i < searchPaths.length; ++i) {
String query = "SELECT * FROM nt:base WHERE guideComponentType= 'fd/af/components/appearance/" + guideNodeClass + "' AND jcr:path LIKE '" + searchPaths[i] + "%'";
Iterator appearances = resolver.findResources(query, "sql");
if (appearances == null) continue;
while (appearances.hasNext()) {
String qtip;
Resource r = (Resource)appearances.next();
String path = r.getPath();
if (path.startsWith("/libs/") || path.startsWith("/apps/")) {
path = path.substring(6);
}
if (StringUtils.isEmpty((String)path)) continue;
String text = NodeStructureUtils.getLayoutDescription(r);
if (StringUtils.isEmpty((String)text)) {
text = path;
}
if (StringUtils.isEmpty((String)(qtip = NodeStructureUtils.getLayoutQtip(r)))) {
qtip = text;
}
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)text);
respObj.put("value", (Object)path);
respObj.put("qtip", (Object)qtip);
response.put((Object)respObj);
}
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONObject queryFragFinder(String formType, String resourceType, Map<String, String> options) {
String[] searchPathsForFragments = new String[]{"/content/dam/formsanddocuments"};
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
String QUERY = "query";
String START = "start";
String LIMIT = "limit";
String QUERY_LANG = "xpath";
String QUERY_ROOT = "/jcr:root";
String QUERY_ELEMENT_TYPE = "//element(*, dam:Asset)";
String SORT_BY_LAST_MODIFIED = " order by jcr:content/@jcr:lastModified descending";
String PREDICATE = "jcr:content/metadata/@formmodel=";
String FORM_PREDICATE = "jcr:content/@" + formType + " ='1'";
String ASSET_TYPE_NONE = "'none'";
String ASSET_TYPE_XSD = "'xmlschema'";
String ASSET_TYPE_XFA = "'formtemplates'";
try {
JSONArray fragRefs = new JSONArray();
String nameOrTitle = options.get("query");
String alreadySentNodesString = options.get("start");
String maxLimitToSendString = options.get("limit");
ArrayList<String> typePredicates = new ArrayList<String>();
String assetTypeParam = options.get("assetType");
if (StringUtils.isNotBlank((String)assetTypeParam)) {
for (String assetType : StringUtils.remove((String)assetTypeParam, (char)' ').split(",")) {
String filterType = null;
if ("none".equals(assetType)) {
filterType = "'none'";
} else if ("xfa".equals(assetType)) {
filterType = "'formtemplates'";
} else if ("xsd".equals(assetType)) {
filterType = "'xmlschema'";
}
if (filterType == null) continue;
typePredicates.add("jcr:content/metadata/@formmodel=" + filterType);
}
}
String combinedTypePredicates = "";
if (typePredicates.size() > 0) {
combinedTypePredicates = " and ( " + StringUtils.join(typePredicates, (String)" or ") + " )";
}
for (String searchPathsForFragment : searchPathsForFragments) {
String query = "/jcr:root" + searchPathsForFragment + "//element(*, dam:Asset)" + "[" + FORM_PREDICATE + combinedTypePredicates + "]" + " order by jcr:content/@jcr:lastModified descending";
Iterator fragmentNodes = resolver.findResources(query, "xpath");
int alreadySentNodes = -1;
int maxLimitToSend = -1;
int nodesLeft = -1;
if (maxLimitToSendString != null && maxLimitToSendString.length() > 0) {
maxLimitToSend = Integer.parseInt(maxLimitToSendString);
}
if (alreadySentNodesString != null && alreadySentNodesString.length() > 0) {
alreadySentNodes = Integer.parseInt(alreadySentNodesString);
nodesLeft = maxLimitToSend - alreadySentNodes;
}
if (fragmentNodes == null) continue;
if (alreadySentNodes != -1) {
for (int node = 0; node < alreadySentNodes; ++node) {
if (!fragmentNodes.hasNext()) continue;
fragmentNodes.next();
}
}
while (fragmentNodes.hasNext() && (nodesLeft == -1 || nodesLeft-- != 0)) {
Resource r = (Resource)fragmentNodes.next();
ValueMap properties = r.getChild("jcr:content").getChild("metadata").getValueMap();
boolean titleOrNameMatches = false;
if (nameOrTitle != null && nameOrTitle.length() > 0) {
boolean bl = titleOrNameMatches = StringUtils.containsIgnoreCase((String)((String)properties.get((Object)"name")), (String)nameOrTitle) || StringUtils.containsIgnoreCase((String)((String)properties.get((Object)"title")), (String)nameOrTitle);
}
if (nameOrTitle != null && !nameOrTitle.equals("") && !titleOrNameMatches) continue;
JSONObject fragObj = new JSONObject();
String name = (String)properties.get("title", (Object)"");
if (name.length() == 0) {
name = r.getName();
}
String resourcePath = r.getPath();
String imageRef = resourcePath + "/jcr:content" + "/renditions/cq5dam.thumbnail.319.319.png";
String fragRef = resourcePath;
fragRef = StringUtils.substringBefore((String)fragRef, (String)"/jcr:content");
fragObj.put("name", (Object)name);
fragObj.put("jcr:primaryType", (Object)"nt:unstructured");
fragObj.put("sling:resourceType", (Object)resourceType);
Resource componentResource = resolver.getResource(resourceType);
fragObj.put("component-path", (Object)componentResource.getPath());
fragObj.put("image", (Object)imageRef);
fragObj.put("path", (Object)fragRef);
fragRefs.put((Object)fragObj);
}
}
JSONObject response = new JSONObject();
response.put("fragRefs", (Object)fragRefs);
return response;
}
catch (Exception e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException(e);
}
}
public JSONArray queryLayout(String[] searchPaths, Map<String, String> options, SlingHttpServletRequest request) {
JSONArray response = new JSONArray();
String layoutType = "";
String isAfField = "";
if (options.get("layoutType") != null && options.get("layoutType").length() > 0) {
layoutType = options.get("layoutType");
isAfField = options.get("isAfField");
}
if (layoutType.length() > 0) {
try {
if ("fd/af/layouts/field".equals(layoutType)) {
JSONObject firstObj = new JSONObject();
firstObj.put("text", (Object)"");
firstObj.put("value", (Object)"");
response.put((Object)firstObj);
}
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
ArrayList<String> listOfLayouts = new ArrayList<String>();
for (int i = 0; i < searchPaths.length; ++i) {
String query = "SELECT * FROM nt:base WHERE guideComponentType='" + layoutType + "' AND jcr:path LIKE '" + searchPaths[i] + "%'";
Iterator layouts = resolver.findResources(query, "sql");
if (layouts == null) continue;
while (layouts.hasNext()) {
Resource r = (Resource)layouts.next();
String path = r.getPath();
if (path.startsWith("/libs/") || path.startsWith("/apps/")) {
path = path.substring(6);
}
String desc = NodeStructureUtils.getLayoutDescription(r);
if (listOfLayouts.contains(path)) continue;
JSONObject respObj = new JSONObject();
if ("fd/af/layouts/panel".equals(layoutType)) {
respObj.put("guideNavigatorTab", (Object)NodeStructureUtils.getGuideNavigatorTabProperty(r));
}
I18n i18n = new I18n(request.getResourceBundle(new Locale(request.getLocale().getLanguage())));
desc = "true".equals(isAfField) && path != null && path.indexOf("defaultFieldLayout") > 0 ? i18n.get("Inherit From Adaptive Form Configuration") : desc;
respObj.put("text", (Object)(desc == null ? r.getPath() : desc));
String qtip = NodeStructureUtils.getLayoutQtip(r);
respObj.put("value", (Object)path);
if ("fd/af/layouts/field".equals(layoutType)) {
XSSAPI xssapi = (XSSAPI)request.adaptTo(XSSAPI.class);
qtip = GuideELUtils.encodeForHtml(qtip, xssapi);
}
respObj.put("qtip", (Object)qtip);
listOfLayouts.add(path);
response.put((Object)respObj);
}
}
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
} else {
this.logger.warn("Request did not have layout type mentioned.So, not returning any layout types");
}
return response;
}
public JSONArray queryPrefillServiceProviders() {
JSONArray result = new JSONArray();
try {
List providers = this.prefillRegistry.getProviders();
for (DataXMLProvider provider : providers) {
JSONObject obj = new JSONObject();
String serviceName = provider.getServiceName();
String serviceDescription = provider.getServiceDescription();
obj.put("text", (Object)serviceDescription);
obj.put("value", (Object)serviceName);
obj.put("qtip", (Object)serviceDescription);
result.put((Object)obj);
}
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
return result;
}
public JSONArray queryTheme() {
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
String[] searchPathsForThemes = new String[]{"/content/dam/formsanddocuments-themes"};
JSONArray response = new JSONArray();
JSONObject firstObj = new JSONObject();
firstObj.put("text", (Object)"");
firstObj.put("value", (Object)"");
firstObj.put("name", (Object)"");
response.put((Object)firstObj);
for (int i = 0; i < searchPathsForThemes.length; ++i) {
Iterator themes = resolver.findResources("SELECT * FROM dam:Asset WHERE jcr:path LIKE '" + searchPathsForThemes[i] + "%'", "sql");
if (themes == null) continue;
while (themes.hasNext()) {
Resource r = (Resource)themes.next();
Resource metadataResource = r.getChild("jcr:content/metadata");
Node node = (Node)metadataResource.adaptTo(Node.class);
try {
String themeName = node.getProperty("title").getString();
String themeNodePath = node.getParent().getParent().getPath();
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)themeName);
respObj.put("value", (Object)themeNodePath);
respObj.put("name", (Object)themeName);
response.put((Object)respObj);
continue;
}
catch (RepositoryException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray queryAction(String[] searchPaths) {
HashMap<String, Resource> resourceMappings = new HashMap<String, Resource>();
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONArray response = new JSONArray();
for (int i = 0; i < searchPaths.length; ++i) {
Iterator layouts = resolver.findResources("SELECT * FROM nt:base WHERE guideComponentType = 'fd/af/components/action' AND jcr:path LIKE '" + searchPaths[i] + "%'", "sql");
if (layouts == null) continue;
resourceMappings.clear();
while (layouts.hasNext()) {
Resource r = (Resource)layouts.next();
String path = r.getPath();
if (path.startsWith("/libs/") || path.startsWith("/apps/")) {
path = path.substring(6);
}
if (resourceMappings.containsKey(path) && !r.getPath().startsWith("/apps/")) continue;
resourceMappings.put(path, r);
}
for (Map.Entry entry : resourceMappings.entrySet()) {
Resource resource = (Resource)entry.getValue();
JSONObject respObj = new JSONObject();
String desc = NodeStructureUtils.getLayoutDescription(resource);
respObj.put("text", (Object)(desc == null ? (String)entry.getKey() : desc));
respObj.put("value", entry.getKey());
respObj.put("name", (Object)resource.getName());
respObj.put("path", (Object)resource.getPath());
if (resource.getResourceSuperType() != null) {
respObj.put("sling:resourceSuperType", (Object)resource.getResourceSuperType());
}
respObj.put("templatePath", (Object)this.getComponentTemplatePath(resource));
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray queryProgressiveStrategies(String[] searchPaths) {
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONArray response = new JSONArray();
for (String searchPath : searchPaths) {
Iterator services = resolver.findResources("SELECT * FROM nt:base WHERE guideComponentType = '/libs/fd/af/components/progressiveDataCapture' AND jcr:path LIKE '" + searchPath + "%'", "sql");
if (services == null) continue;
while (services.hasNext()) {
Resource r = (Resource)services.next();
String value = r.getPath();
ValueMap properties = r.getValueMap();
String displayName = NodeStructureUtils.getLayoutDescription(r);
String strategyName = (String)properties.get("strategyName", (Object)"");
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)displayName);
respObj.put("qtip", (Object)displayName);
respObj.put("value", (Object)value);
respObj.put("strategyName", (Object)strategyName);
respObj.put("type", (Object)"service");
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray queryProgressiveLayout(String[] searchPaths) {
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONArray response = new JSONArray();
for (int i = 0; i < searchPaths.length; ++i) {
Iterator layouts = resolver.findResources("SELECT * FROM nt:base WHERE guideComponentType = 'fd/af/layouts/progressive' AND jcr:path LIKE '" + searchPaths[i] + "%'", "sql");
if (layouts == null) continue;
while (layouts.hasNext()) {
Resource r = (Resource)layouts.next();
String desc = NodeStructureUtils.getLayoutDescription(r);
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)(desc == null ? r.getPath() : desc));
String qtip = NodeStructureUtils.getLayoutQtip(r);
respObj.put("qtip", (Object)qtip);
String path = r.getPath();
respObj.put("value", (Object)(path + "/layout.html"));
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray queryFormatters(String guideNodeClass, String[] searchPaths) {
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONArray response = new JSONArray();
JSONObject firstObj = new JSONObject();
firstObj.put("text", (Object)"none");
firstObj.put("value", (Object)"");
response.put((Object)firstObj);
if (guideNodeClass != null && !guideNodeClass.isEmpty() && GuideUtils.listContains(GuideConstants.GUIDE_FIELDS_CLASS_NAMES, guideNodeClass, Boolean.TRUE).booleanValue()) {
for (int i = 0; i < searchPaths.length; ++i) {
Resource format;
String query = "SELECT * FROM nt:base WHERE guideComponentType= 'fd/af/components/formatter/" + guideNodeClass + "' AND jcr:path LIKE '" + searchPaths[i] + "%'";
Iterator formats = resolver.findResources(query, "sql");
if (!formats.hasNext() || (format = (Resource)formats.next()) == null) continue;
ValueMap properties = format.getValueMap();
for (Map.Entry pairs : properties.entrySet()) {
String key = (String)pairs.getKey();
if (!key.startsWith("pattern")) continue;
JSONObject respObj = new JSONObject();
String value = (String)pairs.getValue();
String[] arr = value.split("=", 2);
respObj.put("text", (Object)arr[0]);
respObj.put("value", (Object)arr[1]);
response.put((Object)respObj);
}
}
}
JSONObject lastObj = new JSONObject();
lastObj.put("text", (Object)"Custom");
lastObj.put("value", (Object)"custom");
response.put((Object)lastObj);
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray querySubmitOrAutoSaveAction(String[] searchPaths, Map<String, String> options) {
String type = options.get("type");
String requestedDataModel = options.get("guideDataModel");
String guideComponentType = type.equalsIgnoreCase(SUBMITACTION) ? "fd/af/components/guidesubmittype" : "fd/af/components/guideautosavetype";
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
ArrayList<String> listOfSubmitAction = new ArrayList<String>();
JSONArray response = new JSONArray();
for (int i = 0; i < searchPaths.length; ++i) {
Iterator actions = resolver.findResources("SELECT * FROM nt:base WHERE guideComponentType = '" + guideComponentType + "' AND jcr:path LIKE '" + searchPaths[i] + "%'", "sql");
if (actions == null) continue;
while (actions.hasNext()) {
Resource r = (Resource)actions.next();
String value = r.getPath();
if (value.startsWith("/libs/") || value.startsWith("/apps/")) {
value = value.substring(6);
}
ValueMap properties = r.getValueMap();
String text = (String)properties.get("jcr:description", (Object)"");
String qtip = (String)properties.get("qtip", (Object)"");
Boolean addOption = true;
if (requestedDataModel != null) {
String dataModel = (String)properties.get("guideDataModel", (Object)"");
addOption = dataModel.toLowerCase().contains(requestedDataModel.toLowerCase()) ? Boolean.valueOf(true) : Boolean.valueOf(false);
}
if (!addOption.booleanValue() || listOfSubmitAction.contains(value)) continue;
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)text);
listOfSubmitAction.add(value);
respObj.put("value", (Object)value);
respObj.put("qtip", (Object)qtip);
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray queryLcProcess() {
try {
JSONArray response = new JSONArray();
List<String> services = this.guideLCServiceConnector.getServices();
for (String s : services) {
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)s);
respObj.put("value", (Object)s);
response.put((Object)respObj);
}
return response;
}
catch (Exception e) {
this.logger.error("Cannot fetch LCServices", (Throwable)e);
throw new GuideException(e);
}
}
public JSONArray queryMobileLayout(String[] searchPaths) {
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONArray response = new JSONArray();
ArrayList<String> listOfMobileLayoutPath = new ArrayList<String>();
for (int i = 0; i < searchPaths.length; ++i) {
Iterator layouts = resolver.findResources("SELECT * FROM nt:base WHERE guideComponentType = 'fd/af/layouts/mobile' AND jcr:path LIKE '" + searchPaths[i] + "%'", "sql");
if (layouts == null) continue;
while (layouts.hasNext()) {
Resource r = (Resource)layouts.next();
String path = r.getPath();
String desc = NodeStructureUtils.getLayoutDescription(r);
if (path.startsWith("/libs/") || path.startsWith("/apps/")) {
path = path.substring(6);
}
if (listOfMobileLayoutPath.contains(path)) continue;
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)(desc == null ? r.getPath() : desc));
String qtip = NodeStructureUtils.getLayoutQtip(r);
respObj.put("qtip", (Object)qtip);
listOfMobileLayoutPath.add(path);
respObj.put("value", (Object)path);
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray queryChartReducer(String[] searchPaths) {
JSONArray response = new JSONArray();
try {
JSONObject firstObj = new JSONObject();
firstObj.put("text", (Object)"None");
firstObj.put("value", (Object)"none");
firstObj.put("qtip", (Object)"None");
response.put((Object)firstObj);
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
for (int i = 0; i < searchPaths.length; ++i) {
Iterator reducerFunctions = resolver.findResources("SELECT * FROM nt:base WHERE guideComponentType = 'fd/af/reducer' AND jcr:path LIKE '" + searchPaths[i] + "%'", "sql");
if (reducerFunctions == null) continue;
while (reducerFunctions.hasNext()) {
String qtip;
Resource r = (Resource)reducerFunctions.next();
ValueMap properties = r.getValueMap();
String val = (String)properties.get((Object)"value");
if (StringUtils.isEmpty((String)val)) continue;
String text = NodeStructureUtils.getLayoutDescription(r);
if (StringUtils.isEmpty((String)text)) {
text = val;
}
if (StringUtils.isEmpty((String)(qtip = NodeStructureUtils.getLayoutQtip(r)))) {
qtip = text;
}
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)text);
respObj.put("value", (Object)val);
respObj.put("qtip", (Object)qtip);
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
public JSONArray fetchEsignCloudServiceConfiguration(String rootPath, ResourceResolver resourceResolver) {
JSONArray response = new JSONArray();
try {
ConfigurationManager configManager = (ConfigurationManager)resourceResolver.adaptTo(ConfigurationManager.class);
if (rootPath != null) {
com.day.cq.wcm.webservicesupport.Service service = configManager.getService(configManager.getServiceName(rootPath));
Iterator iter = configManager.getConfigurations(rootPath);
while (iter.hasNext()) {
Configuration cfg = (Configuration)iter.next();
Template template = cfg.getTemplate();
if (template == null || service == null || !service.isSelectableChild(template.getPath()).booleanValue()) continue;
String description = cfg.getDescription() != null ? cfg.getDescription() : template.getDescription();
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)cfg.getTitle());
respObj.put("value", (Object)cfg.getPath());
respObj.put("icon", (Object)cfg.getIconPath());
respObj.put("description", (Object)description);
response.put((Object)respObj);
}
} else {
this.logger.warn("Missing parameter for 'rootPath'");
}
}
catch (Exception e) {
this.logger.error("Unexpected error while listing cloudservice configs: ", (Throwable)e);
}
return response;
}
private String getComponentTemplatePath(Resource componentResource) {
try {
Node componentNode = (Node)componentResource.adaptTo(Node.class);
ValueMap componentProperties = (ValueMap)componentResource.adaptTo(ValueMap.class);
String templatePath = (String)componentProperties.get((Object)"cq:templatePath");
if (templatePath == null && componentNode.hasNode("cq:template")) {
templatePath = componentNode.getNode("cq:template").getPath();
}
return templatePath;
}
catch (Exception e) {
throw new GuideException(e);
}
}
public Iterator<JSONObject> getJSONIterator(JSONArray arr) {
return new JSONArrayIterator(arr);
}
public Map<String, Object> getMapFromJSONObject(JSONObject object) {
HashMap<String, Object> map = new HashMap<String, Object>();
Object jsonObject = null;
try {
Iterator keys = object.keys();
while (keys.hasNext()) {
String key = (String)keys.next();
Object value = object.get(key);
if (value instanceof JSONObject) {
map.put(key, this.getMapFromJSONObject((JSONObject)value));
continue;
}
if (value instanceof JSONArray) {
JSONArray array = (JSONArray)value;
ArrayList<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); ++i) {
jsonObject = array.get(i);
if (jsonObject instanceof JSONObject) {
list.add(this.getMapFromJSONObject((JSONObject)jsonObject));
continue;
}
list.add(jsonObject);
}
map.put(key, list);
continue;
}
map.put(key, value);
}
return map;
}
catch (JSONException e) {
throw new IllegalStateException((Throwable)e);
}
}
public JSONArray queryDocumentFragmentLayout(String[] searchPaths) {
try {
JSONArray response = new JSONArray();
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
JSONObject firstObj = new JSONObject();
firstObj.put("text", (Object)"");
firstObj.put("value", (Object)"");
response.put((Object)firstObj);
for (int i = 0; i < searchPaths.length; ++i) {
String query = "SELECT * FROM nt:base WHERE guideComponentType = 'fd/adaddon/documentFragmentLayout' AND jcr:path LIKE '" + searchPaths[i] + "%'";
Iterator layouts = resolver.findResources(query, "sql");
if (layouts == null) continue;
while (layouts.hasNext()) {
Resource r = (Resource)layouts.next();
ValueMap properties = r.getValueMap();
String desc = NodeStructureUtils.getLayoutDescription(r);
JSONObject respObj = new JSONObject();
respObj.put("text", (Object)(desc == null ? r.getPath() : desc));
respObj.put("value", properties.get("layout", (Object)""));
response.put((Object)respObj);
}
}
return response;
}
catch (JSONException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException((Exception)e);
}
}
protected void bindGuideLCServiceConnector(GuideLCServiceConnector guideLCServiceConnector) {
this.guideLCServiceConnector = guideLCServiceConnector;
}
protected void unbindGuideLCServiceConnector(GuideLCServiceConnector guideLCServiceConnector) {
if (this.guideLCServiceConnector == guideLCServiceConnector) {
this.guideLCServiceConnector = null;
}
}
protected void bindGuideProgressiveStrategyManager(GuideProgressiveStrategyManager guideProgressiveStrategyManager) {
this.guideProgressiveStrategyManager = guideProgressiveStrategyManager;
}
protected void unbindGuideProgressiveStrategyManager(GuideProgressiveStrategyManager guideProgressiveStrategyManager) {
if (this.guideProgressiveStrategyManager == guideProgressiveStrategyManager) {
this.guideProgressiveStrategyManager = null;
}
}
protected void bindExpressionEditorService(ExpressionEditorService expressionEditorService) {
this.expressionEditorService = expressionEditorService;
}
protected void unbindExpressionEditorService(ExpressionEditorService expressionEditorService) {
if (this.expressionEditorService == expressionEditorService) {
this.expressionEditorService = null;
}
}
protected void bindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
this.htmlLibraryManager = htmlLibraryManager;
}
protected void unbindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
if (this.htmlLibraryManager == htmlLibraryManager) {
this.htmlLibraryManager = null;
}
}
protected void bindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
this.resourceResolverHelper = resourceResolverHelper;
}
protected void unbindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
if (this.resourceResolverHelper == resourceResolverHelper) {
this.resourceResolverHelper = null;
}
}
protected void bindPrefillRegistry(FormDataXMLProviderRegistry formDataXMLProviderRegistry) {
this.prefillRegistry = formDataXMLProviderRegistry;
}
protected void unbindPrefillRegistry(FormDataXMLProviderRegistry formDataXMLProviderRegistry) {
if (this.prefillRegistry == formDataXMLProviderRegistry) {
this.prefillRegistry = null;
}
}
}