GuideModelTransformerImpl.java
55.5 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
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.forms.common.service.DataXMLOptions
* com.adobe.forms.common.service.FormDataXMLProviderRegistry
* com.adobe.forms.common.service.FormsCommonConfigurationService
* com.adobe.forms.common.service.StaleAssetIndicatorService
* com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
* com.day.cq.commons.Externalizer
* com.day.cq.i18n.I18n
* com.day.cq.wcm.api.WCMMode
* com.day.cq.widget.ClientLibrary
* com.day.cq.widget.HtmlLibraryManager
* com.day.cq.widget.LibraryType
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.servlet.ServletRequest
* org.apache.commons.io.IOUtils
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* 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.ResourceResolverFactory
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.classloader.DynamicClassLoaderManager
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.apache.sling.commons.osgi.OsgiUtil
* org.apache.sling.commons.osgi.ServiceUtil
* org.apache.sling.jcr.api.SlingRepository
* org.mozilla.javascript.Scriptable
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.service.impl;
import com.adobe.aemds.guide.cache.Cache;
import com.adobe.aemds.guide.cache.CacheManager;
import com.adobe.aemds.guide.common.GuideContainer;
import com.adobe.aemds.guide.common.GuideError;
import com.adobe.aemds.guide.common.GuideValidationResult;
import com.adobe.aemds.guide.common.ResourcePropertyTransformer;
import com.adobe.aemds.guide.service.AdaptiveFormConfigurationService;
import com.adobe.aemds.guide.service.GuideDraftStateProvider;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideLocalizationService;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.service.GuideModuleImporter;
import com.adobe.aemds.guide.service.GuideStoreContentSubmission;
import com.adobe.aemds.guide.service.JsonObjectCreator;
import com.adobe.aemds.guide.service.XFAModelTransformer;
import com.adobe.aemds.guide.service.external.GuideDataMergerSPI;
import com.adobe.aemds.guide.utils.CustomJSONWriter;
import com.adobe.aemds.guide.utils.DocumentDataMerger;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideContainerThreadLocal;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.JSONCreationOptions;
import com.adobe.aemds.guide.utils.KeyValueDataMerger;
import com.adobe.aemds.guide.utils.ValueMapDataMerger;
import com.adobe.aemds.guide.utils.XMLUtils;
import com.adobe.aemds.guide.utils.XsdDocumentDataMerger;
import com.adobe.aemds.guide.utils.rhino.GuideFunctionObject;
import com.adobe.aemds.guide.utils.rhino.GuideScriptObject;
import com.adobe.aemds.guide.utils.rhino.RhinoScriptProcessor;
import com.adobe.forms.common.service.DataXMLOptions;
import com.adobe.forms.common.service.FormDataXMLProviderRegistry;
import com.adobe.forms.common.service.FormsCommonConfigurationService;
import com.adobe.forms.common.service.StaleAssetIndicatorService;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import com.day.cq.commons.Externalizer;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.WCMMode;
import com.day.cq.widget.ClientLibrary;
import com.day.cq.widget.HtmlLibraryManager;
import com.day.cq.widget.LibraryType;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.ServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.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.ResourceResolverFactory;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.commons.osgi.ServiceUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.mozilla.javascript.Scriptable;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(immediate=1, metatype=1, label="Adaptive Form Json Transformer", description="Adaptive Form Json Transformer Service")
@Service(value={GuideModelTransformer.class})
public class GuideModelTransformerImpl
implements GuideModelTransformer {
private Logger logger = LoggerFactory.getLogger(GuideModelTransformerImpl.class);
@org.apache.felix.scr.annotations.Property(name="enforceServerUrlConfig", boolValue={0}, label="Enforce Server URL Configuration", description="Enforce the use of server url from externalizer service(com.day.cq.commons.impl.ExternalizerImpl) for making rest calls when doing Adaptive Form Server side validation")
private Boolean enforceServerUrlConfig;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private XFAModelTransformer xfaModelTransformerService;
@Reference
private FormsCommonConfigurationService formsCommonConfigurationService;
@Reference
private GuideLocalizationService guideLocalizationService;
@Reference
private DynamicClassLoaderManager dynamicClassLoaderManager;
@Reference
private GuideStoreContentSubmission guideStoreContentSubmission;
@Reference
private HtmlLibraryManager htmlLibraryManager;
@Reference
private SlingRepository repository;
@Reference
private ResourceResolverHelper resourceResolverHelper;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private Externalizer externalizer;
@Reference
private JsonObjectCreator jsonObjectCreator;
@Reference
private AdaptiveFormConfigurationService adaptiveFormConfigurationService;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private StaleAssetIndicatorService staleAssetIndicatorService;
@Reference
private CacheManager cacheManager;
@Reference
private FormDataXMLProviderRegistry formDataXMLProviderRegistry;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private GuideModuleImporter guideModuleImporter;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private GuideDataMergerSPI guideDataMerger;
private final int ENV_RHINO_PARSER = 8;
private ArrayList<String> xfaSpecificScript;
private ArrayList<String> envScript = null;
private ArrayList<String> scriptToLoadBeforeXFA = null;
private ArrayList<String> scriptToLoadAfterXFA = null;
private ArrayList<String> localeSpecificLibs = null;
private final AtomicBoolean isActivateSuccess = new AtomicBoolean(false);
private final Locale defaultFallBackLocaleObject = new Locale("en");
@Reference(name="guideDraftStateProvider", referenceInterface=GuideDraftStateProvider.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
private Map<Comparable<Object>, GuideDraftStateProvider> providers = new ConcurrentSkipListMap(Collections.reverseOrder());
protected void activate(ComponentContext context) {
Dictionary props = context.getProperties();
this.enforceServerUrlConfig = OsgiUtil.toBoolean(props.get("enforceServerUrlConfig"), (boolean)false);
this.isActivateSuccess.set(this.checkIfScriptsCachedDuringActivation());
}
private String[] getAemSupportedLocales() {
String[] aemSupportedlocales = this.guideLocalizationService != null ? this.guideLocalizationService.getSupportedLocales() : GuideConstants.AEM_SUPPORTED_LOCALES;
return aemSupportedlocales;
}
private boolean checkIfScriptsCachedDuringActivation() {
return this.scriptToLoadBeforeXFA != null && this.xfaSpecificScript != null && this.scriptToLoadAfterXFA != null && this.envScript != null && this.scriptToLoadBeforeXFA.get(0) != null && this.xfaSpecificScript.get(0) != null && this.scriptToLoadAfterXFA.get(0) != null && this.envScript.get(0) != null;
}
private void compileAndCacheGuideStaticScripts() {
int i;
String script;
this.localeSpecificLibs = this.getAllLocaleSpecificLibs();
this.scriptToLoadBeforeXFA = this.getScriptToLoadBeforeXFA();
this.xfaSpecificScript = this.getXFASpecficScript();
this.scriptToLoadAfterXFA = this.getScriptToLoadAfterXFA();
this.envScript = this.getEnvRhinoModules();
for (int i2 = 0; i2 < this.envScript.size(); ++i2) {
String script2 = this.envScript.get(i2);
if (script2 == null || i2 == 8) continue;
RhinoScriptProcessor.compileAndCache(this.envScript.get(i2), "envScript" + i2);
}
String[] aemSupportedLocales = this.getAemSupportedLocales();
for (i = 0; i < this.localeSpecificLibs.size(); ++i) {
script = this.localeSpecificLibs.get(i);
if (script == null) continue;
RhinoScriptProcessor.compileAndCache(script, "localeSpecificLib" + aemSupportedLocales[i]);
}
for (i = 0; i < this.scriptToLoadBeforeXFA.size(); ++i) {
script = this.scriptToLoadBeforeXFA.get(i);
if (script == null) continue;
RhinoScriptProcessor.compileAndCache(script, "scriptToLoadBeforeXFA" + i);
}
for (i = 0; i < this.xfaSpecificScript.size(); ++i) {
script = this.xfaSpecificScript.get(i);
if (script == null) continue;
RhinoScriptProcessor.compileAndCache(script, "xfaSpecificScript" + i);
}
for (i = 0; i < this.scriptToLoadAfterXFA.size(); ++i) {
script = this.scriptToLoadAfterXFA.get(i);
if (script == null) continue;
RhinoScriptProcessor.compileAndCache(script, "scriptToLoadAfterXFA" + i);
}
}
private ArrayList<String> getScriptToLoadBeforeXFA() {
String[] clientLibCommonCategories = new String[]{"xfaforms.xfalibutil", "xfaforms.xfalibwidgets"};
return GuideUtils.getScriptFromClientLibList(this.htmlLibraryManager, clientLibCommonCategories);
}
private String getLocaleScriptToLoadBeforeXFA(String locale) {
int index = GuideUtils.getLocaleIndexFromLocale(locale, this.getAemSupportedLocales());
String[] GUIDES_SUPPORTED_CLIENTLIBS = GuideUtils.sanitizeLocaleList(this.getAemSupportedLocales());
String[] clientLibCommonCategories = new String[]{"guides.I18N." + GUIDES_SUPPORTED_CLIENTLIBS[index]};
ArrayList<String> script = GuideUtils.getScriptFromClientLibList(this.htmlLibraryManager, clientLibCommonCategories);
String localeScript = "";
if (script != null && script.size() > 0) {
localeScript = script.get(0);
} else {
String[] defaultClientLib = new String[]{"guides.I18N.en"};
ArrayList<String> defaultScript = GuideUtils.getScriptFromClientLibList(this.htmlLibraryManager, defaultClientLib);
localeScript = defaultScript.get(0);
}
return localeScript;
}
private ArrayList<String> getAllLocaleSpecificLibs() {
String[] aemSupportedLocales = this.getAemSupportedLocales();
ArrayList<String> scriptToLoadBeforeXFAForAllLocales = new ArrayList<String>(aemSupportedLocales.length);
for (String locale : aemSupportedLocales) {
scriptToLoadBeforeXFAForAllLocales.add(this.getLocaleScriptToLoadBeforeXFA(locale));
}
return scriptToLoadBeforeXFAForAllLocales;
}
private ArrayList<String> getXFASpecficScript() {
String[] clientLibXfaCategories = new String[]{"xfaforms.formbridge", "xfaforms.formcalc", "xfaforms.xfalibCoreModel", "xfaforms.xfalibDomModel"};
return GuideUtils.getScriptFromClientLibList(this.htmlLibraryManager, clientLibXfaCategories);
}
private ArrayList<String> getEnvRhinoModules() {
ArrayList<String> envScript = new ArrayList<String>();
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/platform/core.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/platform/rhino.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/console.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/dom.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/event.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/timer.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/html.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/css.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/parser.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/xhr.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/third-party/javascript/envjs/window.js"));
envScript.add(this.readFile("/etc/clientlibs/fd/af/guidelib/javascript/EnvRhinoFixes.js"));
return envScript;
}
private ArrayList<String> getScriptToLoadAfterXFA() {
String[] clientLibToLoadAfterXfa = new String[]{"guides.3rdparty", "guides.guidelib", "af.customwidgets", "cqguides.signing"};
return GuideUtils.getScriptFromClientLibList(this.htmlLibraryManager, clientLibToLoadAfterXfa);
}
@Override
public String exportGuideJson(Resource guideContainer, I18n i18n) throws GuideException {
return this.exportGuideJson(guideContainer, i18n, this.defaultFallBackLocaleObject);
}
@Override
public String exportGuideJson(Resource guideContainer, I18n i18n, Locale locale) throws GuideException {
JSONObject guideJson = this.exportGuideJsonObject(guideContainer, i18n, locale);
return guideJson.toString();
}
@Override
public JSONObject exportGuideJsonObject(Resource guideContainer) {
return this.exportGuideJsonObject(guideContainer, null, this.defaultFallBackLocaleObject);
}
@Override
public JSONObject exportGuideJsonObject(Resource guideContainer, I18n i18n) {
return this.exportGuideJsonObject(guideContainer, i18n, this.defaultFallBackLocaleObject);
}
@Override
public JSONObject exportGuideJsonObject(Resource guideContainer, I18n i18n, Locale locale) {
JSONCreationOptions jsonCreationOptions = new JSONCreationOptions(i18n, true, true, locale, guideContainer);
return this.exportGuideJsonObject(guideContainer, jsonCreationOptions);
}
@Override
public JSONObject exportGuideJsonObject(Resource guideContainer, JSONCreationOptions jsonCreationOptions) {
try {
String locale = jsonCreationOptions.getLocale().toString();
String key = guideContainer.getPath() + "_" + locale;
Cache guideJsonCache = this.cacheManager.getOrCreateCache("cache.json");
Map jsonMap = (Map)guideJsonCache.get(key);
JSONObject guideJson = null;
if (jsonMap != null) {
this.logger.debug("Guide Json Cache hit for guideContainer " + guideContainer.getPath());
String sGuideJson = (String)jsonMap.get("guidejson");
if (!StringUtils.isEmpty((CharSequence)sGuideJson)) {
guideJson = new JSONObject(sGuideJson);
}
}
if (guideJson == null) {
GuideContainerThreadLocal.setGuideFragmentHolder(null, null, null, null);
guideJson = this.jsonObjectCreator.createWithContext(guideContainer, -1, jsonCreationOptions);
GuideContainerThreadLocal.setGuideFragmentHolder(null, null, null, null);
this.logger.debug("Guide Json Cache miss for guideContainer " + guideContainer.getPath());
}
if (guideJson.has("assets")) {
guideJson.remove("assets");
}
return guideJson;
}
catch (Exception e) {
this.logger.error("Error in exporting guide json", (Throwable)e);
throw new GuideException(e);
}
}
@Override
public Map<String, String> exportXfaJson(Resource guideContainer) throws GuideException {
try {
ValueMap valueMap = (ValueMap)guideContainer.adaptTo(ValueMap.class);
String formPath = (String)valueMap.get((Object)"xdpRef");
if (formPath == null || formPath.length() == 0 || !GuideUtils.isXDPValid(guideContainer)) {
return null;
}
return this.xfaModelTransformerService.exportXfaJson(guideContainer, null, null);
}
catch (Exception e) {
this.logger.error("Error in exporting xfa json", (Throwable)e);
throw new GuideException(e);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public String exportGuideState(String guideStatePath) throws GuideException {
String result = null;
try {
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
Resource slingResource = resolver.resolve(guideStatePath);
Node jcrNode = (Node)slingResource.adaptTo(Node.class);
InputStream is = jcrNode.getProperty("jcr:data").getBinary().getStream();
BufferedInputStream bin = new BufferedInputStream(is);
try {
result = new String(this.readStream(bin), "UTF-8");
}
finally {
bin.close();
is.close();
}
}
catch (Exception e) {
this.logger.error("Error in exporting merged json", (Throwable)e);
throw new GuideException(e);
}
return result;
}
@Override
public String exportGuideStateFromStore(String guideStatePathRef) throws GuideException {
String result;
result = null;
try {
for (GuideDraftStateProvider provider : this.getProviders()) {
try {
String state = provider.getGuideDraftState(guideStatePathRef);
if (state == null) continue;
result = state;
break;
}
catch (Exception e) {
this.logger.error("The current provider could not return the guidestate" + e.getMessage(), (Throwable)e);
continue;
}
}
}
catch (Exception e) {
this.logger.error("Error in exporting merged json from ref", (Throwable)e);
throw new GuideException(e);
}
return result;
}
private Collection<GuideDraftStateProvider> getProviders() {
return this.providers.values();
}
private void writeDataJson(Resource guideContainer, CustomJSONWriter jsonWriter, JSONCreationOptions options) throws GuideException {
block19 : {
try {
String formContainerPath = options.getFormContainerPath();
I18n i18n = options.getI18n();
String dataRef = options.getDataRef();
ValueMap resourceProps = ResourceUtil.getValueMap((Resource)guideContainer);
String prefillService = (String)resourceProps.get((Object)"prefillService");
ResourceResolver resolver = guideContainer.getResourceResolver();
DataXMLOptions dataXMLOptions = new DataXMLOptions();
dataXMLOptions.setAemFormContainer(resolver.getResource(formContainerPath)).setFormResource(guideContainer);
String data = options.getData();
InputStream inputStream = null;
if (data == null) {
if (dataRef != null) {
dataXMLOptions.setDataRef(dataRef);
inputStream = this.formDataXMLProviderRegistry.getDataXMLStreamFromService(dataXMLOptions);
} else if (prefillService != null) {
dataXMLOptions.setServiceName(prefillService);
inputStream = this.formDataXMLProviderRegistry.getDataXMLStreamFromService(dataXMLOptions);
}
} else {
inputStream = new ByteArrayInputStream(data.getBytes("UTF-8"));
}
if (inputStream == null) break block19;
ValueMap guideProps = (ValueMap)guideContainer.adaptTo(ValueMap.class);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = null;
try {
doc = builder.parse(inputStream);
}
catch (SAXException e) {
this.logger.error("Error in parsing prefill xml from data Ref", (Throwable)e);
}
catch (IOException e) {
this.logger.error("Error in reading prefill xml from data Ref", (Throwable)e);
}
if (doc != null) {
boolean startsWithAfData = XMLUtils.isWrappedXml(doc);
if (GuideUtils.isTargetEnabled(guideContainer)) {
jsonWriter.key("completeDataXML").value(XMLUtils.getXMLfromXsdDom(doc.getDocumentElement()));
}
JSONObject templateJson = this.exportGuideJsonObject(guideContainer);
boolean hasEmbeddedXsdForms = templateJson.optBoolean("isHasEmbeddedXsdForm");
if (guideProps.get((Object)"xdpRef") != null && GuideUtils.isXDPValid(guideContainer)) {
this.getExportedXfaData(guideContainer, jsonWriter, XMLUtils.getBoundDataXmlPart(doc), null);
if (startsWithAfData) {
jsonWriter.key("unboundDataMap").value((Object)XMLUtils.getMapOfUnboundData(doc));
jsonWriter.key("guidePrefillXml").value(XMLUtils.getPrefillXmlWithoutBoundPart(doc));
}
} else if (guideProps.get((Object)"xsdRef") != null || guideProps.get((Object)"letterRef") != null || guideProps.get((Object)"ddRef") != null || guideProps.get((Object)"xdpRef") == null && hasEmbeddedXsdForms) {
String boundDataXmlStr = XMLUtils.getBoundDataXmlPart(doc);
if (StringUtils.isNotBlank((CharSequence)boundDataXmlStr)) {
Document boundDoc = builder.parse(new ByteArrayInputStream(boundDataXmlStr.getBytes("UTF-8")));
this.getExportedGuideData(guideContainer, jsonWriter, boundDoc, i18n);
}
if (startsWithAfData) {
jsonWriter.key("unboundDataMap").value((Object)XMLUtils.getMapOfUnboundData(doc));
}
jsonWriter.key("guidePrefillXml").value(XMLUtils.getXMLfromXsdDom(doc.getDocumentElement()));
} else {
Document unBoundDoc = builder.parse(new ByteArrayInputStream(XMLUtils.getUnboundDataXmlPart(doc).getBytes("UTF-8")));
this.getExportedGuideData(guideContainer, jsonWriter, unBoundDoc, i18n);
jsonWriter.key("guidePrefillXml").value(XMLUtils.getPrefillXmlWithoutBoundPart(doc));
}
}
}
catch (Exception e) {
this.logger.error("Error in creating data merged json from data Ref", (Throwable)e);
throw new GuideException(e);
}
}
}
@Override
public String getDataJson(Resource guideContainer, JSONCreationOptions options) {
StringWriter stringWriter = new StringWriter();
CustomJSONWriter jsonWriter = new CustomJSONWriter(stringWriter);
jsonWriter.object();
jsonWriter.key("guideState").object();
try {
this.writeDataJson(guideContainer, jsonWriter, options);
}
catch (Exception e) {
throw new GuideException(e);
}
jsonWriter.endObject();
jsonWriter.endObject();
String result = stringWriter.toString();
return result;
}
@Override
public String exportGuideDataJsonFromDataRef(Resource guideContainer, String dataRef, I18n i18n) {
String result = null;
try {
JSONCreationOptions options = new JSONCreationOptions();
options.setDataRef(dataRef);
options.setI18n(i18n);
result = this.getDataJson(guideContainer, options);
}
catch (Exception e) {
this.logger.error("Error in creating data merged json from data Ref", (Throwable)e);
throw new GuideException(e);
}
return result;
}
@Override
public String exportGuideDataJson(Resource guideContainer, String data, I18n i18n) {
String result = null;
try {
JSONCreationOptions options = new JSONCreationOptions();
options.setData(data);
options.setI18n(i18n);
result = this.getDataJson(guideContainer, options);
}
catch (Exception e) {
this.logger.error("Error in creating data merged json from data", (Throwable)e);
throw new GuideException(e);
}
return result;
}
private void getExportedXfaData(Resource guideContainer, CustomJSONWriter jsonWriter, String data, String dataRef) {
Map<String, String> xfaResult = this.xfaModelTransformerService.exportXfaJson(guideContainer, data, dataRef);
jsonWriter.key("xfaState").object();
jsonWriter.key("xfaDom").value(xfaResult.get("mergedformdom"));
jsonWriter.key("xfaRenderContext").value(xfaResult.get("xfaRenderContext"));
jsonWriter.endObject();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void getExportedGuideData(Resource guideContainer, CustomJSONWriter jsonWriter, Document doc, I18n i18n) throws GuideException {
JSONObject guideJSON = this.exportGuideJsonObject(guideContainer, i18n);
ValueMap guideProps = (ValueMap)guideContainer.adaptTo(ValueMap.class);
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(GuideModuleImporter.class.getName(), this.guideModuleImporter);
try {
if (doc != null) {
boolean isXsd = guideProps.get((Object)"xsdRef") != null;
String ddRef = (String)guideProps.get((Object)"ddRef");
String letterRef = (String)guideProps.get((Object)"letterRef");
ClassLoader dynamicClassLoader = this.dynamicClassLoaderManager.getDynamicClassLoader();
ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
KeyValueDataMerger keyValueDataMerge;
Thread.currentThread().setContextClassLoader(dynamicClassLoader);
JSONObject templateJson = this.exportGuideJsonObject(guideContainer);
boolean hasEmbeddedXsdForms = templateJson.optBoolean("isHasEmbeddedXsdForm");
if (this.guideDataMerger != null && (ddRef != null || letterRef != null)) {
keyValueDataMerge = this.guideDataMerger.createDataMerger(guideJSON, doc, params);
} else if (isXsd || hasEmbeddedXsdForms) {
keyValueDataMerge = new XsdDocumentDataMerger(guideJSON, doc, params);
} else {
if (this.guideModuleImporter != null) {
this.guideModuleImporter.extractVariablesFromData(doc, params);
}
keyValueDataMerge = new DocumentDataMerger(guideJSON, doc, params);
}
jsonWriter.key("guideDom").value((Object)keyValueDataMerge.merge());
}
finally {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
}
String loadPath = (String)guideProps.get("loadPath", String.class);
if (loadPath != null) {
ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
Resource initialDataResource = resourceResolver.resolve(loadPath);
ValueMap valueMap = (ValueMap)initialDataResource.adaptTo(ValueMap.class);
ValueMapDataMerger keyValueDataMerge = new ValueMapDataMerger(guideJSON, valueMap, params);
jsonWriter.key("guideDom").value((Object)keyValueDataMerge.merge());
}
}
catch (Exception e) {
this.logger.error("Error in creating data merged json", (Throwable)e);
throw new GuideException(e);
}
}
private byte[] readStream(InputStream inputStream) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int length = 0;
length = inputStream.read(buffer);
while (length != -1) {
baos.write(buffer, 0, length);
length = inputStream.read(buffer);
}
return baos.toByteArray();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public String readFile(String path) {
Resource resource = null;
StringWriter writer = null;
Node fileNode = null;
Node jcrContent = null;
InputStream content = null;
try {
if (this.resourceResolverHelper.getResourceResolver() != null) {
resource = this.resourceResolverHelper.getResourceResolver().getResource(path);
fileNode = (Node)resource.adaptTo(Node.class);
jcrContent = fileNode.getNode("jcr:content");
content = jcrContent.getProperty("jcr:data").getBinary().getStream();
} else {
Session serviceSession = null;
try {
serviceSession = this.repository.loginService(null, null);
if (serviceSession.nodeExists(path)) {
fileNode = serviceSession.getNode(path);
jcrContent = fileNode.getNode("jcr:content");
content = jcrContent.getProperty("jcr:data").getBinary().getStream();
}
}
catch (RepositoryException ex) {
this.logger.error("Error in accessing the repository using anonymous session " + path + ex.getMessage(), (Throwable)ex);
}
finally {
if (serviceSession != null) {
serviceSession.logout();
}
}
}
if (content != null) {
writer = new StringWriter();
IOUtils.copy((InputStream)content, (Writer)writer);
content.close();
}
}
catch (IOException ex) {
this.logger.error("Error in reading the file " + path + ex.getMessage(), (Throwable)ex);
}
catch (RepositoryException re) {
this.logger.error("Error in accessing the file " + path + re.getMessage(), (Throwable)re);
}
return writer != null ? writer.toString() : null;
}
private String getSyncXfaScript(String guideJson, String xfaJson) {
StringBuilder syncXfaBuilder = new StringBuilder("");
syncXfaBuilder.append("window.guidelib.model._getGuideJsonWithSyncXfaProps(" + guideJson + "," + xfaJson + ");").append("\n");
return syncXfaBuilder.toString();
}
private ArrayList<String> getExecutionScript(String clientLibRef, String serverUrl, String guideState, String contextPath) {
ArrayList<String> execScript = new ArrayList<String>();
if (clientLibRef != null) {
String[] clientLib = new String[]{clientLibRef};
Collection clientLibrary = this.htmlLibraryManager.getLibraries(clientLib, null, true, false);
Iterator iter = clientLibrary.iterator();
String path = ((ClientLibrary)iter.next()).getPath();
execScript.add(GuideUtils.getScriptAsStringFromClientLib(this.htmlLibraryManager, path));
}
if (serverUrl != null) {
execScript.add("jQuery.support.cors = true;");
execScript.add("window.guideBridge._updateAjaxUrl(\"" + serverUrl + "\");");
}
if (contextPath != null && contextPath.length() > 0) {
execScript.add("window.guideBridge.registerConfig(\"contextPath\",\"" + contextPath + "\");");
}
execScript.add("window.guidelib.model.fireOnContainerDomElementReady(" + guideState + ");");
execScript.add("var errorList = []; window.guideBridge.validate(errorList, null, false); errorList;");
return execScript;
}
private void embedJavaFunctionsIntoRhinoContext(Scriptable scope) {
String[] functionNames;
for (String functionName : functionNames = GuideScriptObject.getExposedMethods()) {
try {
GuideScriptObject scriptObject = new GuideScriptObject(this.xfaModelTransformerService);
scriptObject.setParentScope(scope);
Method scriptableInstanceMethod = GuideScriptObject.class.getMethod(functionName, Object.class);
GuideFunctionObject boundJavascriptFunction = new GuideFunctionObject(functionName, scriptableInstanceMethod, (Scriptable)scriptObject);
scope.put(functionName, scope, (Object)boundJavascriptFunction);
continue;
}
catch (Exception ex) {
this.logger.error("Method not found in Guide Script Object " + ex.getMessage(), (Throwable)ex);
}
}
}
private Map<String, String>[] validateInternal(String guideState, Resource guideContainer, String serverUrl, String locale, String contextPath) throws GuideException {
GuideContainer guideContainerBean = new GuideContainer(guideContainer);
String clientLibRef = guideContainerBean.getClientLibRef();
ArrayList<String> execScript = this.getExecutionScript(clientLibRef, serverUrl, guideState, contextPath);
Map[] errorList = null;
Scriptable scope = RhinoScriptProcessor.getRhinoScope();
try {
scope = this.embedGuideStaticScriptsIntoRhino(guideContainerBean, scope, locale);
this.embedJavaFunctionsIntoRhinoContext(scope);
int size = execScript.size();
for (int i = 0; i < size; ++i) {
String script = execScript.get(i);
if (script == null) continue;
if (i == size - 1) {
errorList = (Map[])RhinoScriptProcessor.interpret(script, "execScript" + i, scope);
continue;
}
scope = (Scriptable)RhinoScriptProcessor.interpret(script, "execScript" + i, scope);
}
if (errorList != null && errorList.length >= 0) {
if (errorList.length != 0) {
this.logger.info("Server side validation errors for the Adaptive Form :- " + guideContainer.getPath());
for (int index = 0; index < errorList.length; ++index) {
this.logger.info("SomExpression: " + (String)errorList[index].get("som") + " ErrorMessage: " + (String)errorList[index].get("errorText"));
}
}
return errorList;
}
return null;
}
catch (Exception ex) {
this.logger.error("Error while doing server side validation -" + ex.getMessage(), (Throwable)ex);
throw new GuideException(ex);
}
}
private Scriptable embedGuideStaticScriptsIntoRhino(GuideContainer guideContainer, Scriptable scope, String locale) {
String script;
int i;
String xdpRef = guideContainer.getXdpRef();
if (this.isActivateSuccess.compareAndSet(false, true)) {
this.compileAndCacheGuideStaticScripts();
}
for (int i2 = 0; i2 < this.envScript.size(); ++i2) {
scope = i2 == 8 ? (Scriptable)RhinoScriptProcessor.interpret(this.envScript.get(i2), "parser", scope) : RhinoScriptProcessor.execute(this.envScript.get(i2), "envScript" + i2, scope);
}
String[] aemSupportedLocales = this.getAemSupportedLocales();
int index = GuideUtils.getLocaleIndexFromLocale(locale, aemSupportedLocales);
String localeLib = this.localeSpecificLibs.get(index);
if (localeLib != null) {
scope = RhinoScriptProcessor.execute(localeLib, "localeSpecificLib" + aemSupportedLocales[index], scope);
}
for (i = 0; i < this.scriptToLoadBeforeXFA.size(); ++i) {
script = this.scriptToLoadBeforeXFA.get(i);
if (script == null) continue;
scope = RhinoScriptProcessor.execute(script, "scriptToLoadBeforeXFA" + i, scope);
}
if (xdpRef != null && xdpRef.length() > 0) {
for (i = 0; i < this.xfaSpecificScript.size(); ++i) {
script = this.xfaSpecificScript.get(i);
if (script == null) continue;
scope = RhinoScriptProcessor.execute(script, "xfaSpecificScript" + i, scope);
}
}
for (i = 0; i < this.scriptToLoadAfterXFA.size(); ++i) {
script = this.scriptToLoadAfterXFA.get(i);
if (script == null) continue;
scope = RhinoScriptProcessor.execute(script, "scriptToLoadAfterXFA" + i, scope);
}
scope = (Scriptable)RhinoScriptProcessor.interpret("window.guideBridge.hostName =\"server\";", "setHostName", scope);
return scope;
}
private Map<String, Object> getGuideInitializationStateWithSyncXFAProps(String guideJson, String xfaJson, GuideContainer guideContainer, String locale) {
String syncXfaScript = this.getSyncXfaScript(guideJson, xfaJson);
Map guideJsonWithXfaPropsSync = null;
Scriptable scope = RhinoScriptProcessor.getRhinoScope();
try {
scope = this.embedGuideStaticScriptsIntoRhino(guideContainer, scope, locale);
if (syncXfaScript != null && syncXfaScript.length() > 0) {
guideJsonWithXfaPropsSync = (Map)RhinoScriptProcessor.interpret(syncXfaScript, "syncXfaScript", scope);
}
}
catch (Exception ex) {
this.logger.error("Error during sync xfa props -" + ex.getMessage(), (Throwable)ex);
throw new GuideException(ex);
}
if (guideJsonWithXfaPropsSync != null && guideJsonWithXfaPropsSync.size() > 0) {
return guideJsonWithXfaPropsSync;
}
return null;
}
private HashMap<String, Object> getGuideJsonForLocale(GuideContainer guideContainer, String locale) {
try {
Resource guideResource = guideContainer.getResource();
String[] aemSupportedLocales = this.getAemSupportedLocales();
HashMap<String, Object> guideJsonListForLocale = new HashMap<String, Object>(aemSupportedLocales.length);
Locale localeObject = new Locale(locale);
I18n i18n = GuideUtils.getI18nForDesiredLocale(guideContainer.getSlingRequest(), guideResource, localeObject);
guideJsonListForLocale.put(locale, this.exportGuideJson(guideResource, i18n, localeObject));
return guideJsonListForLocale;
}
catch (Exception e) {
this.logger.error("Error in getGuideJsonForAllLocales", (Throwable)e);
return null;
}
}
@Override
public Map<String, Object> syncXfaProps(GuideContainer guideContainer, String locale) throws GuideException {
try {
Cache guideJsonCache = this.cacheManager.getOrCreateCache("cache.json");
String containerPath = guideContainer.getPath();
String key = containerPath + "_" + locale;
HashMap<String, Object> renderHasMap = null;
Map guideXFAmap = null;
Calendar lastModifiedTime = GuideUtils.getLastModifiedTimeFromStaleAssetIndicatorService(guideContainer, this.staleAssetIndicatorService);
boolean isCacheStale = guideJsonCache.isCacheEntryStale(key, lastModifiedTime);
if (isCacheStale) {
for (String supportedLocale : this.guideLocalizationService.getSupportedLocales()) {
String currentKey = containerPath + "_" + supportedLocale;
guideJsonCache.clear(currentKey);
}
this.logger.debug("resetting cache since the entry is stale");
}
if (!guideJsonCache.entryExists(key)) {
String guideJson = null;
String xfaJson = guideContainer.getXfaJson();
String localeString = GuideUtils.getGuideRuntimeLocale(guideContainer.getSlingRequest(), guideContainer.getResource());
HashMap<String, Object> guideJsonListForAllLocales = this.getGuideJsonForLocale(guideContainer, locale);
guideJson = (String)guideJsonListForAllLocales.get(locale);
if (guideContainer.getXdpRef().length() > 0) {
guideXFAmap = this.getGuideInitializationStateWithSyncXFAProps(guideJson, xfaJson, guideContainer, locale);
} else {
guideXFAmap = new HashMap();
guideXFAmap.put((String)"guidejson", (String)guideJson);
guideXFAmap.put("xfajson", xfaJson);
}
if (guideContainer.getSlingRequest() != null && WCMMode.fromRequest((ServletRequest)guideContainer.getSlingRequest()).equals((Object)WCMMode.DISABLED)) {
guideJsonCache.put(key, guideXFAmap, lastModifiedTime);
if (guideContainer.isRenderCall()) {
String guideJsonString = (String)guideXFAmap.get("guidejson");
JSONObject trimmedJsonObject = GuideUtils.trimLazyChildren(guideJsonString);
renderHasMap = new HashMap();
renderHasMap.put("guidejson", trimmedJsonObject.toString());
renderHasMap.put("xfajson", guideXFAmap.get("xfajson"));
return renderHasMap;
}
}
} else {
guideXFAmap = (HashMap<String, Object>)guideJsonCache.get(key);
}
renderHasMap = guideXFAmap;
if (guideContainer.isRenderCall()) {
String guideJsonString = (String)renderHasMap.get("guidejson");
JSONObject trimmedJsonObject = GuideUtils.trimLazyChildren(guideJsonString);
String xfaJsonString = (String)renderHasMap.get("xfajson");
renderHasMap = new HashMap<String, Object>();
renderHasMap.put("guidejson", trimmedJsonObject.toString());
renderHasMap.put("xfajson", xfaJsonString);
}
return renderHasMap;
}
catch (Exception e) {
this.logger.error("syncXfaProps call failed", (Throwable)e);
return null;
}
}
@Deprecated
@Override
public Map<String, String>[] validate(String dataXml, Resource guideContainerResource, String serverUrl, String locale, String contextPath) throws GuideException {
if (dataXml != null && guideContainerResource != null) {
String newServerUrl = serverUrl;
GuideContainer guideContainer = new GuideContainer(guideContainerResource);
guideContainer.setGuideModelTransformer(this);
if (this.enforceServerUrlConfig.booleanValue()) {
try {
String externalUrl = this.externalizer.externalLink(guideContainerResource.getResourceResolver(), "local", "");
if (externalUrl != null) {
int index = StringUtils.ordinalIndexOf((CharSequence)externalUrl, (CharSequence)"/", (int)3);
if (index != -1) {
newServerUrl = externalUrl.substring(0, index);
new URL(newServerUrl);
} else {
newServerUrl = serverUrl;
}
}
}
catch (MalformedURLException ex) {
newServerUrl = serverUrl;
this.logger.error("URL Provided in Externalizer Service Configuration is invalid. Falling back to URL generated from request object " + ex.getMessage(), (Throwable)ex);
}
catch (IllegalArgumentException ex) {
newServerUrl = serverUrl;
this.logger.error(ex.getMessage(), (Throwable)ex);
}
}
return this.validateInternal(guideContainer.getGuideInitializationState(dataXml, locale), guideContainerResource, newServerUrl, locale, contextPath);
}
return null;
}
@Deprecated
@Override
public Map<String, String>[] validate(String dataXml, Resource guideContainerResource, String serverUrl, String contextPath) throws GuideException {
return this.validate(dataXml, guideContainerResource, serverUrl, "en", contextPath);
}
protected void bindGuideDraftStateProvider(GuideDraftStateProvider provider, Map<String, Object> config) {
this.providers.put(ServiceUtil.getComparableForServiceRanking(config), provider);
}
protected void unbindGuideDraftStateProvider(GuideDraftStateProvider provider, Map<String, Object> config) {
this.providers.remove(ServiceUtil.getComparableForServiceRanking(config));
}
@Override
public GuideValidationResult validateData(String dataXml, Resource guideContainerResource, String serverUrl, String locale, String contextPath) throws GuideException {
if (locale == null) {
locale = "en";
}
List<GuideError> guideErrorList = this.transformValidationData(this.validate(dataXml, guideContainerResource, serverUrl, locale, contextPath));
return new GuideValidationResult(guideErrorList);
}
private List<GuideError> transformValidationData(Map<String, String>[] validationArr) {
if (validationArr == null) {
return null;
}
ArrayList<GuideError> transformedList = new ArrayList<GuideError>();
for (int i = 0; i < validationArr.length; ++i) {
Map<String, String> validationItem = validationArr[i];
transformedList.add(new GuideError(validationItem.get("som"), validationItem.get("errorText")));
}
return transformedList;
}
@Override
public String getAdaptiveFormTreeJSON(Resource guideContainer, ResourcePropertyTransformer transformer) throws JSONException {
JSONCreationOptions options = new JSONCreationOptions();
options.setIncludeFragmentJson(true);
options.setTransformer(transformer);
JSONObject obj = this.jsonObjectCreator.create(guideContainer, -1, options);
return obj.toString();
}
protected void bindXfaModelTransformerService(XFAModelTransformer xFAModelTransformer) {
this.xfaModelTransformerService = xFAModelTransformer;
}
protected void unbindXfaModelTransformerService(XFAModelTransformer xFAModelTransformer) {
if (this.xfaModelTransformerService == xFAModelTransformer) {
this.xfaModelTransformerService = null;
}
}
protected void bindFormsCommonConfigurationService(FormsCommonConfigurationService formsCommonConfigurationService) {
this.formsCommonConfigurationService = formsCommonConfigurationService;
}
protected void unbindFormsCommonConfigurationService(FormsCommonConfigurationService formsCommonConfigurationService) {
if (this.formsCommonConfigurationService == formsCommonConfigurationService) {
this.formsCommonConfigurationService = null;
}
}
protected void bindGuideLocalizationService(GuideLocalizationService guideLocalizationService) {
this.guideLocalizationService = guideLocalizationService;
}
protected void unbindGuideLocalizationService(GuideLocalizationService guideLocalizationService) {
if (this.guideLocalizationService == guideLocalizationService) {
this.guideLocalizationService = null;
}
}
protected void bindDynamicClassLoaderManager(DynamicClassLoaderManager dynamicClassLoaderManager) {
this.dynamicClassLoaderManager = dynamicClassLoaderManager;
}
protected void unbindDynamicClassLoaderManager(DynamicClassLoaderManager dynamicClassLoaderManager) {
if (this.dynamicClassLoaderManager == dynamicClassLoaderManager) {
this.dynamicClassLoaderManager = null;
}
}
protected void bindGuideStoreContentSubmission(GuideStoreContentSubmission guideStoreContentSubmission) {
this.guideStoreContentSubmission = guideStoreContentSubmission;
}
protected void unbindGuideStoreContentSubmission(GuideStoreContentSubmission guideStoreContentSubmission) {
if (this.guideStoreContentSubmission == guideStoreContentSubmission) {
this.guideStoreContentSubmission = null;
}
}
protected void bindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
this.htmlLibraryManager = htmlLibraryManager;
}
protected void unbindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
if (this.htmlLibraryManager == htmlLibraryManager) {
this.htmlLibraryManager = null;
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
this.resourceResolverHelper = resourceResolverHelper;
}
protected void unbindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
if (this.resourceResolverHelper == resourceResolverHelper) {
this.resourceResolverHelper = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindExternalizer(Externalizer externalizer) {
this.externalizer = externalizer;
}
protected void unbindExternalizer(Externalizer externalizer) {
if (this.externalizer == externalizer) {
this.externalizer = null;
}
}
protected void bindJsonObjectCreator(JsonObjectCreator jsonObjectCreator) {
this.jsonObjectCreator = jsonObjectCreator;
}
protected void unbindJsonObjectCreator(JsonObjectCreator jsonObjectCreator) {
if (this.jsonObjectCreator == jsonObjectCreator) {
this.jsonObjectCreator = null;
}
}
protected void bindAdaptiveFormConfigurationService(AdaptiveFormConfigurationService adaptiveFormConfigurationService) {
this.adaptiveFormConfigurationService = adaptiveFormConfigurationService;
}
protected void unbindAdaptiveFormConfigurationService(AdaptiveFormConfigurationService adaptiveFormConfigurationService) {
if (this.adaptiveFormConfigurationService == adaptiveFormConfigurationService) {
this.adaptiveFormConfigurationService = null;
}
}
protected void bindStaleAssetIndicatorService(StaleAssetIndicatorService staleAssetIndicatorService) {
this.staleAssetIndicatorService = staleAssetIndicatorService;
}
protected void unbindStaleAssetIndicatorService(StaleAssetIndicatorService staleAssetIndicatorService) {
if (this.staleAssetIndicatorService == staleAssetIndicatorService) {
this.staleAssetIndicatorService = null;
}
}
protected void bindCacheManager(CacheManager cacheManager) {
this.cacheManager = cacheManager;
}
protected void unbindCacheManager(CacheManager cacheManager) {
if (this.cacheManager == cacheManager) {
this.cacheManager = null;
}
}
protected void bindFormDataXMLProviderRegistry(FormDataXMLProviderRegistry formDataXMLProviderRegistry) {
this.formDataXMLProviderRegistry = formDataXMLProviderRegistry;
}
protected void unbindFormDataXMLProviderRegistry(FormDataXMLProviderRegistry formDataXMLProviderRegistry) {
if (this.formDataXMLProviderRegistry == formDataXMLProviderRegistry) {
this.formDataXMLProviderRegistry = null;
}
}
protected void bindGuideModuleImporter(GuideModuleImporter guideModuleImporter) {
this.guideModuleImporter = guideModuleImporter;
}
protected void unbindGuideModuleImporter(GuideModuleImporter guideModuleImporter) {
if (this.guideModuleImporter == guideModuleImporter) {
this.guideModuleImporter = null;
}
}
protected void bindGuideDataMerger(GuideDataMergerSPI guideDataMergerSPI) {
this.guideDataMerger = guideDataMergerSPI;
}
protected void unbindGuideDataMerger(GuideDataMergerSPI guideDataMergerSPI) {
if (this.guideDataMerger == guideDataMergerSPI) {
this.guideDataMerger = null;
}
}
}