FMUtils.java
60.1 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
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.forms.foundation.service.FormsAssetType
* com.adobe.granite.asset.api.AssetManager
* com.day.cq.replication.ReplicationStatus
* com.day.cq.wcm.api.Template
* com.day.cq.wcm.api.policies.ContentPolicy
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.PathNotFoundException
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.ValueFormatException
* javax.jcr.nodetype.NodeType
* javax.jcr.security.AccessControlManager
* javax.jcr.security.Privilege
* org.apache.commons.lang.StringUtils
* org.apache.jackrabbit.commons.JcrUtils
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ModifiableValueMap
* 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.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.apache.sling.event.jobs.JobManager
* org.apache.sling.event.jobs.ScheduledJobInfo
* org.apache.sling.jcr.api.SlingRepository
* org.apache.sling.jcr.resource.JcrResourceUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aem.formsndocuments.util;
import com.adobe.aem.formsndocuments.transferobjects.AssetInfo;
import com.adobe.aem.formsndocuments.util.FMConstants;
import com.adobe.aemforms.fm.exception.FormsMgrException;
import com.adobe.forms.foundation.service.FormsAssetType;
import com.adobe.granite.asset.api.AssetManager;
import com.day.cq.replication.ReplicationStatus;
import com.day.cq.wcm.api.Template;
import com.day.cq.wcm.api.policies.ContentPolicy;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.NodeType;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.Privilege;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ModifiableValueMap;
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.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.event.jobs.JobManager;
import org.apache.sling.event.jobs.ScheduledJobInfo;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.JcrResourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FMUtils {
private static final Logger log = LoggerFactory.getLogger(FMUtils.class);
public static Node getMetadataNode(Node formNode, boolean create) throws FormsMgrException {
try {
Node metadataNode = null;
Node contentNode = FMUtils.getContentNode(formNode, create);
if (contentNode != null) {
if (!contentNode.hasNode("metadata")) {
if (create) {
metadataNode = contentNode.addNode("metadata", "{http://www.jcp.org/jcr/nt/1.0}unstructured");
}
} else {
metadataNode = contentNode.getNode("metadata");
}
}
return metadataNode;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static Node getMetadataNode(Session session, String formPath, boolean create) throws FormsMgrException {
try {
Node metadataNode = null;
if (session != null) {
Node formNode = session.getNode(FMUtils.getAssetPathFromPage(formPath));
metadataNode = FMUtils.getMetadataNode(formNode, create);
}
return metadataNode;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static Node getAnalyticsDataNode(Node formNode, boolean create) throws FormsMgrException {
try {
Node analyticsDataNode = null;
Node contentNode = FMUtils.getContentNode(formNode, create);
if (contentNode != null) {
if (!contentNode.hasNode("analyticsdatanode")) {
if (create) {
analyticsDataNode = contentNode.addNode("analyticsdatanode", "{http://www.jcp.org/jcr/nt/1.0}unstructured");
}
} else {
analyticsDataNode = contentNode.getNode("analyticsdatanode");
}
}
return analyticsDataNode;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static Node getContentNode(Node formNode, boolean create) throws FormsMgrException {
try {
Node contentNode = null;
if (!formNode.hasNode("jcr:content")) {
if (create) {
contentNode = formNode.addNode("jcr:content", "dam:AssetContent");
}
} else {
contentNode = formNode.getNode("jcr:content");
}
return contentNode;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean isFolder(Session session, String path) throws FormsMgrException {
boolean isFolderNode = false;
if (session != null) {
try {
Property prop;
Node folderNode = null;
folderNode = session.getNode(path);
String primaryType = folderNode.getPrimaryNodeType().getName();
if (primaryType.equals("sling:OrderedFolder") && folderNode.hasProperty("lcFolder") && (prop = folderNode.getProperty("lcFolder")).getLong() == (long)FMConstants.FOLDER_STATE.VALID.ordinal()) {
isFolderNode = true;
}
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
return isFolderNode;
}
public static boolean isApplication(Session session, String path) throws FormsMgrException {
boolean isApplicationNode = false;
if (session != null) {
try {
Property prop;
Node applicationNode = null;
applicationNode = session.getNode(path);
if (applicationNode.hasProperty("lcApplication") && (prop = applicationNode.getProperty("lcApplication")).getLong() == (long)FMConstants.APPLICATION_STATE.VALID.ordinal()) {
isApplicationNode = true;
}
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
return isApplicationNode;
}
public static boolean isXDPForm(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("xfaForm"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isResource(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("lcResource"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isGuide(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("guide"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isPDFForm(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("pdfForm"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isPrintForm(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("printForm"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isFormset(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("formset"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isAFFragment(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("affragment"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isAdaptiveDocument(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("adaptivedocument"), FMConstants.FORM_STATE.VALID.ordinal());
}
public static boolean isTheme(Session session, String path) throws FormsMgrException {
return FMUtils.isValidAssetType(session, path, Collections.singletonList("theme"), FMConstants.FORM_STATE.VALID.ordinal());
}
private static boolean isValidAssetType(Session session, String path, List<String> assetTypes, long validValue) throws FormsMgrException {
if (session != null) {
try {
Node assetNode = null;
assetNode = session.getNode(path);
if (assetNode == null) {
return false;
}
String primaryType = assetNode.getPrimaryNodeType().getName();
if (primaryType.equals("dam:Asset")) {
Node contentNode = FMUtils.getContentNode(assetNode, false);
if (contentNode == null) {
return false;
}
for (String assetType : assetTypes) {
Property prop;
if (!contentNode.hasProperty(assetType) || (prop = contentNode.getProperty(assetType)).getLong() != validValue) continue;
return true;
}
}
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
return false;
}
public static boolean isXFABasedForm(Session session, String path) throws FormsMgrException {
try {
Node formNode;
Node metadataNode;
if (session.nodeExists(path) && (FMUtils.isGuide(session, path) || FMUtils.isAFFragment(session, path)) && (metadataNode = FMUtils.getMetadataNode(formNode = session.getNode(path), false)) != null) {
return metadataNode.hasProperty("formmodel") && metadataNode.getProperty("formmodel").getString().equals("formtemplates");
}
return false;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean hasDORTemplate(Session session, String path) throws FormsMgrException {
try {
Node formNode;
Node metadataNode;
if (session.nodeExists(path) && (FMUtils.isGuide(session, path) || FMUtils.isAFFragment(session, path)) && (metadataNode = FMUtils.getMetadataNode(formNode = session.getNode(path), false)) != null && metadataNode.hasProperty("dorType")) {
return "select".equals(metadataNode.getProperty("dorType").getString()) && metadataNode.hasProperty("dorTemplateRef");
}
return false;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean hasMetaTemplate(Session session, String path) throws FormsMgrException {
try {
Node formNode;
Node metadataNode;
if (session.nodeExists(path) && FMUtils.isGuide(session, path) && (metadataNode = FMUtils.getMetadataNode(formNode = session.getNode(path), false)) != null) {
return metadataNode.hasProperty("metaTemplateRef");
}
return false;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean hasXSDRef(Session session, String path) throws FormsMgrException {
try {
Node formNode;
Node metadataNode;
if (session.nodeExists(path) && (FMUtils.isGuide(session, path) || FMUtils.isAFFragment(session, path)) && (metadataNode = FMUtils.getMetadataNode(formNode = session.getNode(path), false)) != null) {
return metadataNode.hasProperty("xsdRef");
}
return false;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean isLockedAsset(Session session, String path) throws FormsMgrException {
boolean isLocked = false;
if (session != null) {
try {
if (session.nodeExists(path)) {
Node assetNode = session.getNode(path);
if (path.startsWith("/content/dam/formsanddocuments-themes/themeLibrary") || path.startsWith("/etc/clientlibs/fd/themes/themeLibrary")) {
return true;
}
}
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
return isLocked;
}
public static Property getNodeProperty(String propertyName, Node node) throws FormsMgrException {
try {
Property property;
if (node.hasProperty(propertyName) && (property = node.getProperty(propertyName)) != null) {
return property;
}
return null;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static String getXDPRefPath(Session session, String guidePath) throws FormsMgrException {
try {
String guideContainerNodePath = guidePath + "/" + "jcr:content/guideContainer";
if (!session.itemExists(guideContainerNodePath)) {
throw new FormsMgrException("AEM-FMG-800-001", new String[]{guidePath});
}
Node guideContainerNode = session.getNode(guideContainerNodePath);
if (guideContainerNode.hasProperty("xdpRef")) {
return guideContainerNode.getProperty("xdpRef").getString();
}
throw new FormsMgrException("AEM-FMG-800-003", new String[]{guidePath});
}
catch (FormsMgrException e) {
throw e;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static String getDORRefPath(Session session, String guidePath) throws FormsMgrException {
try {
String guideContainerNodePath = guidePath + "/" + "jcr:content/guideContainer";
if (!session.itemExists(guideContainerNodePath)) {
throw new FormsMgrException("AEM-FMG-800-001", new String[]{guidePath});
}
Node guideContainerNode = session.getNode(guideContainerNodePath);
if (guideContainerNode.hasProperty("dorTemplateRef")) {
return guideContainerNode.getProperty("dorTemplateRef").getString();
}
throw new FormsMgrException("AEM-FMG-800-003", new String[]{guidePath});
}
catch (FormsMgrException e) {
throw e;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static String getMetaTemplateRefPath(Session session, String guidePath) throws FormsMgrException {
try {
String guideContainerNodePath = guidePath + "/" + "jcr:content/guideContainer";
if (!session.nodeExists(guideContainerNodePath)) {
throw new FormsMgrException("AEM-FMG-800-001", new String[]{guidePath});
}
Node guideContainerNode = session.getNode(guideContainerNodePath);
if (guideContainerNode.hasProperty("metaTemplateRef")) {
return guideContainerNode.getProperty("metaTemplateRef").getString();
}
throw new FormsMgrException("AEM-FMG-800-003", new String[]{guidePath});
}
catch (FormsMgrException e) {
throw e;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static String getXSDRefPath(Session session, String guidePath) throws FormsMgrException {
try {
String guideContainerNodePath = guidePath + "/" + "jcr:content/guideContainer";
if (!session.itemExists(guideContainerNodePath)) {
throw new FormsMgrException("AEM-FMG-800-001", new String[]{guidePath});
}
Node guideContainerNode = session.getNode(guideContainerNodePath);
if (guideContainerNode.hasProperty("xsdRef")) {
return guideContainerNode.getProperty("xsdRef").getString();
}
throw new FormsMgrException("AEM-FMG-800-003", new String[]{guidePath});
}
catch (FormsMgrException e) {
throw e;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static Map<String, String> createGuideRenderURL(Node guideNode, String sampleDataId, Session session) throws FormsMgrException {
try {
HashMap<String, String> renderUrlMap = new HashMap<String, String>();
String cqPagePath = FMUtils.getPagePathFromAsset(guideNode.getPath());
if (!session.nodeExists(cqPagePath)) {
throw new FormsMgrException("CQ Page corresponding to Guide Node does not exists");
}
renderUrlMap.put("formUrl", cqPagePath + ".html");
String completeDataUrl = FMUtils.createDataUrl(sampleDataId, session);
renderUrlMap.put("dataRef", completeDataUrl);
return renderUrlMap;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static Map<String, String> createFormsetRenderURLParams(Node formNode, String type, String submitUrl, String profile, String sampleDataId, Session session) throws FormsMgrException {
try {
HashMap<String, String> renderUrlMap = new HashMap<String, String>();
Node metadataNode = FMUtils.getMetadataNode(formNode, false);
if (profile == null || profile.trim().equals("")) {
profile = metadataNode != null && metadataNode.hasProperty("profile") ? metadataNode.getProperty("profile").getString() : "/content/forms/formsets/profiles/default";
}
if (submitUrl == null) {
submitUrl = metadataNode != null && metadataNode.hasProperty("submitUrl") ? metadataNode.getProperty("submitUrl").getString() : null;
}
String templateName = null;
String contentRoot = null;
String formsetPath = null;
String contentUri = formNode.getPath();
if (contentUri == null) {
throw new FormsMgrException("Failed to render form. Null ContentRootURI.");
}
int index = contentUri.lastIndexOf("/");
templateName = contentUri.substring(index + 1);
contentRoot = contentUri.substring(0, index);
formsetPath = contentRoot + "/" + templateName;
String completeDataUrl = FMUtils.createDataUrl(sampleDataId, session);
String formUrl = profile + "." + type;
renderUrlMap.put("formUrl", formUrl);
renderUrlMap.put("formsetPath", formsetPath);
renderUrlMap.put("dataRef", completeDataUrl);
renderUrlMap.put("submitUrl", submitUrl);
return renderUrlMap;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
private static String createDataUrl(String dataId, Session session) throws FormsMgrException {
String dataUrl = null;
String urlPrefix = "crx://";
if (dataId != null && dataId.trim().length() > 0 && !dataId.contains("://") && !dataId.trim().equals("None")) {
dataUrl = FMUtils.getSampleDataPath(dataId, session);
}
String completeDataUrl = null;
completeDataUrl = dataUrl != null && !dataUrl.trim().equals("") ? urlPrefix + dataUrl : (dataId != null && !dataId.trim().equals("") && dataId.contains("://") ? dataId : "");
return completeDataUrl;
}
private static String getSampleDataPath(String fileId, Session session) throws FormsMgrException {
try {
String fileName = "tempArchive_" + fileId;
String tempArchiveLocation = "/content/dam/formsanddocuments/temp_archive_storage/" + fileName;
Node tempNode = null;
if (!session.nodeExists(tempArchiveLocation)) {
log.error("temp node doesn't exist " + tempArchiveLocation);
return null;
}
tempNode = session.getNode(tempArchiveLocation);
return tempNode.getPath();
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean isForm(FMConstants.CoreAssetType assetType) {
return assetType == FMConstants.CoreAssetType.FORM || assetType == FMConstants.CoreAssetType.PDFFORM || assetType == FMConstants.CoreAssetType.PRINTFORM;
}
public static String getFormType(FMConstants.CoreAssetType assetType) {
if (FMConstants.CoreAssetType.FORM == assetType) {
return "xfaForm";
}
if (FMConstants.CoreAssetType.PDFFORM == assetType) {
return "pdfForm";
}
if (FMConstants.CoreAssetType.PRINTFORM == assetType) {
return "printForm";
}
throw new RuntimeException("Invalid form type");
}
public static void deleteTempArchives(Session session) throws FormsMgrException {
block11 : {
String rootPath = "/content/dam/formsanddocuments";
String tempStoragePath = rootPath + "/" + "temp_archive_storage";
try {
if (!session.nodeExists(tempStoragePath)) break block11;
Node tempStorageNode = session.getNode(tempStoragePath);
NodeIterator iter = tempStorageNode.getNodes();
if (iter != null) {
int i = 0;
while ((long)i < iter.getSize()) {
Node node = iter.nextNode();
if (node.hasProperty("jcr:created")) {
long creationTime;
Calendar cal = Calendar.getInstance();
long currentTime = cal.getTime().getTime();
if (currentTime - (creationTime = node.getProperty("jcr:created").getDate().getTime().getTime()) > 1800000) {
log.info("Deleting temp archive : " + node.getPath());
node.remove();
session.save();
}
} else {
long currentTime = System.nanoTime();
String name = node.getName();
if (name.startsWith("tempArchive_")) {
String creationTimeString = name.substring("tempArchive".length() + 1);
try {
Long creationTime = Long.parseLong(creationTimeString);
if (currentTime - creationTime > 1800000000000L) {
log.info("Deleting temp archive without mixin : " + node.getPath());
node.remove();
session.save();
}
}
catch (NumberFormatException e) {
log.warn(node.getName() + " does not have a valid system time name. Failed to delete", (Throwable)e);
}
}
}
++i;
}
break block11;
}
log.info("No Temp Archive files.");
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
}
public static ResourceResolver getResourceResolver(ResourceResolverFactory resourceResolverFactory, Session session) throws FormsMgrException {
try {
HashMap<String, Session> authInfo = new HashMap<String, Session>();
authInfo.put("user.jcr.session", session);
return resourceResolverFactory.getResourceResolver(authInfo);
}
catch (LoginException e) {
throw new FormsMgrException((Throwable)e);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static void writeRequestStatusSuccess(SlingHttpServletResponse resp, boolean isIE) throws IOException, JSONException {
PrintWriter writer = null;
try {
writer = resp.getWriter();
JSONObject successJson = new JSONObject();
successJson.put("requestStatus", (Object)"success");
if (isIE) {
resp.setContentType("text/html;charset=utf-8");
writer.write("<textarea>");
}
writer.write(successJson.toString());
if (isIE) {
writer.write("</textarea>");
}
}
finally {
if (writer != null) {
writer.close();
}
}
}
public static Node getFolderNode(Session session, String rootNodePath, boolean create, String folderType) throws FormsMgrException {
try {
Node workspaceRootNode;
Node workingNode = null;
if (session.nodeExists(rootNodePath)) {
return session.getNode(rootNodePath);
}
if (!create) {
throw new FormsMgrException("Node " + rootNodePath + " does not exist. Please check logs for more detail.");
}
String[] pathElems = rootNodePath.split("/");
Node parentNode = workspaceRootNode = session.getRootNode();
String rootPath = rootNodePath;
if (rootPath.endsWith("/")) {
rootPath = rootPath.substring(0, rootPath.length() - 1);
}
for (String path : pathElems) {
if (path.equals("")) continue;
workingNode = !parentNode.hasNode(path) ? parentNode.addNode(path, folderType) : parentNode.getNode(path);
parentNode = workingNode;
}
session.save();
return workingNode;
}
catch (FormsMgrException e) {
throw e;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static String getPagePathFromAsset(String assetPath) {
return assetPath.replace("/content/dam/formsanddocuments", "/content/forms/af");
}
public static String getAssetPathFromPage(String pagePath) {
return pagePath.replace("/content/forms/af", "/content/dam/formsanddocuments");
}
public static Resource getClosestNodeUpInHierarchy(ResourceResolver resolver, String path, String inputPropertyName, String inputPropertyValue, boolean includeCurrentNode) throws FormsMgrException {
try {
if (resolver == null || path == null || path.isEmpty() || inputPropertyName == null || inputPropertyName.isEmpty() || inputPropertyValue == null || inputPropertyValue.isEmpty()) {
throw new FormsMgrException("AEM-FMG-700-001");
}
Resource res = resolver.getResource(path);
String propeVal = null;
ValueMap map = null;
if (res != null && !includeCurrentNode) {
res = res.getParent();
}
while (res != null && !inputPropertyValue.equals(propeVal = (String)(map = res.getValueMap()).get((Object)inputPropertyName))) {
res = res.getParent();
}
return res;
}
catch (FormsMgrException e) {
log.error("exception while finding node in getClosestNodeUpInHierarchy() : " + e);
throw e;
}
catch (Exception e) {
log.error("exception while finding node in getClosestNodeUpInHierarchy() : " + e);
throw new FormsMgrException(e);
}
}
public static long getLastModifiedOrCreated(Session session, String assetPath) throws FormsMgrException {
try {
Property lastUpdateProperty = null;
Node assetNode = session.getNode(assetPath);
Node contentNode = FMUtils.getContentNode(assetNode, false);
if (assetNode.isNodeType("cq:Template")) {
return -1;
}
if (assetNode.isNodeType("cq:ClientLibraryFolder")) {
return -1;
}
if (assetNode.hasProperty("sling:resourceType") && "wcm/core/components/policy/policy".equals(assetNode.getProperty("sling:resourceType").getString())) {
return -1;
}
if (contentNode != null && contentNode.hasProperty("jcr:lastModified")) {
lastUpdateProperty = contentNode.getProperty("jcr:lastModified");
} else if (contentNode != null && contentNode.hasProperty("jcr:created")) {
lastUpdateProperty = contentNode.getProperty("jcr:created");
} else if (assetNode.hasProperty("jcr:lastModified")) {
lastUpdateProperty = assetNode.getProperty("jcr:lastModified");
}
if (lastUpdateProperty == null) {
return -1;
}
return lastUpdateProperty.getDate().getTimeInMillis();
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static String getDisplayAssetType(Session session, String nodePath) throws FormsMgrException {
if (FMUtils.isXDPForm(session, nodePath)) {
return "Form Template";
}
if (FMUtils.isResource(session, nodePath)) {
return "Resource";
}
if (FMUtils.isGuide(session, nodePath)) {
return "Adaptive Form";
}
if (FMUtils.isPDFForm(session, nodePath)) {
return "PDF Form";
}
if (FMUtils.isPrintForm(session, nodePath)) {
return "Document";
}
if (FMUtils.isFormset(session, nodePath)) {
return "Form Set";
}
throw new FormsMgrException("Invalid Resource for publishing:" + nodePath);
}
public static String getNameFromPath(String path) throws FormsMgrException {
String name = null;
int nameStartIndex = path.lastIndexOf("/");
if (nameStartIndex < 0 || nameStartIndex >= path.length() - 1) {
throw new FormsMgrException("Invalid asset path: " + path);
}
name = path.substring(nameStartIndex + 1);
return name;
}
public static FMConstants.CoreAssetType getAssetType(Session session, String nodePath) throws FormsMgrException {
if (session != null) {
try {
if (!session.nodeExists(nodePath)) {
Object[] args = new Object[]{nodePath};
throw new FormsMgrException("AEM-FMG-700-002", args);
}
if (FMUtils.isXDPForm(session, nodePath)) {
return FMConstants.CoreAssetType.FORM;
}
if (FMUtils.isPDFForm(session, nodePath)) {
return FMConstants.CoreAssetType.PDFFORM;
}
if (FMUtils.isPrintForm(session, nodePath)) {
return FMConstants.CoreAssetType.PRINTFORM;
}
if (FMUtils.isFolder(session, nodePath) || FMUtils.isApplication(session, nodePath)) {
return FMConstants.CoreAssetType.FOLDER;
}
if (FMUtils.isResource(session, nodePath)) {
return FMConstants.CoreAssetType.RESOURCE;
}
if (FMUtils.isGuide(session, nodePath)) {
return FMConstants.CoreAssetType.GUIDE;
}
if (FMUtils.isFormset(session, nodePath)) {
return FMConstants.CoreAssetType.FORMSET;
}
if (FMUtils.isAFFragment(session, nodePath)) {
return FMConstants.CoreAssetType.AFFRAGMENT;
}
if (FMUtils.isAdaptiveDocument(session, nodePath)) {
return FMConstants.CoreAssetType.ADAPTIVEDOCUMENT;
}
if (FMUtils.isTheme(session, nodePath)) {
return FMConstants.CoreAssetType.THEME;
}
return FMConstants.CoreAssetType.NONFMASSET;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
log.error("Unable to get a JCR session");
throw new FormsMgrException("Invalid session object.");
}
public static FormsMgrException getFormsMgrException(Exception e) {
if (e instanceof FormsMgrException) {
return (FormsMgrException)e;
}
return new FormsMgrException(e);
}
public static void unscheduleJob(JobManager jobManager, String formPath, String replicationAtribute) {
Collection scheduledJobs = jobManager.getScheduledJobs();
for (ScheduledJobInfo eachJob : scheduledJobs) {
Map eachJobProps = eachJob.getJobProperties();
if (!eachJob.getJobTopic().equals("com/adobe/aem/formsndocuments/scheduler/formreplication") || !eachJobProps.get("event.form.path").equals(formPath) || !eachJobProps.get("event.replication.attribute").equals(replicationAtribute)) continue;
eachJob.unschedule();
break;
}
}
public static String getRootLevelAssetType(Session session, String assetPath) throws RepositoryException {
if (assetPath != null && assetPath.startsWith("/content/dam/formsanddocuments")) {
int endIndex = assetPath.indexOf("/", "/content/dam/formsanddocuments".length() + 1);
if (endIndex > 0) {
assetPath = assetPath.substring(0, endIndex);
}
if (session.nodeExists(assetPath)) {
Node rootFolderNode = session.getNode(assetPath);
if (rootFolderNode.hasProperty("lcApplication")) {
return "lcApplication";
}
if (rootFolderNode.hasProperty("lcFolder")) {
return "lcFolder";
}
if (rootFolderNode.hasProperty("xfaForm")) {
return "xfaForm";
}
if (rootFolderNode.hasProperty("pdfForm")) {
return "pdfForm";
}
if (rootFolderNode.hasProperty("printForm")) {
return "printForm";
}
if (rootFolderNode.hasProperty("lcResource")) {
return "lcResource";
}
}
}
return null;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static byte[] getBytesFromInputStream(InputStream oInpStream) throws IOException {
byte[] result = new byte[]{};
if (oInpStream == null) {
return result;
}
BufferedInputStream oStream = new BufferedInputStream(oInpStream);
ByteArrayOutputStream oBAOS = new ByteArrayOutputStream();
int nRead = 0;
int nBlkSize = 32768;
byte[] buffer = new byte[nBlkSize];
try {
while ((nRead = oStream.read(buffer, 0, nBlkSize)) != -1) {
oBAOS.write(buffer, 0, nRead);
}
result = oBAOS.toByteArray();
}
catch (IOException e) {
log.debug("Error while generating a byte array from input stream.", (Throwable)e);
}
finally {
try {
if (oStream != null) {
oStream.close();
}
if (oBAOS != null) {
oBAOS.close();
}
if (oInpStream != null) {
oInpStream.close();
}
}
catch (IOException e) {
log.debug("Error while attempting to close input/output stream.", (Throwable)e);
}
}
return result;
}
public static Session getFnDServiceUserSession(SlingRepository repository) throws RepositoryException {
Session session = repository.loginService(null, null);
return session;
}
public static ResourceResolver getFnDServiceUserResourceResolver(ResourceResolverFactory resourceResolverFactory) throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(null);
return resourceResolver;
}
public static JSONObject convertSetOfFormInfoToJSONObject(Set<AssetInfo> formInfoList) throws FormsMgrException {
try {
JSONObject rootJson = new JSONObject();
JSONArray jsonArray = new JSONArray();
for (AssetInfo formInfo : formInfoList) {
JSONObject formInfoJSON = new JSONObject();
Resource resource = formInfo.getResource();
if (resource != null) {
Session session = (Session)resource.getResourceResolver().adaptTo(Session.class);
String title = FMUtils.getResourceTitle(resource);
if (title != null && !title.isEmpty()) {
formInfoJSON.put("name", (Object)title);
} else {
formInfoJSON.put("name", (Object)resource.getName());
}
formInfoJSON.put("type", (Object)formInfo.getPublishAssetType());
formInfoJSON.put("path", (Object)resource.getPath());
ReplicationStatus replStatus = (ReplicationStatus)resource.adaptTo(ReplicationStatus.class);
long lastModified = FMUtils.getLastModifiedOrCreated(session, resource.getPath());
formInfoJSON.put("lastModified", lastModified);
if (replStatus != null) {
boolean published = replStatus.isDelivered() || replStatus.isActivated();
formInfoJSON.put("published", published);
if (published) {
long lastPublished = replStatus.getLastPublished().getTimeInMillis();
formInfoJSON.put("lastPublished", lastPublished);
boolean outdated = lastPublished < lastModified;
formInfoJSON.put("outdated", outdated);
formInfoJSON.put("status", (Object)(outdated ? "outdated" : "not available"));
}
}
formInfoJSON.put("disabled", !FMUtils.canReplicate(resource.getPath(), session));
}
jsonArray.put((Object)formInfoJSON);
}
rootJson.put("assets", (Object)jsonArray);
return rootJson;
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
public static boolean canReplicate(String path, Session session) throws RepositoryException {
AccessControlManager acMgr = session.getAccessControlManager();
return acMgr.hasPrivileges(path, new Privilege[]{acMgr.privilegeFromName("{http://www.day.com/crx/1.0}replicate")});
}
public static void prepareJsonToCreateDAMAsset(ResourceResolver resourceResolver, JSONObject inOutAssetJSON, FMConstants.CoreAssetType assetType, String formPath, String formName) throws FormsMgrException {
if (resourceResolver == null || inOutAssetJSON == null || formPath == null || formName == null) {
log.error("invalid input parametrs in prepareJsonToCreateDAMAsset()");
throw new FormsMgrException("AEM-FMG-700-001");
}
try {
String[] tags;
formName = formName.replaceAll("[^a-zA-Z0-9_-]", "-");
Session session = (Session)resourceResolver.adaptTo(Session.class);
if (!session.nodeExists(formPath)) {
log.error("DAM Asset to be created at non existant path : " + formPath);
Object[] args = new Object[]{formPath};
throw new FormsMgrException("AEM-FMG-700-002", args);
}
String assetPath = ResourceUtil.normalize((String)(formPath + "/" + formName));
inOutAssetJSON.put("path", (Object)assetPath);
JSONObject assetJcrProperties = new JSONObject();
switch (assetType) {
case GUIDE: {
inOutAssetJSON.put("assetType", (Object)"guide");
assetJcrProperties.put("sling:resourceType", (Object)"fd/fm/af/render");
break;
}
case AFFRAGMENT: {
inOutAssetJSON.put("assetType", (Object)"affragment");
assetJcrProperties.put("sling:resourceType", (Object)"fd/fm/af/render");
break;
}
case FORMSET: {
inOutAssetJSON.put("assetType", (Object)"formset");
assetJcrProperties.put("sling:resourceType", (Object)"fd/fm/formset/render");
}
}
inOutAssetJSON.put("assetJcrProperties", (Object)assetJcrProperties);
JSONObject metaDataProperties = inOutAssetJSON.getJSONObject("metadataProperties");
metaDataProperties.put("allowedRenderFormat", (Object)"HTML");
metaDataProperties.put("author", (Object)resourceResolver.getUserID());
metaDataProperties.put("jcr:primaryType", (Object)"nt:unstructured");
if (!metaDataProperties.has("title") || metaDataProperties.getString("title").isEmpty()) {
metaDataProperties.put("title", (Object)formName);
}
if (metaDataProperties.has("xdpRef") && metaDataProperties.getString("xdpRef").isEmpty()) {
metaDataProperties.remove("xdpRef");
}
if (metaDataProperties.has("xsdRef") && metaDataProperties.getString("xsdRef").isEmpty()) {
metaDataProperties.remove("xsdRef");
}
if (metaDataProperties.has("description") && metaDataProperties.getString("description").isEmpty()) {
metaDataProperties.remove("description");
}
if (metaDataProperties.has("cq:tags") && (tags = (String[])metaDataProperties.get("cq:tags")) != null && tags.length > 0) {
metaDataProperties.put("cq:tags", (Object)new JSONArray(Arrays.asList(tags)));
}
}
catch (FormsMgrException fmException) {
throw fmException;
}
catch (Exception e) {
log.error("error while creating json to create DAM Asset", (Throwable)e);
throw new FormsMgrException("AEM-FMG-800-005");
}
}
public static Node createCQPageNode(ResourceResolver resourceResolver, JSONObject paramsJson, FMConstants.CoreAssetType assetType, FMConstants.FORM_MODEL form_model, String templatePath) throws FormsMgrException {
try {
String cqPagePath = FMUtils.getPagePathFromAsset(paramsJson.getString("path"));
JcrUtils.getOrCreateByPath((String)cqPagePath, (String)"sling:OrderedFolder", (String)"sling:OrderedFolder", (Session)((Session)resourceResolver.adaptTo(Session.class)), (boolean)false);
AssetManager assetManager = (AssetManager)resourceResolver.adaptTo(AssetManager.class);
if (assetType == FMConstants.CoreAssetType.GUIDE) {
assetManager.copyAsset(templatePath, cqPagePath);
} else if (assetType == FMConstants.CoreAssetType.AFFRAGMENT) {
assetManager.copyAsset("/libs/fd/af/templateForFragment/defaultFragmentTemplate", cqPagePath);
}
Resource cqPageResource = resourceResolver.getResource(cqPagePath);
Resource thumbnailResource = resourceResolver.getResource(cqPageResource, "thumbnail.png");
if (thumbnailResource != null) {
resourceResolver.delete(thumbnailResource);
}
ModifiableValueMap mvm = (ModifiableValueMap)cqPageResource.adaptTo(ModifiableValueMap.class);
mvm.remove((Object)"jcr:title");
mvm.remove((Object)"jcr:description");
mvm.remove((Object)"allowedPaths");
mvm.put((Object)"jcr:primaryType", (Object)"cq:Page");
Resource jcrContentResource = resourceResolver.getResource(cqPageResource, "jcr:content");
mvm = (ModifiableValueMap)jcrContentResource.adaptTo(ModifiableValueMap.class);
if (assetType == FMConstants.CoreAssetType.GUIDE) {
mvm.put((Object)"cq:template", (Object)templatePath);
} else if (assetType == FMConstants.CoreAssetType.AFFRAGMENT) {
mvm.put((Object)"cq:template", (Object)"/libs/fd/af/templateForFragment/defaultFragmentTemplate");
}
mvm.put((Object)"jcr:language", (Object)"en");
mvm.put((Object)"cq:lastModifiedBy", (Object)resourceResolver.getUserID());
mvm.put((Object)"cq:lastModified", (Object)Calendar.getInstance());
mvm.remove((Object)"guideComponentType");
JSONObject metadataProperties = paramsJson.getJSONObject("metadataProperties");
mvm.put((Object)"jcr:title", (Object)metadataProperties.getString("title"));
Resource guideContainerResource = resourceResolver.getResource(cqPageResource, "jcr:content/guideContainer");
mvm = (ModifiableValueMap)guideContainerResource.adaptTo(ModifiableValueMap.class);
if (assetType == FMConstants.CoreAssetType.GUIDE) {
if (form_model == FMConstants.FORM_MODEL.FORM_TEMPLATE) {
mvm.put((Object)"xdpRef", (Object)metadataProperties.getString("xdpRef"));
} else if (form_model == FMConstants.FORM_MODEL.XML_SCHEMA) {
mvm.put((Object)"xsdRef", (Object)metadataProperties.getString("xsdRef"));
}
} else if (assetType == FMConstants.CoreAssetType.AFFRAGMENT) {
if (form_model == FMConstants.FORM_MODEL.FORM_TEMPLATE) {
mvm.put((Object)"xdpRef", (Object)metadataProperties.getString("xdpRef"));
mvm.put((Object)"fragmentModelRoot", (Object)metadataProperties.getString("fragmentModelRoot"));
} else if (form_model == FMConstants.FORM_MODEL.XML_SCHEMA) {
mvm.put((Object)"xsdRef", (Object)metadataProperties.getString("xsdRef"));
mvm.put((Object)"fragmentModelRoot", (Object)metadataProperties.getString("fragmentModelRoot"));
}
}
Resource guideRootPanelItemResource = resourceResolver.getResource(guideContainerResource, "rootPanel/items");
if (guideContainerResource != null) {
Node itemNode = (Node)guideRootPanelItemResource.adaptTo(Node.class);
NodeIterator Iter = itemNode.getNodes();
while (Iter.hasNext()) {
Iter.nextNode().remove();
}
}
return (Node)cqPageResource.adaptTo(Node.class);
}
catch (Exception e) {
log.error("Error while creating cq page Node : ", (Throwable)e);
throw new FormsMgrException("AEM-FMG-900-005");
}
}
public static void JsonToJcrNode(Node node, JSONObject jsonObject) throws JSONException, RepositoryException {
Iterator keys = jsonObject.keys();
while (keys.hasNext()) {
String key = (String)keys.next();
Object property = jsonObject.get(key);
FMUtils.handleProperty(node, key, property);
}
}
private static void handleProperty(Node node, String name, Object property) throws JSONException, RepositoryException {
if (JSONObject.class.isAssignableFrom(property.getClass())) {
JSONObject nodeJson = (JSONObject)property;
if (nodeJson.has("jcr:primaryType") && nodeJson.getString("jcr:primaryType").equals("nt:file")) {
return;
}
Node childNode = node.addNode(name, "nt:unstructured");
FMUtils.JsonToJcrNode(childNode, (JSONObject)property);
} else {
if (name.equals("jcr:primaryType") || name.equals("jcr:mixinTypes")) {
return;
}
String[] propertyValue = property;
if (property instanceof String) {
propertyValue = StringUtils.trim((String)((String)property));
} else if (property instanceof JSONArray) {
JSONArray arrJson = (JSONArray)property;
int len = arrJson.length();
String[] strArr = new String[len];
for (int i = 0; i < len; ++i) {
strArr[i] = arrJson.getString(i);
}
propertyValue = strArr;
}
JcrResourceUtil.setProperty((Node)node, (String)name, (Object)propertyValue);
}
}
public static void moveNode(ResourceResolver resolver, String sourceLocation, String destinationLocation) throws FormsMgrException {
if (sourceLocation == null || "".equals(sourceLocation)) {
log.error("Exception in moveNode() as source path is not valid");
Object[] args = new Object[]{"sourceLocation", sourceLocation};
throw new FormsMgrException("AEM-FMG-700-001", args);
}
if (destinationLocation == null || "".equals(destinationLocation)) {
log.error("Exception in moveNode() as destination path is not valid");
Object[] args = new Object[]{"destinationLocation", destinationLocation};
throw new FormsMgrException("AEM-FMG-700-001", args);
}
Session session = (Session)resolver.adaptTo(Session.class);
int index = sourceLocation.lastIndexOf("/");
String nodeName = sourceLocation.substring(index);
try {
if (!session.nodeExists(sourceLocation)) {
log.error("Exception in moveNode() as source location" + sourceLocation + "does not exist");
Object[] args = new Object[]{"sourceLocation", sourceLocation};
throw new FormsMgrException("AEM-FMG-700-001", args);
}
if (session.nodeExists(destinationLocation + nodeName)) {
log.error("Exception in moveNode() as resource already exist at destination");
Object[] args = new Object[]{nodeName, destinationLocation};
throw new FormsMgrException("AEM-FMG-900-002", args);
}
session.move(sourceLocation, destinationLocation + nodeName);
resolver.commit();
}
catch (FormsMgrException e) {
throw e;
}
catch (Exception e) {
log.error("Exception in moveNode() while moving node from" + sourceLocation + "to" + destinationLocation, (Throwable)e);
throw new FormsMgrException(e);
}
}
public static String getClientlibPath(Node resourceNode) throws FormsMgrException {
String clientLibProperty = "./jcr:content/metadata/clientlibRef";
String clientLibPath = "";
try {
if (resourceNode != null && resourceNode.hasProperty(clientLibProperty)) {
clientLibPath = resourceNode.getProperty(clientLibProperty).getString() + "/" + resourceNode.getName();
}
}
catch (ValueFormatException e) {
log.error("Exception in getClientlibNode()", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
catch (PathNotFoundException e) {
log.error("Exception in getClientlibNode()", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
catch (RepositoryException e) {
log.error("Exception in getClientlibNode()", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
return clientLibPath;
}
public static String getThemeRef(Session session, String path) throws FormsMgrException {
String themeRefPath = null;
try {
Node formNode;
Node metadataNode;
if (session.nodeExists(path) && (metadataNode = FMUtils.getMetadataNode(formNode = session.getNode(path), false)) != null && metadataNode.hasProperty("themeRef")) {
themeRefPath = metadataNode.getProperty("themeRef").getString();
}
return themeRefPath;
}
catch (ValueFormatException e) {
log.error("Exception in getThemeRef() due to ValueFormatException", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
catch (PathNotFoundException e) {
log.error("Exception in getThemeRef() due to PathNotFoundException", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
catch (RepositoryException e) {
log.error("Exception in getThemeRef() due to RepositoryException", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
}
public static String getCategoryNameFromClientLibPath(String clientLibPath) {
String categoryName = "fdtheme";
clientLibPath = clientLibPath.replace("/etc/clientlibs/fd/themes", "");
clientLibPath = clientLibPath.replaceAll("\\s+", "");
categoryName = categoryName + clientLibPath.replace("/", ".");
return categoryName;
}
public static Node getRenditionNode(Node formNode, boolean create) throws FormsMgrException {
Node renditionNode = null;
Node contentNode = FMUtils.getContentNode(formNode, create);
if (contentNode != null) {
try {
if (!contentNode.hasNode("renditions")) {
if (create) {
renditionNode = contentNode.addNode("renditions", "{http://www.jcp.org/jcr/nt/1.0}folder");
}
} else {
renditionNode = contentNode.getNode("renditions");
}
}
catch (RepositoryException e) {
throw new FormsMgrException((Throwable)e);
}
}
return renditionNode;
}
public static String getResourceTitle(Resource resource) throws FormsMgrException {
try {
String title = null;
Template template = (Template)resource.adaptTo(Template.class);
if (template != null) {
return template.getTitle();
}
ContentPolicy contentPolicy = (ContentPolicy)resource.adaptTo(ContentPolicy.class);
if (contentPolicy != null) {
ValueMap contentPolicyProps = contentPolicy.getProperties();
return (String)contentPolicyProps.get("jcr:title", null);
}
Node resourceNode = (Node)resource.adaptTo(Node.class);
Node metadataNode = FMUtils.getMetadataNode(resourceNode, false);
if (metadataNode != null && metadataNode.hasProperty("title")) {
title = metadataNode.getProperty("title").getString();
}
return title;
}
catch (ValueFormatException e) {
log.error("Exception in getResourceTitle() due to ValueFormatException", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
catch (PathNotFoundException e) {
log.error("Exception in getResourceTitle() due to PathNotFoundException", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
catch (RepositoryException e) {
log.error("Exception in getResourceTitle() due to RepositoryException", (Throwable)e);
throw new FormsMgrException((Throwable)e);
}
}
public static FormsAssetType getFormsFoundationAssetType(FMConstants.CoreAssetType coreAssetType) throws FormsMgrException {
FormsAssetType formsAssetType = null;
switch (coreAssetType) {
case FORM: {
formsAssetType = FormsAssetType.XDP;
break;
}
case RESOURCE: {
formsAssetType = FormsAssetType.FM_RESOURCE;
break;
}
case GUIDE: {
formsAssetType = FormsAssetType.ADAPTIVE_FORM;
break;
}
case FORMSET: {
formsAssetType = FormsAssetType.FORMSET;
break;
}
case AFFRAGMENT: {
formsAssetType = FormsAssetType.ADAPTIVE_FORM_FRAGMENT;
break;
}
case ADAPTIVEDOCUMENT: {
formsAssetType = FormsAssetType.ADAPTIVE_DOCUMENT;
break;
}
case THEME: {
formsAssetType = FormsAssetType.THEME;
break;
}
case PDFFORM: {
formsAssetType = FormsAssetType.PDF;
break;
}
case PRINTFORM: {
formsAssetType = FormsAssetType.PRINT_FORM;
break;
}
case FOLDER: {
formsAssetType = FormsAssetType.FOLDER;
break;
}
case NONFMASSET:
case ALL: {
log.error("FM Asset Type " + (Object)((Object)coreAssetType) + " cannot be converted into FormsAssetType.");
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"FM Asset Type", coreAssetType.toString()});
}
default: {
log.error("If there is any new addition in FM CoreAssetType, it should be handled here.");
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"FM Asset Type", coreAssetType.toString()});
}
}
log.debug("FM Core Asset type : " + (Object)((Object)coreAssetType) + "converted into Forms Foundation Asset Type : " + (Object)formsAssetType);
return formsAssetType;
}
public static boolean hasMixin(Node node, String mixinName) throws RepositoryException {
if (node == null || mixinName == null) {
return false;
}
NodeType[] nodeTypes = node.getMixinNodeTypes();
if (nodeTypes != null) {
for (NodeType nodeType : nodeTypes) {
if (!mixinName.equals(nodeType.getName())) continue;
return true;
}
}
return false;
}
public static void addMixin(Node node, String[] mixinNames) throws FormsMgrException {
if (node == null) {
Object[] args = new Object[]{"asset path", node};
throw new FormsMgrException("AEM-FMG-700-001", args);
}
if (mixinNames == null) {
Object[] args = new Object[]{"mixins", mixinNames};
throw new FormsMgrException("AEM-FMG-700-001", args);
}
try {
for (String mixinName : mixinNames) {
if (FMUtils.hasMixin(node, mixinName)) continue;
node.addMixin(mixinName);
}
}
catch (Exception e) {
throw new FormsMgrException("AEM-FMG-700-026", e);
}
}
}