Revision 72eb64b9
Added by Andreas Müller over 12 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/MarkupDocumentImport.java | ||
---|---|---|
60 | 60 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
61 | 61 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
62 | 62 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
63 |
import eu.etaxonomy.cdm.model.description.Distribution; |
|
63 | 64 |
import eu.etaxonomy.cdm.model.description.Feature; |
65 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase; |
|
64 | 66 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
65 | 67 |
import eu.etaxonomy.cdm.model.description.TextData; |
66 | 68 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
... | ... | |
84 | 86 |
import eu.etaxonomy.cdm.model.reference.IJournal; |
85 | 87 |
import eu.etaxonomy.cdm.model.reference.Reference; |
86 | 88 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
89 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
|
87 | 90 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
88 | 91 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
89 | 92 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
... | ... | |
101 | 104 |
*/ |
102 | 105 |
@Component |
103 | 106 |
public class MarkupDocumentImport extends MarkupImportBase implements ICdmIO<MarkupImportState> { |
107 |
private static final String HABITAT = "habitat"; |
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
private static final String LIFE_CYCLE_PERIODS = "lifeCyclePeriods"; |
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
private static final String DISTRIBUTION_LOCALITY = "distributionLocality"; |
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
private static final String REFERENCE = "reference"; |
|
120 |
|
|
121 |
|
|
122 |
|
|
104 | 123 |
private static final Logger logger = Logger.getLogger(MarkupDocumentImport.class); |
105 | 124 |
|
106 | 125 |
|
... | ... | |
480 | 499 |
boolean hasTitle = false; |
481 | 500 |
boolean hasNomenclature = false; |
482 | 501 |
String taxonTitle = null; |
483 |
Extension writerExtension = null; |
|
484 |
|
|
485 |
|
|
502 |
|
|
486 | 503 |
while (reader.hasNext()){ |
487 | 504 |
XMLEvent next = readNoWhitespace(reader); |
488 | 505 |
if (next.isEndElement()){ |
... | ... | |
505 | 522 |
}else if(isEndingElement(next, KEY)){ |
506 | 523 |
//NOT YET IMPLEMENTED |
507 | 524 |
popUnimplemented(next.asEndElement()); |
508 |
}else if(isEndingElement(next, NOTES)){ |
|
509 |
//NOT YET IMPLEMENTED |
|
510 |
popUnimplemented(next.asEndElement()); |
|
511 | 525 |
}else if(isEndingElement(next, REFERENCES)){ |
512 | 526 |
//NOT YET IMPLEMENTED |
513 | 527 |
popUnimplemented(next.asEndElement()); |
... | ... | |
522 | 536 |
taxonTitle = handleTaxonTitle(state, reader, next); |
523 | 537 |
hasTitle = true; |
524 | 538 |
}else if(isStartingElement(next, WRITER)){ |
525 |
List<FootnoteDataHolder> footNotes = new ArrayList<FootnoteDataHolder>(); |
|
526 |
writerExtension = handleWriter(state, reader, next, footNotes);
|
|
527 |
taxon.addExtension(writerExtension);
|
|
539 |
|
|
540 |
WriterDataHolder writer = handleWriter(state, reader, next);
|
|
541 |
taxon.addExtension(writer.extension);
|
|
528 | 542 |
//TODO what if taxonTitle comes later |
529 |
if (StringUtils.isNotBlank(taxonTitle) && writerExtension != null){ |
|
530 |
String writer = writerExtension.getValue(); |
|
531 |
Reference sec = ReferenceFactory.newBookSection(); |
|
543 |
if (StringUtils.isNotBlank(taxonTitle) && writer.extension != null){ |
|
544 |
Reference<?> sec = ReferenceFactory.newBookSection(); |
|
532 | 545 |
sec.setTitle(taxonTitle); |
533 |
TeamOrPersonBase author = createAuthor(writer);
|
|
546 |
TeamOrPersonBase<?> author = createAuthor(writer.writer);
|
|
534 | 547 |
sec.setAuthorTeam(author); |
535 | 548 |
sec.setInReference(state.getConfig().getSourceReference()); |
536 | 549 |
taxon.setSec(sec); |
537 |
registerFootnotes(state, sec, footNotes);
|
|
550 |
registerFootnotes(state, sec, writer.footnotes);
|
|
538 | 551 |
}else{ |
539 | 552 |
String message = "No taxontitle exists for writer"; |
540 | 553 |
fireWarningEvent(message, next, 6); |
... | ... | |
550 | 563 |
}else if(isStartingElement(next, FEATURE)){ |
551 | 564 |
handleFeature(state, reader, next); |
552 | 565 |
}else if(isStartingElement(next, NOTES)){ |
553 |
handleNotYetImplementedElement(next); |
|
566 |
//TODO is this the correct way to handle notes? |
|
567 |
String note = handleNotes(state, reader, next); |
|
568 |
|
|
569 |
UUID notesUuid; |
|
570 |
try { |
|
571 |
notesUuid = state.getTransformer().getFeatureUuid("notes"); |
|
572 |
Feature feature = getFeature(state, notesUuid, "Notes", "Notes", "note", null); |
|
573 |
TextData textData = TextData.NewInstance(feature); |
|
574 |
textData.putText(Language.DEFAULT(), note); |
|
575 |
TaxonDescription description = getTaxonDescription(taxon, false, true); |
|
576 |
description.addElement(textData); |
|
577 |
} catch (UndefinedTransformerMethodException e) { |
|
578 |
String message = "getFeatureUuid method not yet implemented"; |
|
579 |
fireWarningEvent(message, next, 8); |
|
580 |
} |
|
554 | 581 |
}else if(isStartingElement(next, REFERENCES)){ |
555 | 582 |
handleNotYetImplementedElement(next); |
556 | 583 |
}else if(isStartingElement(next, FIGURE)){ |
... | ... | |
575 | 602 |
} |
576 | 603 |
|
577 | 604 |
|
605 |
private String handleNotes(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
606 |
checkNoAttributes(parentEvent); |
|
607 |
|
|
608 |
String text = ""; |
|
609 |
while (reader.hasNext()){ |
|
610 |
XMLEvent next = readNoWhitespace(reader); |
|
611 |
if(isMyEndingElement(next, parentEvent)){ |
|
612 |
return text; |
|
613 |
}else if (next.isEndElement()){ |
|
614 |
if (isEndingElement(next, HEADING)){ |
|
615 |
popUnimplemented(next.asEndElement()); |
|
616 |
}else if (isEndingElement(next, SUB_HEADING)){ |
|
617 |
popUnimplemented(next.asEndElement()); |
|
618 |
}else if (isEndingElement(next, WRITER)){ |
|
619 |
popUnimplemented(next.asEndElement()); |
|
620 |
}else if (isEndingElement(next, NUM)){ |
|
621 |
popUnimplemented(next.asEndElement()); |
|
622 |
}else { |
|
623 |
handleUnexpectedEndElement(next.asEndElement()); |
|
624 |
} |
|
625 |
}else if (next.isStartElement()){ |
|
626 |
if (isStartingElement(next, HEADING)){ |
|
627 |
handleNotYetImplementedElement(next); |
|
628 |
}else if (isStartingElement(next, SUB_HEADING)){ |
|
629 |
handleNotYetImplementedElement(next); |
|
630 |
}else if (isStartingElement(next, WRITER)){ |
|
631 |
handleNotYetImplementedElement(next); |
|
632 |
}else if (isStartingElement(next, NUM)){ |
|
633 |
handleNotYetImplementedElement(next); |
|
634 |
}else if (isStartingElement(next, STRING)){ |
|
635 |
//TODO why multiple strings? |
|
636 |
text += handleString(state, reader, next); |
|
637 |
}else { |
|
638 |
handleUnexpectedStartElement(next.asStartElement()); |
|
639 |
} |
|
640 |
}else { |
|
641 |
handleUnexpectedElement(next); |
|
642 |
} |
|
643 |
} |
|
644 |
throw new IllegalStateException("<Notes> has no closing tag"); |
|
645 |
} |
|
646 |
|
|
647 |
|
|
578 | 648 |
/** |
579 | 649 |
* @param state |
580 | 650 |
* @param attributes |
... | ... | |
690 | 760 |
|
691 | 761 |
} |
692 | 762 |
|
693 |
private Extension handleWriter(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent, List<FootnoteDataHolder> footNotes) throws XMLStreamException {
|
|
763 |
private WriterDataHolder handleWriter(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
|
|
694 | 764 |
String text = ""; |
695 | 765 |
checkNoAttributes(parentEvent); |
766 |
WriterDataHolder dataHolder = new WriterDataHolder(); |
|
767 |
List<FootnoteDataHolder> footnotes = new ArrayList<FootnoteDataHolder>(); |
|
696 | 768 |
|
697 | 769 |
//TODO handle attributes |
698 | 770 |
while (reader.hasNext()){ |
699 | 771 |
XMLEvent next = readNoWhitespace(reader); |
700 | 772 |
if (next.isEndElement()){ |
701 | 773 |
if (isMyEndingElement(next, parentEvent)){ |
774 |
text = CdmUtils.removeBrackets(text); |
|
702 | 775 |
if (checkMandatoryText(text, parentEvent)){ |
703 |
UUID uuidWriter = MarkupTransformer.uuidWriter; |
|
704 |
ExtensionType titleExtensionType = this.getExtensionType(state, uuidWriter, "Writer", "writer", "writer"); |
|
776 |
text = normalize(text); |
|
777 |
dataHolder.writer = text; |
|
778 |
dataHolder.footnotes = footnotes; |
|
779 |
|
|
780 |
//Extension |
|
781 |
UUID uuidWriterExtension = MarkupTransformer.uuidWriterExtension; |
|
782 |
ExtensionType writerExtensionType = this.getExtensionType(state, uuidWriterExtension, "Writer", "writer", "writer"); |
|
705 | 783 |
Extension extension = Extension.NewInstance(); |
706 |
extension.setType(titleExtensionType); |
|
707 |
extension.setValue(normalize(text)); |
|
708 |
return extension; |
|
784 |
extension.setType(writerExtensionType); |
|
785 |
extension.setValue(text); |
|
786 |
dataHolder.extension = extension; |
|
787 |
|
|
788 |
//Annotation |
|
789 |
UUID uuidWriterAnnotation = MarkupTransformer.uuidWriterAnnotation; |
|
790 |
AnnotationType writerAnnotationType = this.getAnnotationType(state, uuidWriterAnnotation, "Writer", "writer", "writer", null); |
|
791 |
Annotation annotation = Annotation.NewInstance(text, writerAnnotationType, Language.DEFAULT()); |
|
792 |
dataHolder.annotation = annotation; |
|
793 |
|
|
794 |
|
|
795 |
|
|
796 |
return dataHolder; |
|
709 | 797 |
}else{ |
710 | 798 |
return null; |
711 | 799 |
} |
... | ... | |
722 | 810 |
if(isStartingElement(next, FOOTNOTE_REF)){ |
723 | 811 |
FootnoteDataHolder footNote = handleFootnoteRef(state, reader, next); |
724 | 812 |
if (footNote.isRef()){ |
725 |
footNotes.add(footNote);
|
|
813 |
footnotes.add(footNote);
|
|
726 | 814 |
}else{ |
727 | 815 |
logger.warn ("Non ref footnotes not yet impelemnted"); |
728 | 816 |
} |
... | ... | |
1015 | 1103 |
popUnimplemented(next.asEndElement()); |
1016 | 1104 |
}else if (isEndingElement(next, COLLECTION)){ |
1017 | 1105 |
popUnimplemented(next.asEndElement()); |
1018 |
}else if (isEndingElement(next, REFERENCES)){ |
|
1019 |
popUnimplemented(next.asEndElement()); |
|
1020 | 1106 |
}else if (isEndingElement(next, BR)){ |
1021 | 1107 |
isTextMode = true; |
1022 | 1108 |
}else if (isHtml(next)){ |
... | ... | |
1030 | 1116 |
}else if (isStartingElement(next, COLLECTION)){ |
1031 | 1117 |
handleNotYetImplementedElement(next); |
1032 | 1118 |
}else if (isStartingElement(next, REFERENCES)){ |
1033 |
handleNotYetImplementedElement(next);
|
|
1119 |
text += " " + handleInLineReferences(state, reader, next) + " ";
|
|
1034 | 1120 |
}else if (isStartingElement(next, BR)){ |
1035 | 1121 |
text += "<br/>"; |
1036 | 1122 |
isTextMode = false; |
... | ... | |
1044 | 1130 |
String message = "footnoteString is not in text mode"; |
1045 | 1131 |
fireWarningEvent(message, next, 6); |
1046 | 1132 |
}else{ |
1047 |
text += next.asCharacters().getData();
|
|
1133 |
text += next.asCharacters().getData().trim(); //getCData(state, reader, next); does not work as we have inner tags like <references>
|
|
1048 | 1134 |
} |
1049 | 1135 |
}else { |
1050 | 1136 |
handleUnexpectedEndElement(next.asEndElement()); |
... | ... | |
1055 | 1141 |
} |
1056 | 1142 |
|
1057 | 1143 |
|
1144 |
private String handleInLineReferences(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
1145 |
checkNoAttributes(parentEvent); |
|
1146 |
|
|
1147 |
boolean hasReference = false; |
|
1148 |
String text = ""; |
|
1149 |
while (reader.hasNext()){ |
|
1150 |
XMLEvent next = readNoWhitespace(reader); |
|
1151 |
if (isMyEndingElement(next, parentEvent)){ |
|
1152 |
checkMandatoryElement(hasReference, parentEvent.asStartElement(), REFERENCE); |
|
1153 |
return text; |
|
1154 |
}else if(isStartingElement(next, REFERENCE)){ |
|
1155 |
text += handleInLineReference(state, reader, next); |
|
1156 |
hasReference = true; |
|
1157 |
}else{ |
|
1158 |
handleUnexpectedElement(next); |
|
1159 |
} |
|
1160 |
} |
|
1161 |
//TODO handle missing end element |
|
1162 |
throw new IllegalStateException("<References> has no closing tag"); |
|
1163 |
} |
|
1164 |
|
|
1165 |
|
|
1166 |
private String handleInLineReference(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
1167 |
checkNoAttributes(parentEvent); |
|
1168 |
|
|
1169 |
boolean hasRefPart = false; |
|
1170 |
Map<String, String> refMap = new HashMap<String, String>(); |
|
1171 |
while (reader.hasNext()){ |
|
1172 |
XMLEvent next = readNoWhitespace(reader); |
|
1173 |
if (isMyEndingElement(next, parentEvent)){ |
|
1174 |
checkMandatoryElement(hasRefPart, parentEvent.asStartElement(), REF_PART); |
|
1175 |
Reference<?> reference = createReference(state, refMap, next); |
|
1176 |
String result = "<ref uuid='%s'>%s</ref>"; |
|
1177 |
result = String.format(result, reference.getUuid(), reference.getTitleCache()); |
|
1178 |
return result; |
|
1179 |
}else if(isStartingElement(next, REF_PART)){ |
|
1180 |
handleRefPart(state, reader, next, refMap); |
|
1181 |
hasRefPart = true; |
|
1182 |
}else{ |
|
1183 |
handleUnexpectedElement(next); |
|
1184 |
} |
|
1185 |
} |
|
1186 |
//TODO handle missing end element |
|
1187 |
throw new IllegalStateException("<Reference> has no closing tag"); |
|
1188 |
} |
|
1189 |
|
|
1190 |
|
|
1058 | 1191 |
private void handleHomotypes(MarkupImportState state, XMLEventReader reader, StartElement parentEvent) throws XMLStreamException { |
1059 | 1192 |
checkNoAttributes(parentEvent); |
1060 | 1193 |
|
... | ... | |
1084 | 1217 |
hasNom = true; |
1085 | 1218 |
}else if(isStartingElement(next, NAME_TYPE)){ |
1086 | 1219 |
state.setNameType(true); |
1087 |
handleNameType(state, reader, next); |
|
1220 |
handleNameType(state, reader, next, homotypicalGroup);
|
|
1088 | 1221 |
}else if(isStartingElement(next, SPECIMEN_TYPE)){ |
1089 | 1222 |
handleSpecimenType(state, reader, next, homotypicalGroup); |
1090 | 1223 |
}else if(isStartingElement(next, NOTES)){ |
... | ... | |
1102 | 1235 |
} |
1103 | 1236 |
|
1104 | 1237 |
|
1105 |
private void handleNameType(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
1238 |
private void handleNameType(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent, HomotypicalGroup homotypicalGroup) throws XMLStreamException {
|
|
1106 | 1239 |
Map<String, Attribute> attributes = getAttributes(parentEvent); |
1107 | 1240 |
String typeStatus = getAndRemoveAttributeValue(attributes, TYPE_STATUS); |
1108 | 1241 |
checkNoAttributes(attributes, parentEvent); |
... | ... | |
1114 | 1247 |
String message = "Type status could not be recognized: %s"; |
1115 | 1248 |
message = String.format(message, typeStatus); |
1116 | 1249 |
fireWarningEvent(message, parentEvent, 4); |
1250 |
status = null; |
|
1117 | 1251 |
} |
1118 | 1252 |
|
1119 | 1253 |
boolean hasNom = false; |
... | ... | |
1122 | 1256 |
if (next.isEndElement()){ |
1123 | 1257 |
if (isMyEndingElement(next, parentEvent)){ |
1124 | 1258 |
checkMandatoryElement(hasNom, parentEvent.asStartElement(), NOM); |
1259 |
state.setNameType(false); |
|
1125 | 1260 |
return; |
1126 | 1261 |
}else{ |
1127 | 1262 |
if(isEndingElement(next, ACCEPTED_NAME)){ |
... | ... | |
1133 | 1268 |
} |
1134 | 1269 |
}else if (next.isStartElement()){ |
1135 | 1270 |
if(isStartingElement(next, NOM)){ |
1136 |
NonViralName name = handleNom(state, reader, next, null); |
|
1271 |
//TODO should we check if the type is always a species, is this a rule? |
|
1272 |
NonViralName<?> speciesName = handleNom(state, reader, next, null); |
|
1273 |
for (TaxonNameBase<?,?> name : homotypicalGroup.getTypifiedNames()){ |
|
1274 |
name.addNameTypeDesignation(speciesName, null, null, null, status, false, false, false, false); |
|
1275 |
} |
|
1137 | 1276 |
hasNom = true; |
1138 | 1277 |
}else if(isStartingElement(next, ACCEPTED_NAME)){ |
1139 | 1278 |
handleNotYetImplementedElement(next); |
... | ... | |
1397 | 1536 |
if ("locality".equalsIgnoreCase(classValue)){ |
1398 | 1537 |
isLocality = true; |
1399 | 1538 |
}else{ |
1400 |
try { |
|
1401 |
areaLevel = state.getTransformer().getNamedAreaLevelByKey(classValue); |
|
1402 |
} catch (UndefinedTransformerMethodException e) { |
|
1403 |
//do nothing |
|
1404 |
} |
|
1405 |
if (areaLevel == null){ |
|
1406 |
String message = "Named area level '%s' not yet implemented."; |
|
1407 |
message = String.format(message, classValue); |
|
1408 |
fireWarningEvent(message, parentEvent, 6); |
|
1409 |
} |
|
1539 |
areaLevel = makeNamedAreaLevel(state, classValue, parentEvent); |
|
1410 | 1540 |
} |
1411 | 1541 |
|
1412 | 1542 |
String text = ""; |
... | ... | |
1783 | 1913 |
if (isSynonym){ |
1784 | 1914 |
Rank defaultRank = Rank.SPECIES(); //can be any |
1785 | 1915 |
name = createNameByCode(state, defaultRank); |
1786 |
name.setHomotypicalGroup(homotypicalGroup); |
|
1916 |
if (homotypicalGroup != null){ |
|
1917 |
name.setHomotypicalGroup(homotypicalGroup); |
|
1918 |
} |
|
1787 | 1919 |
SynonymRelationshipType synonymType = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(); |
1788 | 1920 |
if (taxon.getHomotypicGroup().equals(homotypicalGroup)){ |
1789 | 1921 |
synonymType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); |
... | ... | |
1865 | 1997 |
|
1866 | 1998 |
state.setCitation(true); |
1867 | 1999 |
boolean hasRefPart = false; |
1868 |
Reference reference = ReferenceFactory.newGeneric(); |
|
1869 | 2000 |
Map<String, String> refMap = new HashMap<String, String>(); |
1870 | 2001 |
while (reader.hasNext()){ |
1871 | 2002 |
XMLEvent next = readNoWhitespace(reader); |
1872 | 2003 |
if (isMyEndingElement(next, parentEvent)){ |
1873 | 2004 |
checkMandatoryElement(hasRefPart, parentEvent.asStartElement(), REF_PART); |
1874 |
reference = createReference(state, refMap, next); |
|
2005 |
Reference reference = createReference(state, refMap, next);
|
|
1875 | 2006 |
String microReference = refMap.get(DETAILS); |
1876 | 2007 |
doCitation(state, name, classValue, reference, microReference, parentEvent); |
1877 | 2008 |
state.setCitation(false); |
... | ... | |
1944 | 2075 |
reference = (Reference)article; |
1945 | 2076 |
|
1946 | 2077 |
}else{ |
2078 |
//TODO |
|
1947 | 2079 |
Reference bookOrPartOf = ReferenceFactory.newGeneric(); |
1948 | 2080 |
reference = bookOrPartOf; |
1949 | 2081 |
} |
... | ... | |
1953 | 2085 |
|
1954 | 2086 |
|
1955 | 2087 |
}else{ |
1956 |
reference = ReferenceFactory.newGeneric(); |
|
2088 |
if (volume != null || "journal".equalsIgnoreCase(type)){ |
|
2089 |
IArticle article = ReferenceFactory.newArticle(); |
|
2090 |
if (pubName != null){ |
|
2091 |
IJournal journal = ReferenceFactory.newJournal(); |
|
2092 |
journal.setTitle(pubName); |
|
2093 |
article.setInJournal(journal); |
|
2094 |
} |
|
2095 |
reference = (Reference)article; |
|
2096 |
|
|
2097 |
}else{ |
|
2098 |
Reference bookOrPartOf = ReferenceFactory.newGeneric(); |
|
2099 |
reference = bookOrPartOf; |
|
2100 |
} |
|
2101 |
|
|
1957 | 2102 |
//TODO type |
1958 | 2103 |
TeamOrPersonBase author = createAuthor(authorStr); |
1959 | 2104 |
reference.setAuthorTeam(author); |
... | ... | |
1966 | 2111 |
reference.setEditor(editors); |
1967 | 2112 |
|
1968 | 2113 |
if (pubName != null){ |
1969 |
Reference inReference = ReferenceFactory.newGeneric(); |
|
2114 |
Reference inReference; |
|
2115 |
if (reference.getType().equals(ReferenceType.Article)){ |
|
2116 |
inReference = ReferenceFactory.newJournal(); |
|
2117 |
}else{ |
|
2118 |
inReference = ReferenceFactory.newGeneric(); |
|
2119 |
} |
|
1970 | 2120 |
inReference.setTitle(pubName); |
1971 | 2121 |
reference.setInReference(inReference); |
1972 | 2122 |
} |
... | ... | |
2041 | 2191 |
if (isMyEndingElement(next, parentEvent)){ |
2042 | 2192 |
return; |
2043 | 2193 |
}else{ |
2044 |
if(isEndingElement(next, WRITER)){ |
|
2045 |
//NOT YET IMPLEMENTED |
|
2046 |
popUnimplemented(next.asEndElement()); |
|
2047 |
}else if(isEndingElement(next, DISTRIBUTION_LIST)){ |
|
2048 |
//NOT YET IMPLEMENTED |
|
2049 |
popUnimplemented(next.asEndElement()); |
|
2050 |
}else if(isEndingElement(next, HABITAT_LIST)){ |
|
2051 |
//NOT YET IMPLEMENTED |
|
2052 |
popUnimplemented(next.asEndElement()); |
|
2194 |
if(isEndingElement(next, DISTRIBUTION_LIST) || isEndingElement(next, HABITAT_LIST)){ |
|
2195 |
//only handle list elements |
|
2053 | 2196 |
}else if(isEndingElement(next, REFERENCES)){ |
2054 | 2197 |
//NOT YET IMPLEMENTED |
2055 | 2198 |
popUnimplemented(next.asEndElement()); |
... | ... | |
2070 | 2213 |
} |
2071 | 2214 |
} |
2072 | 2215 |
}else if(isStartingElement(next, WRITER)){ |
2073 |
handleNotYetImplementedElement(next); |
|
2216 |
WriterDataHolder writer = handleWriter(state, reader, next); |
|
2217 |
if (StringUtils.isNotBlank(writer.writer)){ |
|
2218 |
//TODO |
|
2219 |
Reference<?> ref = state.getConfig().getSourceReference(); |
|
2220 |
TaxonDescription description = getTaxonDescription(taxon, ref, false, true); |
|
2221 |
TextData featurePlaceholder = getFeaturePlaceholder(state, description, true); |
|
2222 |
featurePlaceholder.addAnnotation(writer.annotation); |
|
2223 |
registerFootnotes(state, featurePlaceholder, writer.footnotes); |
|
2224 |
}else{ |
|
2225 |
String message = "Writer element is empty"; |
|
2226 |
fireWarningEvent(message, next, 4); |
|
2227 |
} |
|
2228 |
}else if(isStartingElement(next, DISTRIBUTION_LOCALITY)){ |
|
2229 |
if (! feature.equals(Feature.DISTRIBUTION())){ |
|
2230 |
String message = "Distribution locality only allowed for feature of type 'distribution'"; |
|
2231 |
fireWarningEvent(message, next, 4); |
|
2232 |
} |
|
2233 |
handleDistributionLocality(state,reader, next); |
|
2074 | 2234 |
}else if(isStartingElement(next, DISTRIBUTION_LIST)){ |
2075 |
handleNotYetImplementedElement(next); |
|
2235 |
//only handle list elements |
|
2236 |
}else if(isStartingElement(next, HABITAT)){ |
|
2237 |
if (! (feature.equals(Feature.HABITAT())) || feature.equals(Feature.HABITAT_ECOLOGY()) || feature.equals(Feature.ECOLOGY()) ){ |
|
2238 |
String message = "Habitat only allowed for feature of type 'habitat','habitat ecology' or 'ecology'"; |
|
2239 |
fireWarningEvent(message, next, 4); |
|
2240 |
} |
|
2241 |
handleHabitat(state,reader, next); |
|
2076 | 2242 |
}else if(isStartingElement(next, HABITAT_LIST)){ |
2077 |
handleNotYetImplementedElement(next);
|
|
2243 |
//only handle list elements
|
|
2078 | 2244 |
}else if(isStartingElement(next, CHAR)){ |
2079 | 2245 |
TextData textData = handleChar (state,reader, next); |
2080 | 2246 |
taxonDescription.addElement(textData); |
... | ... | |
2130 | 2296 |
} |
2131 | 2297 |
|
2132 | 2298 |
|
2299 |
private void handleHabitat(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
2300 |
checkNoAttributes(parentEvent); |
|
2301 |
Taxon taxon = state.getCurrentTaxon(); |
|
2302 |
//TODO which ref to take? |
|
2303 |
Reference<?> ref = state.getConfig().getSourceReference(); |
|
2304 |
|
|
2305 |
String text = ""; |
|
2306 |
while (reader.hasNext()){ |
|
2307 |
XMLEvent next = readNoWhitespace(reader); |
|
2308 |
if(isMyEndingElement(next, parentEvent)){ |
|
2309 |
TaxonDescription description = getTaxonDescription(taxon, ref, false, true); |
|
2310 |
UUID uuidExtractedHabitat = MarkupTransformer.uuidExtractedHabitat; |
|
2311 |
Feature feature = getFeature(state, uuidExtractedHabitat, "Extracted Habitat", "An structured habitat that was extracted from a habitat text", "extr. habit.", null); |
|
2312 |
TextData habitat = TextData.NewInstance(feature); |
|
2313 |
habitat.putText(Language.DEFAULT(), text); |
|
2314 |
description.addElement(habitat); |
|
2315 |
|
|
2316 |
return; |
|
2317 |
}else if (next.isStartElement()){ |
|
2318 |
if (isStartingElement(next, ALTITUDE)){ |
|
2319 |
handleNotYetImplementedElement(next); |
|
2320 |
}else if (isStartingElement(next, LIFE_CYCLE_PERIODS)){ |
|
2321 |
handleNotYetImplementedElement(next); |
|
2322 |
}else { |
|
2323 |
handleUnexpectedStartElement(next.asStartElement()); |
|
2324 |
} |
|
2325 |
} else if (next.isCharacters()){ |
|
2326 |
text += next.asCharacters().getData(); |
|
2327 |
}else { |
|
2328 |
handleUnexpectedElement(next); |
|
2329 |
} |
|
2330 |
} |
|
2331 |
throw new IllegalStateException("<Habitat> has no closing tag"); |
|
2332 |
|
|
2333 |
|
|
2334 |
} |
|
2335 |
|
|
2336 |
|
|
2337 |
private void handleDistributionLocality(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
2338 |
String classValue =getClassOnlyAttribute(parentEvent); |
|
2339 |
|
|
2340 |
Taxon taxon = state.getCurrentTaxon(); |
|
2341 |
//TODO which ref to take? |
|
2342 |
Reference ref = state.getConfig().getSourceReference(); |
|
2343 |
|
|
2344 |
String text = ""; |
|
2345 |
while (reader.hasNext()){ |
|
2346 |
XMLEvent next = readNoWhitespace(reader); |
|
2347 |
if(isMyEndingElement(next, parentEvent)){ |
|
2348 |
if (StringUtils.isNotBlank(text)){ |
|
2349 |
TaxonDescription description = getTaxonDescription(taxon, ref, false, true); |
|
2350 |
NamedAreaLevel level = makeNamedAreaLevel(state, classValue, next); |
|
2351 |
NamedArea area = createArea(text, level, state); |
|
2352 |
|
|
2353 |
PresenceAbsenceTermBase<?> status = null; |
|
2354 |
Distribution distribution = Distribution.NewInstance(area, status); |
|
2355 |
description.addElement(distribution); |
|
2356 |
}else{ |
|
2357 |
String message = "Empty distribution locality"; |
|
2358 |
fireWarningEvent(message, next, 4); |
|
2359 |
} |
|
2360 |
return; |
|
2361 |
}else if (next.isStartElement()){ |
|
2362 |
if (isStartingElement(next, COORDINATES)){ |
|
2363 |
handleNotYetImplementedElement(next); |
|
2364 |
}else { |
|
2365 |
handleUnexpectedStartElement(next.asStartElement()); |
|
2366 |
} |
|
2367 |
} else if (next.isCharacters()){ |
|
2368 |
text += next.asCharacters().getData(); |
|
2369 |
}else { |
|
2370 |
handleUnexpectedEndElement(next.asEndElement()); |
|
2371 |
} |
|
2372 |
} |
|
2373 |
throw new IllegalStateException("<String> has no closing tag"); |
|
2374 |
} |
|
2375 |
|
|
2376 |
|
|
2377 |
/** |
|
2378 |
* @param state |
|
2379 |
* @param levelString |
|
2380 |
* @param next |
|
2381 |
* @return |
|
2382 |
*/ |
|
2383 |
private NamedAreaLevel makeNamedAreaLevel(MarkupImportState state, |
|
2384 |
String levelString, XMLEvent next) { |
|
2385 |
NamedAreaLevel level; |
|
2386 |
try { |
|
2387 |
level = state.getTransformer().getNamedAreaLevelByKey(levelString); |
|
2388 |
if (level == null){ |
|
2389 |
UUID levelUuid = state.getTransformer().getNamedAreaLevelUuid(levelString); |
|
2390 |
if (levelUuid == null){ |
|
2391 |
String message = "Unknown distribution locality class (named area level): %s. Create new level instead."; |
|
2392 |
message = String.format(message, levelString); |
|
2393 |
fireWarningEvent(message, next, 6); |
|
2394 |
} |
|
2395 |
level = getNamedAreaLevel(state, levelUuid, levelString, levelString, levelString, null); |
|
2396 |
} |
|
2397 |
} catch (UndefinedTransformerMethodException e) { |
|
2398 |
throw new RuntimeException(e); |
|
2399 |
} |
|
2400 |
return level; |
|
2401 |
} |
|
2133 | 2402 |
|
2134 | 2403 |
|
2135 | 2404 |
private String handleHeading(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
... | ... | |
2222 | 2491 |
} |
2223 | 2492 |
|
2224 | 2493 |
protected static final List<String> htmlList = Arrays.asList( |
2225 |
"sub", "sup", "ol", "ul", "i", "b", "table", "br"); |
|
2494 |
"sub", "sup", "ol", "ul", "li", "i", "b", "table", "br");
|
|
2226 | 2495 |
|
2227 | 2496 |
|
2228 | 2497 |
private boolean isHtml(XMLEvent event) { |
Also available in: Unified diff
Update on Markup import