1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.elasticsearch.index.objects.event;
23
24 import org.opencastproject.elasticsearch.index.objects.IndexObject;
25 import org.opencastproject.mediapackage.Publication;
26 import org.opencastproject.scheduler.api.RecordingState;
27 import org.opencastproject.util.IoSupport;
28 import org.opencastproject.util.XmlSafeParser;
29 import org.opencastproject.util.jaxb.ExtendedMetadataAdapter;
30 import org.opencastproject.workflow.api.WorkflowInstance.WorkflowState;
31
32 import org.apache.commons.lang3.StringUtils;
33 import org.codehaus.jettison.json.JSONException;
34 import org.codehaus.jettison.json.JSONObject;
35 import org.codehaus.jettison.mapped.Configuration;
36 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
37 import org.codehaus.jettison.mapped.MappedXMLStreamReader;
38 import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.xml.sax.SAXException;
42
43 import java.io.BufferedReader;
44 import java.io.IOException;
45 import java.io.InputStream;
46 import java.io.InputStreamReader;
47 import java.io.StringWriter;
48 import java.util.ArrayList;
49 import java.util.HashMap;
50 import java.util.List;
51 import java.util.Map;
52
53 import javax.xml.bind.JAXBContext;
54 import javax.xml.bind.JAXBException;
55 import javax.xml.bind.Marshaller;
56 import javax.xml.bind.Unmarshaller;
57 import javax.xml.bind.annotation.XmlAccessType;
58 import javax.xml.bind.annotation.XmlAccessorType;
59 import javax.xml.bind.annotation.XmlElement;
60 import javax.xml.bind.annotation.XmlElementWrapper;
61 import javax.xml.bind.annotation.XmlRootElement;
62 import javax.xml.bind.annotation.XmlType;
63 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
64 import javax.xml.stream.XMLStreamException;
65 import javax.xml.stream.XMLStreamReader;
66 import javax.xml.stream.XMLStreamWriter;
67
68
69
70
71 @XmlType(
72 name = "event",
73 namespace = IndexObject.INDEX_XML_NAMESPACE,
74 propOrder = {
75 "identifier", "organization", "title", "description", "subject", "location", "presenters",
76 "contributors", "seriesId", "seriesName", "language", "source", "created", "creator",
77 "publisher", "license", "rights", "extendedMetadata", "accessPolicy", "managedAcl", "workflowState",
78 "workflowId", "workflowDefinitionId", "recordingStartTime", "recordingEndTime", "duration",
79 "hasComments", "hasOpenComments", "comments", "hasPreview", "needsCutting", "publications",
80 "archiveVersion", "recordingStatus", "eventStatus", "agentId", "agentConfigurations",
81 "technicalStartTime", "technicalEndTime", "technicalPresenters"
82 }
83 )
84 @XmlRootElement(name = "event", namespace = IndexObject.INDEX_XML_NAMESPACE)
85 @XmlAccessorType(XmlAccessType.NONE)
86 public class Event implements IndexObject {
87
88
89 private static final Logger logger = LoggerFactory.getLogger(Event.class);
90
91
92 public static final String DOCUMENT_TYPE = "event";
93
94
95 public static final String XML_SURROUNDING_TAG = "events";
96
97
98 private static final Map<String, String> workflowStatusMapping = new HashMap<>();
99 private static final Map<String, String> recordingStatusMapping = new HashMap<>();
100
101 static {
102 recordingStatusMapping.put(RecordingState.CAPTURING, "EVENTS.EVENTS.STATUS.RECORDING");
103 recordingStatusMapping.put(RecordingState.CAPTURE_FINISHED, "EVENTS.EVENTS.STATUS.RECORDING");
104 recordingStatusMapping.put(RecordingState.MANIFEST, "EVENTS.EVENTS.STATUS.INGESTING");
105 recordingStatusMapping.put(RecordingState.MANIFEST_FINISHED, "EVENTS.EVENTS.STATUS.INGESTING");
106 recordingStatusMapping.put(RecordingState.COMPRESSING, "EVENTS.EVENTS.STATUS.INGESTING");
107 recordingStatusMapping.put(RecordingState.UPLOADING, "EVENTS.EVENTS.STATUS.INGESTING");
108 recordingStatusMapping.put(RecordingState.UPLOAD_FINISHED, "EVENTS.EVENTS.STATUS.INGESTING");
109 recordingStatusMapping.put(RecordingState.CAPTURE_ERROR, "EVENTS.EVENTS.STATUS.RECORDING_FAILURE");
110 recordingStatusMapping.put(RecordingState.MANIFEST_ERROR, "EVENTS.EVENTS.STATUS.RECORDING_FAILURE");
111 recordingStatusMapping.put(RecordingState.COMPRESSING_ERROR, "EVENTS.EVENTS.STATUS.RECORDING_FAILURE");
112 recordingStatusMapping.put(RecordingState.UPLOAD_ERROR, "EVENTS.EVENTS.STATUS.RECORDING_FAILURE");
113 workflowStatusMapping.put(WorkflowState.INSTANTIATED.toString(), "EVENTS.EVENTS.STATUS.PENDING");
114 workflowStatusMapping.put(WorkflowState.RUNNING.toString(), "EVENTS.EVENTS.STATUS.PROCESSING");
115 workflowStatusMapping.put(WorkflowState.FAILING.toString(), "EVENTS.EVENTS.STATUS.PROCESSING");
116 workflowStatusMapping.put(WorkflowState.PAUSED.toString(), "EVENTS.EVENTS.STATUS.PAUSED");
117 workflowStatusMapping.put(WorkflowState.SUCCEEDED.toString(), "EVENTS.EVENTS.STATUS.PROCESSED");
118 workflowStatusMapping.put(WorkflowState.FAILED.toString(), "EVENTS.EVENTS.STATUS.PROCESSING_FAILURE");
119 workflowStatusMapping.put(WorkflowState.STOPPED.toString(), "EVENTS.EVENTS.STATUS.PROCESSING_CANCELLED");
120 }
121
122
123 @XmlElement(name = "identifier")
124 private String identifier = null;
125
126
127 @XmlElement(name = "organization")
128 private String organization = null;
129
130
131 @XmlElement(name = "title")
132 private String title = null;
133
134
135 @XmlElement(name = "description")
136 private String description = null;
137
138
139 @XmlElement(name = "subject")
140 private String subject = null;
141
142
143 @XmlElement(name = "location")
144 private String location = null;
145
146 @XmlElementWrapper(name = "presenters")
147 @XmlElement(name = "presenter")
148 private List<String> presenters = null;
149
150 @XmlElementWrapper(name = "contributors")
151 @XmlElement(name = "contributor")
152 private List<String> contributors = null;
153
154
155 @XmlElement(name = "series_id")
156 private String seriesId = null;
157
158
159 @XmlElement(name = "series_name")
160 private String seriesName = null;
161
162
163 @XmlElement(name = "language")
164 private String language = null;
165
166
167 @XmlElement(name = "source")
168 private String source = null;
169
170
171 @XmlElement(name = "created")
172 private String created = null;
173
174
175 @XmlElement(name = "creator")
176 private String creator = null;
177
178
179 @XmlElement(name = "publisher")
180 private String publisher = null;
181
182
183 @XmlElement(name = "license")
184 private String license = null;
185
186
187 @XmlElement(name = "rights")
188 private String rights = null;
189
190 @XmlElement(name = "extendedMetadata")
191 @XmlJavaTypeAdapter(ExtendedMetadataAdapter.class)
192 private Map<String, Map<String, List<String>>> extendedMetadata = new HashMap();
193
194
195 @XmlElement(name = "access_policy")
196 private String accessPolicy = null;
197
198
199 @XmlElement(name = "managed_acl")
200 private String managedAcl = null;
201
202
203 @XmlElement(name = "workflow_state")
204 private String workflowState = null;
205
206
207 @XmlElement(name = "workflow_id")
208 private Long workflowId = null;
209
210
211 @XmlElement(name = "workflow_definition_id")
212 private String workflowDefinitionId = null;
213
214
215 @XmlElement(name = "recording_start_time")
216 private String recordingStartTime = null;
217
218
219 @XmlElement(name = "recording_end_time")
220 private String recordingEndTime = null;
221
222
223 @XmlElement(name = "duration")
224 private Long duration = null;
225
226
227 @XmlElement(name = "event_status")
228 private String eventStatus = null;
229
230
231 @XmlElement(name = "has_comments")
232 private Boolean hasComments = false;
233
234
235 @XmlElement(name = "has_open_comments")
236 private Boolean hasOpenComments = false;
237
238
239 @XmlElement(name = "comments")
240 private List<Comment> comments = new ArrayList<>();
241
242
243 @XmlElement(name = "has_preview")
244 private Boolean hasPreview = false;
245
246
247 @XmlElement(name = "needs_cutting")
248 private Boolean needsCutting = false;
249
250
251 @XmlElementWrapper(name = "publications")
252 @XmlElement(name = "publication")
253 private List<Publication> publications = new ArrayList<>();
254
255
256 @XmlElement(name = "recording_status")
257 private String recordingStatus = null;
258
259
260 @XmlElement(name = "archive_version")
261 private Long archiveVersion = null;
262
263
264 @XmlElement(name = "agent_id")
265 private String agentId = null;
266
267
268 @XmlElementWrapper(name = "agent_configuration")
269 private Map<String, String> agentConfigurations = new HashMap<String, String>();
270
271
272 @XmlElement(name = "technical_end_time")
273 private String technicalEndTime = null;
274
275
276 @XmlElement(name = "technical_start_time")
277 private String technicalStartTime = null;
278
279 @XmlElementWrapper(name = "technical_presenters")
280 @XmlElement(name = "technical_presenter")
281 private List<String> technicalPresenters = null;
282
283
284 private static JAXBContext context = null;
285
286
287
288
289 public Event() {
290
291 }
292
293
294
295
296
297
298
299
300
301 public Event(String identifier, String organization) {
302 this.identifier = identifier;
303 this.organization = organization;
304 updateEventStatus();
305 }
306
307
308
309
310
311
312 public String getIdentifier() {
313 return identifier;
314 }
315
316
317
318
319
320
321 public String getOrganization() {
322 return organization;
323 }
324
325
326
327
328
329
330
331 public void setTitle(String title) {
332 this.title = title;
333 }
334
335
336
337
338
339
340 public String getTitle() {
341 return title;
342 }
343
344
345
346
347
348
349
350 public void setDescription(String description) {
351 this.description = description;
352 }
353
354
355
356
357
358
359 public String getDescription() {
360 return description;
361 }
362
363
364
365
366
367
368
369 public void setSubject(String subject) {
370 this.subject = subject;
371 }
372
373
374
375
376
377
378 public String getSubject() {
379 return subject;
380 }
381
382
383
384
385
386
387
388 public void setLocation(String location) {
389 this.location = location;
390 }
391
392
393
394
395
396
397 public String getLocation() {
398 return location;
399 }
400
401
402
403
404
405
406
407 public void setSeriesId(String seriesId) {
408 this.seriesId = seriesId;
409 }
410
411
412
413
414
415
416 public String getSeriesId() {
417 return seriesId;
418 }
419
420
421
422
423
424
425
426 public void setSeriesName(String seriesName) {
427 this.seriesName = seriesName;
428 }
429
430
431
432
433
434
435 public String getSeriesName() {
436 return seriesName;
437 }
438
439
440
441
442
443
444
445 public void setLanguage(String language) {
446 this.language = language;
447 }
448
449
450
451
452
453
454 public String getLanguage() {
455 return language;
456 }
457
458
459
460
461
462
463
464 public void setSource(String source) {
465 this.source = source;
466 }
467
468
469
470
471
472
473 public String getSource() {
474 return source;
475 }
476
477
478
479
480
481
482
483 public void setCreated(String created) {
484 this.created = created;
485 }
486
487
488
489
490
491
492 public String getCreated() {
493 return created;
494 }
495
496
497
498
499
500
501
502 public void setCreator(String creator) {
503 this.creator = creator;
504 }
505
506
507
508
509
510
511 public String getCreator() {
512 return creator;
513 }
514
515
516
517
518
519
520
521 public void setPublisher(String publisher) {
522 this.publisher = publisher;
523 }
524
525
526
527
528
529
530 public String getPublisher() {
531 return publisher;
532 }
533
534
535
536
537
538
539
540 public void setLicense(String license) {
541 this.license = license;
542 }
543
544
545
546
547
548
549 public String getLicense() {
550 return license;
551 }
552
553
554
555
556
557
558
559 public void setRights(String rights) {
560 this.rights = rights;
561 }
562
563
564
565
566
567
568 public String getRights() {
569 return rights;
570 }
571
572
573
574
575
576
577
578 public void setAccessPolicy(String accessPolicy) {
579 this.accessPolicy = accessPolicy;
580 }
581
582
583
584
585
586
587 public String getAccessPolicy() {
588 return accessPolicy;
589 }
590
591
592
593
594
595
596
597 public void setManagedAcl(String managedAcl) {
598 this.managedAcl = managedAcl;
599 }
600
601
602
603
604
605
606 public String getManagedAcl() {
607 return managedAcl;
608 }
609
610
611
612
613
614
615
616 public void setWorkflowState(WorkflowState workflowState) {
617 this.workflowState = workflowState == null ? null : workflowState.toString();
618 updateEventStatus();
619 }
620
621
622
623
624
625
626 public String getWorkflowState() {
627 return workflowState;
628 }
629
630
631
632
633
634
635
636 public void setWorkflowId(Long workflowId) {
637 this.workflowId = workflowId;
638 }
639
640
641
642
643
644
645 public Long getWorkflowId() {
646 return workflowId;
647 }
648
649
650
651
652
653
654
655 public void setWorkflowDefinitionId(String workflowDefinitionId) {
656 this.workflowDefinitionId = workflowDefinitionId;
657 }
658
659
660
661
662
663
664 public String getWorkflowDefinitionId() {
665 return workflowDefinitionId;
666 }
667
668
669
670
671
672
673
674 public void setRecordingStartDate(String recordingStartTime) {
675 this.recordingStartTime = recordingStartTime;
676 }
677
678
679
680
681
682
683 public String getRecordingStartDate() {
684 return recordingStartTime;
685 }
686
687
688
689
690
691
692
693 public void setRecordingEndDate(String recordingEndTime) {
694 this.recordingEndTime = recordingEndTime;
695 }
696
697
698
699
700
701
702 public String getRecordingEndDate() {
703 return recordingEndTime;
704 }
705
706
707
708
709
710
711
712 public void setDuration(long duration) {
713 this.duration = duration;
714 }
715
716
717
718
719
720
721 public Long getDuration() {
722 return duration;
723 }
724
725
726
727
728
729
730
731 public void setPresenters(List<String> presenters) {
732 this.presenters = presenters;
733 }
734
735
736
737
738
739
740 public List<String> getPresenters() {
741 return presenters;
742 }
743
744
745
746
747
748
749
750 public void setContributors(List<String> contributors) {
751 this.contributors = contributors;
752 }
753
754
755
756
757
758
759 public List<String> getContributors() {
760 return contributors;
761 }
762
763
764
765
766
767
768
769 public void setHasComments(boolean hasComments) {
770 this.hasComments = hasComments;
771 }
772
773
774
775
776
777
778 public boolean hasComments() {
779 return hasComments;
780 }
781
782
783
784
785
786
787
788 public void setHasOpenComments(boolean hasOpenComments) {
789 this.hasOpenComments = hasOpenComments;
790 }
791
792
793
794
795
796
797 public boolean hasOpenComments() {
798 return hasOpenComments;
799 }
800
801
802
803
804
805
806
807 public void setComments(List<Comment> comments) {
808 this.comments = comments;
809 }
810
811
812
813
814
815
816 public List<Comment> comments() {
817 return comments;
818 }
819
820
821
822
823
824
825
826 public void setHasPreview(boolean hasPreview) {
827 this.hasPreview = hasPreview;
828 }
829
830
831
832
833
834
835 public boolean hasPreview() {
836 return hasPreview;
837 }
838
839
840
841
842
843
844
845 public void updatePreview(String previewSubtype) {
846 hasPreview = EventIndexUtils.subflavorMatches(publications, previewSubtype);
847 }
848
849
850
851
852
853
854
855 public void setNeedsCutting(boolean needsCutting) {
856 this.needsCutting = needsCutting;
857 }
858
859
860
861
862
863
864 public boolean needsCutting() {
865 return needsCutting;
866 }
867
868
869
870
871
872
873
874 public void setPublications(List<Publication> publications) {
875 this.publications = publications;
876 }
877
878
879
880
881
882
883 public List<Publication> getPublications() {
884 return publications;
885 }
886
887
888
889
890
891
892
893 public void setArchiveVersion(Long archiveVersion) {
894 this.archiveVersion = archiveVersion;
895 }
896
897
898
899
900
901
902 public Long getArchiveVersion() {
903 return archiveVersion;
904 }
905
906 private void updateEventStatus() {
907 if (getWorkflowId() != null && StringUtils.isBlank(getWorkflowState())
908 || getWorkflowId() == null && StringUtils.isNotBlank(getWorkflowState())) {
909 logger.warn("The workflow id {} and workflow state {} are not in sync on event {} organization {}",
910 getWorkflowId(), getWorkflowState(), getIdentifier(), getOrganization());
911 }
912
913 if (getWorkflowId() != null && StringUtils.isNotBlank(getWorkflowState())) {
914 eventStatus = workflowStatusMapping.get(getWorkflowState());
915 } else if ("EVENTS.EVENTS.STATUS.PROCESSED".equals(eventStatus)
916 && (RecordingState.CAPTURE_FINISHED.equals(getRecordingStatus())
917 || RecordingState.UPLOAD_FINISHED.equals(getRecordingStatus()))) {
918 eventStatus = "EVENTS.EVENTS.STATUS.PROCESSED";
919 } else if ("EVENTS.EVENTS.STATUS.PROCESSING_FAILURE".equals(eventStatus)
920 && RecordingState.CAPTURE_ERROR.equals(getRecordingStatus())
921 || RecordingState.UPLOAD_ERROR.equals(getRecordingStatus())) {
922 eventStatus = recordingStatusMapping.get(getRecordingStatus());
923 } else if (StringUtils.isNotBlank(getRecordingStatus())) {
924 eventStatus = recordingStatusMapping.get(getRecordingStatus());
925 } else if (isScheduledEvent()) {
926 eventStatus = "EVENTS.EVENTS.STATUS.SCHEDULED";
927 } else {
928
929
930 eventStatus = "EVENTS.EVENTS.STATUS.PROCESSED";
931 }
932 }
933
934
935
936
937
938
939
940
941
942 public String getDisplayableStatus(Map<String, Map<String, String>> customWorkflowStatusMapping) {
943 if (getWorkflowId() != null && StringUtils.isNotBlank(getWorkflowState())
944 && customWorkflowStatusMapping.containsKey(getWorkflowDefinitionId())
945 && customWorkflowStatusMapping.get(getWorkflowDefinitionId()).containsKey(getWorkflowState())) {
946 return customWorkflowStatusMapping.get(getWorkflowDefinitionId()).get(getWorkflowState());
947 }
948 return getEventStatus();
949 }
950
951 public boolean isScheduledEvent() {
952
953 return StringUtils.isNotBlank(getAgentId());
954 }
955
956
957
958
959
960
961
962 public boolean hasRecordingStarted() {
963 return isScheduledEvent() && StringUtils.isNotBlank(getRecordingStatus());
964 }
965
966
967
968
969
970
971
972 public void setRecordingStatus(String recordingStatus) {
973 this.recordingStatus = recordingStatus;
974 updateEventStatus();
975 }
976
977
978
979
980
981
982 public String getRecordingStatus() {
983 return recordingStatus;
984 }
985
986
987
988
989
990
991 public String getEventStatus() {
992 updateEventStatus();
993 return eventStatus;
994 }
995
996
997
998
999
1000
1001 public String getAgentId() {
1002 return agentId;
1003 }
1004
1005
1006
1007
1008
1009
1010
1011 public void setAgentId(String agentId) {
1012 this.agentId = agentId;
1013 }
1014
1015
1016
1017
1018
1019
1020 public Map<String, String> getAgentConfiguration() {
1021 return agentConfigurations;
1022 }
1023
1024
1025
1026
1027
1028
1029
1030 public void setAgentConfiguration(Map<String, String> agentConfigurations) {
1031 this.agentConfigurations = agentConfigurations;
1032 }
1033
1034
1035
1036
1037
1038
1039 public String getTechnicalEndTime() {
1040 return technicalEndTime;
1041 }
1042
1043
1044
1045
1046
1047
1048
1049 public void setTechnicalEndTime(String technicalEndTime) {
1050 this.technicalEndTime = technicalEndTime;
1051 }
1052
1053
1054
1055
1056
1057
1058 public String getTechnicalStartTime() {
1059 return technicalStartTime;
1060 }
1061
1062
1063
1064
1065
1066
1067
1068 public void setTechnicalStartTime(String technicalStartTime) {
1069 this.technicalStartTime = technicalStartTime;
1070 }
1071
1072
1073
1074
1075
1076
1077 public List<String> getTechnicalPresenters() {
1078 return technicalPresenters;
1079 }
1080
1081
1082
1083
1084
1085
1086
1087 public void setTechnicalPresenters(List<String> technicalPresenters) {
1088 this.technicalPresenters = technicalPresenters;
1089 }
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099 public void setExtendedMetadata(String type, Map<String, List<String>> metadata) {
1100 extendedMetadata.put(type, metadata);
1101 }
1102
1103
1104
1105
1106 public void resetExtendedMetadata() {
1107 extendedMetadata.clear();
1108 }
1109
1110
1111
1112
1113
1114
1115 public Map<String, Map<String, List<String>>> getExtendedMetadata() {
1116 return extendedMetadata;
1117 }
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128 public static Event valueOf(InputStream xml, Unmarshaller unmarshaller) throws IOException {
1129 try {
1130 if (context == null) {
1131 createJAXBContext();
1132 }
1133 return unmarshaller.unmarshal(XmlSafeParser.parse(xml), Event.class).getValue();
1134 } catch (JAXBException e) {
1135 throw new IOException(e.getLinkedException() != null ? e.getLinkedException() : e);
1136 } catch (SAXException e) {
1137 throw new IOException(e);
1138 } finally {
1139 IoSupport.closeQuietly(xml);
1140 }
1141 }
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153 public static Event valueOfJson(InputStream json)
1154 throws IOException, JSONException, XMLStreamException, JAXBException {
1155
1156 if (context == null) {
1157 createJAXBContext();
1158 }
1159
1160 BufferedReader streamReader = new BufferedReader(new InputStreamReader(json, "UTF-8"));
1161 StringBuilder jsonStringBuilder = new StringBuilder();
1162 String inputStr;
1163 while ((inputStr = streamReader.readLine()) != null) {
1164 jsonStringBuilder.append(inputStr);
1165 }
1166
1167 JSONObject obj = new JSONObject(jsonStringBuilder.toString());
1168 Configuration config = new Configuration();
1169 config.setSupressAtAttributes(true);
1170 Map<String, String> xmlToJsonNamespaces = new HashMap<String, String>(1);
1171 xmlToJsonNamespaces.put(IndexObject.INDEX_XML_NAMESPACE, "");
1172 config.setXmlToJsonNamespaces(xmlToJsonNamespaces);
1173 MappedNamespaceConvention con = new MappedNamespaceConvention(config);
1174 Unmarshaller unmarshaller = context.createUnmarshaller();
1175
1176
1177 XMLStreamReader xmlStreamReader = new MappedXMLStreamReader(obj, con);
1178 Event event = (Event) unmarshaller.unmarshal(xmlStreamReader);
1179
1180 return event;
1181 }
1182
1183
1184
1185
1186 private static void createJAXBContext() throws JAXBException {
1187 context = JAXBContext.newInstance(Event.class);
1188 }
1189
1190
1191
1192
1193
1194
1195 public String toJSON() {
1196 try {
1197 if (context == null) {
1198 createJAXBContext();
1199 }
1200 Marshaller marshaller = Event.context.createMarshaller();
1201
1202 Configuration config = new Configuration();
1203 config.setSupressAtAttributes(true);
1204 MappedNamespaceConvention con = new MappedNamespaceConvention(config);
1205 StringWriter writer = new StringWriter();
1206 XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) {
1207 @Override
1208 public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
1209 super.writeStartElement("", local, "");
1210 }
1211
1212 @Override
1213 public void writeStartElement(String uri, String local) throws XMLStreamException {
1214 super.writeStartElement("", local, "");
1215 }
1216
1217 @Override
1218 public void setPrefix(String pfx, String uri) throws XMLStreamException {
1219 }
1220
1221 @Override
1222 public void setDefaultNamespace(String uri) throws XMLStreamException {
1223 }
1224 };
1225
1226 marshaller.marshal(this, xmlStreamWriter);
1227 return writer.toString();
1228 } catch (JAXBException e) {
1229 throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
1230 }
1231 }
1232
1233
1234
1235
1236
1237
1238 public String toXML() {
1239 try {
1240 if (context == null) {
1241 createJAXBContext();
1242 }
1243 StringWriter writer = new StringWriter();
1244 Marshaller marshaller = Event.context.createMarshaller();
1245 marshaller.marshal(this, writer);
1246 return writer.toString();
1247 } catch (JAXBException e) {
1248 throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
1249 }
1250 }
1251
1252
1253
1254
1255
1256
1257 public static Unmarshaller createUnmarshaller() throws IOException {
1258 try {
1259 if (context == null) {
1260 createJAXBContext();
1261 }
1262 return context.createUnmarshaller();
1263 } catch (JAXBException e) {
1264 throw new IOException(e.getLinkedException() != null ? e.getLinkedException() : e);
1265 }
1266 }
1267
1268 }