-
Notifications
You must be signed in to change notification settings - Fork 4
/
EBUCoreFeatures.cpp
1401 lines (1318 loc) · 49.3 KB
/
EBUCoreFeatures.cpp
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
/*!
* \project_name EBU Player
* \file EBUCoreFeatures.cpp
* \brief EBUCore wrapping features
* \authors Marco Dos Santos Oliveira
* \version 0.1
* \date 28 march 2013
* \copyright This software is published under MPL v2.0
*
*/
#include "EBUCoreFeatures.hpp"
EBUCoreFeatures::EBUCoreFeatures
(
void
)
{
// EBUcore Schemas folder
std::string dir = std::string("./EBUCoreSchema");
// Schemas filenames
std::vector<std::string> files = std::vector<std::string>();
// Get the schemas filenames
getSchemas(dir,files);
//prepare dublin core attributes
DCAttr.push_back(DCAttribute());
// extract all schemas
for (unsigned int i = 0;i < files.size();i++) {
std::cout << files[i] << std::endl;
//std::cout<< "start parsing..."<<std::endl;
extractSchema(dir+"/"+files[i]);
}
// clean the stack and reuse it for skeleton generation
ebucoreStack.clear();
generateSkeleton();
}
EBUCoreFeatures::~EBUCoreFeatures
(
void
)
{
ebucoreStack.clear();
ebucoremodel.clear();
}
void EBUCoreFeatures::UnwrapEBUCore
(
std::string MXFFilename
)
{
// init bmx
bmx::connect_libmxf_logging();
// extract ebucore metadata
try
{
dom_doc = &EBUSDK::EBUCore::ExtractEBUCoreMetadata
(
MXFFilename.c_str(),
&progress_cb
);
dom_root = dom_doc->getDocumentElement();
}
catch (std::exception& e)
{
std::cout << "Standard exception: " << e.what() << std::endl;
}
}
void EBUCoreFeatures::UnwrapEBUCore
(
std::string MXFFilename,
std::string XMLEBUCoreOutputFilename
)
{
// init bmx
bmx::connect_libmxf_logging();
// extract ebucore metadata
EBUSDK::EBUCore::ExtractEBUCoreMetadata
(
MXFFilename.c_str(),
XMLEBUCoreOutputFilename.c_str(),
&progress_cb
);
}
void EBUCoreFeatures::eraseEBUCore
(
std::string MXFFilename
)
{
// init bmx
bmx::connect_libmxf_logging();
// remove ebucore metadatas
EBUSDK::EBUCore::RemoveEBUCoreMetadata
(
MXFFilename.c_str(),
&progress_cb
);
}
void EBUCoreFeatures::eraseEBUCore
(
std::string MXFFilename,
std::string XMLEBUCoreOutputFilename
)
{
// init bmx
bmx::connect_libmxf_logging();
// extract ebucore metadatas
EBUSDK::EBUCore::ExtractEBUCoreMetadata
(
MXFFilename.c_str(),
XMLEBUCoreOutputFilename.c_str(),
&progress_cb
);
// remove ebucore metadatas
EBUSDK::EBUCore::RemoveEBUCoreMetadata
(
MXFFilename.c_str(),
&progress_cb
);
}
void EBUCoreFeatures::WrapEBUCore
(
std::string MXFFilename,
std::string XMLEBUCoreFilename,
bool setHeader,
bool isDark,
bool isSidecar
)
{
// init bmx
bmx::connect_libmxf_logging();
EBUSDK::EBUCore::EmbedEBUCoreMetadata
(
XMLEBUCoreFilename.c_str(),
MXFFilename.c_str(),
&progress_cb,
(EBUSDK::EBUCore::MetadataKind)(isSidecar) ?
EBUSDK::EBUCore::SIDECAR
: ((isDark) ?
EBUSDK::EBUCore::DARK :
EBUSDK::EBUCore::KLV_ENCODED
),
false,
setHeader
);
}
void EBUCoreFeatures::WrapEBUCore
(
std::string MXFFilename,
bool setHeader,
bool isDark,
bool isSidecar,
std::string XMLEBUCoreFilename
)
{
// init bmx
bmx::connect_libmxf_logging();
EBUSDK::EBUCore::EmbedEBUCoreMetadata
(
*dom_doc,
XMLEBUCoreFilename.c_str(),
MXFFilename.c_str(),
&progress_cb,
(EBUSDK::EBUCore::MetadataKind)(isSidecar) ?
EBUSDK::EBUCore::SIDECAR
: ((isDark) ?
EBUSDK::EBUCore::DARK :
EBUSDK::EBUCore::KLV_ENCODED
),
false,
setHeader
);
}
void EBUCoreFeatures::reportEBUCoreSTMetadata
(
std::string MXFFilename,
std::string XMLFilename
)
{
EBUSDK::Analyzer::AnalyzerConfig cfg;
cfg.AnalysisType = EBUSDK::Analyzer::AnalyzerConfig::METADATA;
cfg.MetadataAnalysisType = EBUSDK::Analyzer::AnalyzerConfig::LOGICAL;
cfg.DeepIndexTableAnalysis = false;
EBUSDK::Analyzer::AnalyzeMXFFile
(
MXFFilename.c_str(),
XMLFilename.c_str(),
cfg
);
}
void EBUCoreFeatures::reportEBUCoreSTMux
(
std::string MXFFilename,
std::string XMLFilename
)
{
EBUSDK::Analyzer::AnalyzerConfig cfg;
cfg.AnalysisType = EBUSDK::Analyzer::AnalyzerConfig::MXF_MUX;
cfg.MetadataAnalysisType = EBUSDK::Analyzer::AnalyzerConfig::LOGICAL;
cfg.DeepIndexTableAnalysis = false;
EBUSDK::Analyzer::AnalyzeMXFFile
(
MXFFilename.c_str(),
XMLFilename.c_str(),
cfg
);
}
void EBUCoreFeatures::reportEBUCoreSTDeep
(
std::string MXFFilename,
std::string XMLFilename
)
{
EBUSDK::Analyzer::AnalyzerConfig cfg;
cfg.AnalysisType = EBUSDK::Analyzer::AnalyzerConfig::METADATA;
cfg.MetadataAnalysisType = EBUSDK::Analyzer::AnalyzerConfig::LOGICAL;
cfg.DeepIndexTableAnalysis = true;
EBUSDK::Analyzer::AnalyzeMXFFile
(
MXFFilename.c_str(),
XMLFilename.c_str(),
cfg
);
}
xercesc::DOMDocument * EBUCoreFeatures::getEBUCore
(
void
)
{
return dom_doc;
}
bool EBUCoreFeatures::hasEBUCore
(
void
)
{
return (dom_doc != 0);
}
void EBUCoreFeatures::setEBUCore
(
xercesc::DOMDocument * new_dom_doc
)
{
dom_doc = new_dom_doc;
}
void EBUCoreFeatures::progress_cb
(
float progress,
EBUSDK::EBUCore::ProgressCallbackLevel level,
const char *function,
const char *msg_format,
...
)
{
// append a newline to the msg_format string
int len = strlen(msg_format);
char* newline_msg_format =(char*)malloc((len+2) * sizeof(char));
strncpy(newline_msg_format, msg_format, len); newline_msg_format[len] = 0;
strncat(newline_msg_format, "\n", 1);
va_list p_arg;
va_start(p_arg, msg_format);
switch (level) {
case EBUSDK::EBUCore::INFO:
bmx::log_info(newline_msg_format, p_arg); return;
case EBUSDK::EBUCore::DEBUG:
case EBUSDK::EBUCore::TRACE:
bmx::log_debug(newline_msg_format, p_arg); return;
case 1:
bmx::log_error(newline_msg_format, p_arg); return;
case EBUSDK::EBUCore::WARN:
bmx::log_warn(newline_msg_format, p_arg); return;
default :
bmx::log_warn(newline_msg_format, p_arg);
};
va_end(p_arg);
free(newline_msg_format);
}
// get the path to the schemas
int EBUCoreFeatures::getSchemas
(
std::string dir,
std::vector<std::string> &files
)
{
files=genericFeatures::listFiles(dir);
return 0;
}
// extract a schema
void EBUCoreFeatures::extractSchema
(
std::string pathtofile
)
{
// init xercesc
xercesc::XMLPlatformUtils::Initialize();
xercesc::DOMImplementation* dom_xsd = xercesc::DOMImplementationRegistry::getDOMImplementation(xercesc::XMLString::transcode(""));
xercesc::DOMLSParser* dom_file = dom_xsd->createLSParser(xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, 0);
// extract xml DOM document and element
xercesc::DOMDocument* schema_doc = dom_file->parseURI(pathtofile.c_str());
xercesc::DOMElement* schema_root = schema_doc->getDocumentElement();
// put the cursor at the beginning
schema_root = schema_root->getFirstElementChild();
schema_root = schema_root->getNextElementSibling()->getNextElementSibling();
// generate and store the ebucore root
ebucoremodel.push_back(constructSchema(schema_root));
}
// wrap element attribute
EBUCoreFeatures::AttributeStruct EBUCoreFeatures::packAttribute
(
xercesc::DOMElement * el
)
{
// prepare the attribute struct
EBUCoreFeatures::AttributeStruct attr;
// grab the attributes
std::string name (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("name"))));
std::string ref (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("ref"))));
std::string type (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("type"))));
std::string byDefault (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("default"))));
// wrap the attribute
attr.name = ((name.size()>0)?name:ref);
attr.type = ((type.size()>0)?type:"string");
attr.hasDefaultValue = ((byDefault.size()>0)?true:false);
attr.defaultValue = ((byDefault.size()>0)?byDefault:"NULL");
// wrap the attribute enumeration
attr.hasEnumeration = false;
std::vector<std::string> attrEnum;
attr.Enumeration = attrEnum;
// return the attribute
return attr;
}
// generate the attributes of an element
std::list<EBUCoreFeatures::AttributeStruct> EBUCoreFeatures::generateAttributes
(
std::string father,
xercesc::DOMElement * el
)
{
// groupName to store the attributeGroups
std::vector<std::string> groupName;
// attributes list
std::list<EBUCoreFeatures::AttributeStruct> attributes;
// when father type hasn't a name, that means the type is implicit
if (father =="") {
// we must save the current position
xercesc::DOMElement * tmp = el->getFirstElementChild();
while (tmp != 0 && (std::string)(xercesc::XMLString::transcode(tmp->getTagName())) != "complexType") {
tmp = tmp->getNextElementSibling();// next
}
// and looking for the implicit father complexType (without name)
if (tmp != 0 && (std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "complexType" ) {
// when the complexType is identified, put the cursor inside the first child
tmp = tmp->getFirstElementChild();
// while xercesc pointer not null
while (tmp != 0) {
// if attribute is a simpleContent
if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "simpleContent") {
// grab the first child of the first child of the current element
xercesc::DOMElement * localTmp = tmp->getFirstElementChild()->getFirstElementChild();
// if xercersc pointer not null
while (localTmp != 0) {
// if attribute is a simple attribute
if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attribute" ) {
// wrap and push the attribute
attributes.push_back(packAttribute(localTmp));
// if attribute is an attributeGroup
} else if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attributeGroup" ) {
// push the attributeGroup name inside the attributeGroup stack
groupName.push_back(genericFeatures::removePrefix ((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("ref")))),":" ));
}
// next element...
localTmp = localTmp->getNextElementSibling();
}
// if attribute is a complexContent
} else if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "complexContent") {
// grab the first child of the current element
xercesc::DOMElement * localTmp = tmp->getFirstElementChild();
// if it is a DublinCore attribute
if (isDCSimpleType((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("base")))))) {
//push the dublincore attribute
attributes.push_back(DCAttribute());
} else {
// if it is not a dublincore attribute, that means that is an attributeGroup or external attribute
groupName.push_back(genericFeatures::removePrefix ((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("base")))),":" ));
}
// enter inside the current element
localTmp = localTmp->getFirstElementChild();
// in plus of external attribute and attributeGroup treatments, we can have
// several local attributes and attributeGroups to solve
// if xercesc pointer is not null
while (localTmp != 0) {
// if it is a simple attribute
if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attribute" ) {
// wrap and push the attribute
attributes.push_back(packAttribute(localTmp));
// if it is an attributeGroup
} else if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attributeGroup" ) {
// save the attributeGroup name/reference...
groupName.push_back(genericFeatures::removePrefix ((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("ref")))),":"));
}
// next element...
localTmp = localTmp->getNextElementSibling();
}
// if attribute is an attributeGroup
} else if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "attributeGroup"){
// save the attributeGroup name/reference
groupName.push_back(genericFeatures::removePrefix ((std::string)(xercesc::XMLString::transcode(tmp->getAttribute (xercesc::XMLString::transcode("ref")))), ":" ));
// if attribute is a simple attribute
} else if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "attribute") {
// wrap and push the attribute
attributes.push_back(packAttribute(tmp));
}
// next...
tmp = tmp->getNextElementSibling();
}
}
}
// We don't know if the father is an implicit complexType who references
// an external attributeGroup, so we consider it as an external references
if (father!="") {
groupName.push_back(father);
}
// for each external attributeGroup, build the set of attributes
for (int i=0;i<(int)groupName.size();i++) {
// pointer starter...
xercesc::DOMElement * tmpEl = el;
// looking for the root of the schema document
while ((std::string)(xercesc::XMLString::transcode((tmpEl->getParentNode())->getNodeName())) != "schema") {
tmpEl = dynamic_cast<xercesc::DOMElement*>(tmpEl->getParentNode());
}
// grab the first child of the schema
tmpEl=(dynamic_cast<xercesc::DOMElement*>(tmpEl->getParentNode()))->getFirstElementChild();
// looking for a complexType or an attributeGroup with the right name
while (((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != groupName.at(i) ) || ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "attributeGroup" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != groupName.at(i))) {
tmpEl = tmpEl->getNextElementSibling();
}
//grab the first child
tmpEl=tmpEl->getFirstElementChild();
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "complexContent")
{
tmpEl=tmpEl->getFirstElementChild();
if (!isDCSimpleType(xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("base")))))
{
groupName.push_back(genericFeatures::removePrefix ((std::string)(xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("base")))), ":" ));
} else {
attributes.push_back(DCAttribute());
}
tmpEl=tmpEl->getFirstElementChild();
}
else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "simpleContent")
{
tmpEl=tmpEl->getFirstElementChild();
// must be completed !!!!
tmpEl=tmpEl->getFirstElementChild();
}
// while xerces pointer not null
do {
// and if the element is an attribute
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "attribute") {
// wrap and push the attribute
attributes.push_back(packAttribute(tmpEl));
}
else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "attributeGroup")
{
groupName.push_back(genericFeatures::removePrefix ((std::string)(xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref")))), ":" ));
}
// next
tmpEl = tmpEl->getNextElementSibling();
} while (tmpEl != 0);
}
return attributes;
}
std::list<std::list<std::string>> EBUCoreFeatures::generateChoices
(
std::string father,
xercesc::DOMElement * el
)
{
//std::cout<<"I'm trying to generate choices for "<<father<<std::endl;
std::list<std::list<std::string>> choices;
// copy the current position of xercesc pointer
if (father != "")
{
xercesc::DOMElement * tmpEl = el;
// while xercesc pointer not null, element different of complexType with the proper name
while (tmpEl != 0 && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" || xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != father ))
{
tmpEl = tmpEl->getNextElementSibling();// next
}
if (tmpEl != 0) {
// grab the first child of proper element
tmpEl=tmpEl->getFirstElementChild();
// looking for the choice/sequence of elements
while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "choice" && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence")
{
tmpEl = tmpEl->getNextElementSibling(); // next
}
if (tmpEl != 0)
{
// if not yet choice tag, then continu to look for choice of elements
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "choice")
{
tmpEl=tmpEl->getFirstElementChild();
}
// looking for choice tag
while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "choice")
{
tmpEl = tmpEl->getNextElementSibling(); // next
}
// if pointer not null, grab the first child of the current choice
if (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "choice")
{
tmpEl=tmpEl->getFirstElementChild();
}
// generate the choice list
while (tmpEl != 0)
{
std::list<std::string> tmp;
// if it's element tag
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element")
{
tmp.push_back((std::string)(xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name")))));
}
// else, it's a sequence tag
else
{
xercesc::DOMElement * local = tmpEl->getFirstElementChild();
// looking for element tags inside sequence tag
while (local != 0)
{
if ((std::string)(xercesc::XMLString::transcode(local->getTagName())) == "element")
{
tmp.push_back((std::string)(xercesc::XMLString::transcode(local->getAttribute (xercesc::XMLString::transcode("name")))));
}
local = local->getNextElementSibling(); // next
}
}
choices.push_back(tmp); // push the choice list
tmpEl = tmpEl->getNextElementSibling(); // next
}
}
}
}
return choices;
}
// generate the children of an elements
std::list<EBUCoreFeatures::ElementStruct> EBUCoreFeatures::generateLocalChildren
(
std::string father,
xercesc::DOMElement * el,
xercesc::DOMElement * cursor
)
{
//std::cout<<(std::string)(xercesc::XMLString::transcode(cursor->getTagName()))<<std::endl;
// instantiate the children list
std::list<EBUCoreFeatures::ElementStruct> children;
// copy the current position of xercesc pointer
xercesc::DOMElement * tmpEl = cursor;
while (tmpEl != 0 && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType"))
{
tmpEl = tmpEl->getNextElementSibling();
}
if (tmpEl != 0)
{
tmpEl=tmpEl->getFirstElementChild();
}
while (tmpEl != 0 && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence"))
{
tmpEl = tmpEl->getNextElementSibling();
}
if (tmpEl != 0)
{
tmpEl=tmpEl->getFirstElementChild();
}
while (tmpEl != 0)
{
// if current tag kind is element
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") {
// prepare the element information
std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))));
std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type"))));
std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))));
std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
// instantiate the children struct
EBUCoreFeatures::ElementStruct internalChildren;
// grab the right name/references
internalChildren.name = (name.size()>0)?name:ref;
// identify the cardinality and the type of element
internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
internalChildren.type = ( (type.size()>0) ? type : "" );
internalChildren.choices = generateChoices(((isEBUCoreType(internalChildren.type))?genericFeatures::removePrefix(internalChildren.type, ":"):""), el);
// if type is not standard
if (!isStandardType(type)) {
// if type is not null
if (type.size()>0) {
//generate the attribute list of the current element
internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(genericFeatures::removePrefix(internalChildren.type, ":"), tmpEl);
// and correct his type if required
internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type );
} else {
// generate the attribute list of the current element and correct his type if required
internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl);
internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ;
}
}
// if element type is ebucore and the type not present in the stack, then
if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) {
ebucoreStack.push_back(internalChildren.type); // push the type
// generate the children
internalChildren.children = generateChildren(genericFeatures::removePrefix(internalChildren.type,":"), el);
ebucoreStack.pop_back(); // pop the type
}
else if (internalChildren.type == "" && tmpEl->getFirstElementChild() != 0)
{
ebucoreStack.push_back(internalChildren.type); // push the type
// generate the children
internalChildren.children = generateLocalChildren("", el, tmpEl->getFirstElementChild());
ebucoreStack.pop_back(); // pop the type
}
// push the children list
children.push_back(internalChildren);
// if the current tag king is group, then
} else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group") {
// generate the children of this group and then add it to current list of children
children = generateGroupChildren
(
children,
xercesc::XMLString::transcode
(
tmpEl->getAttribute
(
xercesc::XMLString::transcode("ref")
)
),
el
);
} else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "choice")
{
children = generateChoiceChildren(children, tmpEl, el);
}
tmpEl = tmpEl->getNextElementSibling(); // next
}
// enter
return children;
}
// generate the children of an elements
std::list<EBUCoreFeatures::ElementStruct> EBUCoreFeatures::generateChildren
(
std::string father,
xercesc::DOMElement * el
)
{
// instantiate the children list
// extension should stay empty
std::string localExtension("");
std::list<EBUCoreFeatures::ElementStruct> children;
// copy the current position of xercesc pointer
xercesc::DOMElement * tmpEl = el;
// while xercesc pointer not null, element different of complexType with the proper name
while (tmpEl != 0 && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" || xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != father )) {
tmpEl = tmpEl->getNextElementSibling();// next
}
// grab the first child of proper element
tmpEl=tmpEl->getFirstElementChild();
// looking for the sequence of elements
while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "choice" && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence" && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexContent")
{
tmpEl = tmpEl->getNextElementSibling(); // next
}
if (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "complexContent" && father != "")
{
tmpEl=tmpEl->getFirstElementChild();
localExtension =(std::string)(xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("base"))));
tmpEl=tmpEl->getFirstElementChild();
}
// if pointer not null, grab the first child of the current element
if (tmpEl != 0)
{
tmpEl=tmpEl->getFirstElementChild();
}
// while xerces point not null, loop
while (tmpEl != 0) {
// if current tag kind is element
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") {
// prepare the element information
std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))));
std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type"))));
std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))));
std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
// instantiate the children struct
EBUCoreFeatures::ElementStruct internalChildren;
// grab the right name/references
internalChildren.name = (name.size()>0)?name:ref;
// identify the cardinality and the type of element
internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
internalChildren.type = ( (type.size()>0) ? type : "" );
internalChildren.choices = generateChoices(((isEBUCoreType(internalChildren.type))?genericFeatures::removePrefix(internalChildren.type, ":"):""), el);
// if type is not standard
if (!isStandardType(type)) {
// if type is not null
if (type.size()>0) {
//generate the attribute list of the current element
internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(genericFeatures::removePrefix(internalChildren.type, ":"), tmpEl);
// and correct his type if required
internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type );
} else {
// generate the attribute list of the current element and correct his type if required
internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl);
internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ;
}
}
// if element type is ebucore and the type not present in the stack, then
if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) {
ebucoreStack.push_back(internalChildren.type); // push the type
// generate the children
internalChildren.children = generateChildren(genericFeatures::removePrefix(internalChildren.type,":"), el);
ebucoreStack.pop_back(); // pop the type
}
else if (internalChildren.type == "" && tmpEl->getFirstElementChild() != 0)
{
ebucoreStack.push_back(internalChildren.type); // push the type
// generate the children
internalChildren.children = generateLocalChildren("", el, tmpEl->getFirstElementChild());
ebucoreStack.pop_back(); // pop the type
}
// push the children list
children.push_back(internalChildren);
// if the current tag king is group, then
} else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group") {
// generate the children of this group and then add it to current list of children
children = generateGroupChildren
(
children,
xercesc::XMLString::transcode
(
tmpEl->getAttribute
(
xercesc::XMLString::transcode("ref")
)
),
el
);
} else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "choice")
{
children = generateChoiceChildren(children, tmpEl, el);
}
tmpEl = tmpEl->getNextElementSibling(); // next
}
if (localExtension != "" && localExtension != "dc:elementType")
{
children = generateExtensionChildren
(
children,
genericFeatures::removePrefix(localExtension,":"),
el
);
}
/* std::cout<<"fathertype : "<<father<<std::endl;
for (std::list<EBUCoreFeatures::ElementStruct>::iterator it=children.begin() ; it != children.end(); ++it)
{
EBUCoreFeatures::ElementStruct child = *it;
std::cout<<" : "<<child.name<<std::endl;
}
*/
return children;
}
std::list<EBUCoreFeatures::ElementStruct> EBUCoreFeatures::generateExtensionChildren
(
std::list<ElementStruct> brothers,
std::string father,
xercesc::DOMElement * el
)
{
std::string localExtension("");
std::list<EBUCoreFeatures::ElementStruct> children = brothers;
// store the current position of xercesc pointer
xercesc::DOMElement * tmpEl = el;
// while xercesc pointer not null, element different of complexType with the proper name
while (tmpEl != 0 && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" || xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != father )) {
tmpEl = tmpEl->getNextElementSibling();// next
}
// grab the first child of proper element
tmpEl=tmpEl->getFirstElementChild();
// looking for the sequence of elements
while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "choice" && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence" && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexContent")
{
tmpEl = tmpEl->getNextElementSibling(); // next
}
if (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "complexContent" && father != "")
{
tmpEl=tmpEl->getFirstElementChild();
localExtension =(std::string)(xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("base"))));
tmpEl=tmpEl->getFirstElementChild();
}
// if pointer not null, grab the first child of the current element
if (tmpEl != 0)
{
tmpEl=tmpEl->getFirstElementChild();
}
// while xerces point not null, loop
while (tmpEl != 0) {
// if current tag kind is element
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") {
// prepare the element information
std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))));
std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type"))));
std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))));
std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
// instantiate the children struct
EBUCoreFeatures::ElementStruct internalChildren;
// grab the right name/references
internalChildren.name = (name.size()>0)?name:ref;
// identify the cardinality and the type of element
internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
internalChildren.type = ( (type.size()>0) ? type : "" );
internalChildren.choices = generateChoices(((isEBUCoreType(internalChildren.type))?genericFeatures::removePrefix(internalChildren.type, ":"):""), el);
// if type is not standard
if (!isStandardType(type)) {
// if type is not null
if (type.size()>0) {
//generate the attribute list of the current element
internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(genericFeatures::removePrefix(internalChildren.type, ":"), tmpEl);
// and correct his type if required
internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type );
} else {
// generate the attribute list of the current element and correct his type if required
internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl);
internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ;
}
}
// if element type is ebucore and the type not present in the stack, then
if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) {
ebucoreStack.push_back(internalChildren.type); // push the type
// generate the children
internalChildren.children = generateChildren(genericFeatures::removePrefix(internalChildren.type,":"), el);
ebucoreStack.pop_back(); // pop the type
}
else if (internalChildren.type == "" && tmpEl->getFirstElementChild() != 0)
{
ebucoreStack.push_back(internalChildren.type); // push the type
// generate the children
internalChildren.children = generateLocalChildren("", el, tmpEl->getFirstElementChild());
ebucoreStack.pop_back(); // pop the type
}
// push the children list
children.push_back(internalChildren);
// if the current tag king is group, then
} else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group") {
// generate the children of this group and then add it to current list of children
children = generateGroupChildren
(
children,
xercesc::XMLString::transcode
(
tmpEl->getAttribute
(
xercesc::XMLString::transcode("ref")
)
),
el
);
} else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "choice")
{
children = generateChoiceChildren(children, tmpEl, el);
}
tmpEl = tmpEl->getNextElementSibling(); // next
}
if (localExtension != "" && localExtension != "dc:elementType")
{
children = generateExtensionChildren
(
children,
genericFeatures::removePrefix(localExtension,":"),
el
);
}
return children;
}
// include external elements (from groups)
std::list<EBUCoreFeatures::ElementStruct> EBUCoreFeatures::generateGroupChildren
(
std::list<ElementStruct> brothers,
std::string father,
xercesc::DOMElement * el
)
{
std::list<EBUCoreFeatures::ElementStruct> children = brothers;
// store the current position of xercesc pointer
xercesc::DOMElement * tmpEl = el;
// looking for the group who contains the other elements with the father name
while (tmpEl != 0 && !((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) == genericFeatures::removePrefix(father,":") )) {
tmpEl = tmpEl->getNextElementSibling();
}
// enter inside the group
tmpEl=tmpEl->getFirstElementChild();
// looking for the sequence
while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence") {
tmpEl = tmpEl->getNextElementSibling();
}
// if pointer not null, grab the first child
if (tmpEl != 0) {
tmpEl=tmpEl->getFirstElementChild();
}
// while xerces pointer not null,
while (tmpEl != 0) {
// if it's an element
if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") {
// prepare the element informations
std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))));
std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type"))));
std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))));
std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
// instantiate the list of children
EBUCoreFeatures::ElementStruct internalChildren;
// identify the element name
internalChildren.name = (name.size()>0)?name:ref;
internalChildren.hasChoice = false;
// identify the cardinality and type
internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
internalChildren.type = ( (type.size()>0) ? type : "" );
internalChildren.choices = generateChoices(((isEBUCoreType(internalChildren.type))?genericFeatures::removePrefix(internalChildren.type, ":"):""), el);
// if it is not a standard type
if (!isStandardType(type)) {
// and if type is not null
if (type.size()>0) {
// generate attributes
internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(genericFeatures::removePrefix(internalChildren.type, ":"), tmpEl);
// and correct the type is required
internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type );
} else {
// generate attributes and correct the type is required
internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl);
internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ;
}
}
// if it is an ebucore element and the type of this element is not present in the element type stack
if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) {
// push the type