Revision 47fdce61
Added by Andreas Müller over 12 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmImportBase.java | ||
---|---|---|
34 | 34 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
35 | 35 |
import eu.etaxonomy.cdm.model.common.DescriptionElementSource; |
36 | 36 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
37 |
import eu.etaxonomy.cdm.model.common.Figure; |
|
37 | 38 |
import eu.etaxonomy.cdm.model.common.IOriginalSource; |
38 | 39 |
import eu.etaxonomy.cdm.model.common.ISourceable; |
39 | 40 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
... | ... | |
74 | 75 |
|
75 | 76 |
protected static final boolean CREATE = true; |
76 | 77 |
protected static final boolean IMAGE_GALLERY = true; |
78 |
protected static final boolean READ_MEDIA_DATA = true; |
|
77 | 79 |
|
78 | 80 |
public static final UUID uuidUserDefinedNamedAreaLevelVocabulary = UUID.fromString("255144da-8d95-457e-a327-9752a8f85e5a"); |
79 | 81 |
public static final UUID uuidUserDefinedNamedAreaVocabulary = UUID.fromString("b2238399-a3af-4f6d-b7eb-ff5d0899bf1b"); |
... | ... | |
765 | 767 |
|
766 | 768 |
|
767 | 769 |
/** |
768 |
* @param derivedUnitFacade |
|
769 |
* @param multimediaObject |
|
770 |
* Creates |
|
771 |
* @param uriString |
|
772 |
* @param readDataFromUrl |
|
773 |
* @see #READ_MEDIA_DATA |
|
774 |
* @return |
|
770 | 775 |
* @throws MalformedURLException |
771 | 776 |
*/ |
772 |
protected Media getImageMedia(String multimediaObject, boolean readDataFromUrl) throws MalformedURLException {
|
|
773 |
if( multimediaObject == null){
|
|
777 |
protected Media getImageMedia(String uriString, boolean readMediaData, boolean isFigure) throws MalformedURLException {
|
|
778 |
if( uriString == null){
|
|
774 | 779 |
return null; |
775 | 780 |
} else { |
776 | 781 |
ImageInfo imageInfo = null; |
777 | 782 |
URI uri; |
778 | 783 |
try { |
779 |
uri = new URI(multimediaObject);
|
|
784 |
uri = new URI(uriString);
|
|
780 | 785 |
try { |
781 |
if (readDataFromUrl){
|
|
786 |
if (readMediaData){
|
|
782 | 787 |
imageInfo = ImageInfo.NewInstance(uri, 0); |
783 | 788 |
} |
784 | 789 |
} catch (Exception e) { |
785 | 790 |
String message = "An error occurred when trying to read image meta data: " + e.getMessage(); |
786 | 791 |
logger.warn(message); |
792 |
fireWarningEvent(message, "unknown location", 2, 0); |
|
787 | 793 |
} |
788 | 794 |
ImageFile imageFile = ImageFile.NewInstance(uri, null, imageInfo); |
789 | 795 |
MediaRepresentation representation = MediaRepresentation.NewInstance(); |
... | ... | |
791 | 797 |
representation.setMimeType(imageInfo.getMimeType()); |
792 | 798 |
} |
793 | 799 |
representation.addRepresentationPart(imageFile); |
794 |
Media media = Media.NewInstance(); |
|
800 |
Media media = isFigure ? Figure.NewInstance() : Media.NewInstance();
|
|
795 | 801 |
media.addRepresentation(representation); |
796 | 802 |
return media; |
797 | 803 |
} catch (URISyntaxException e1) { |
798 |
String message = "An URISyntaxException occurred when trying to create uri from multimedia objcet string: " + multimediaObject;
|
|
804 |
String message = "An URISyntaxException occurred when trying to create uri from multimedia objcet string: " + uriString;
|
|
799 | 805 |
logger.warn(message); |
806 |
fireWarningEvent(message, "unknown location", 4, 0); |
|
800 | 807 |
return null; |
801 | 808 |
} |
802 | 809 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImport.java | ||
---|---|---|
313 | 313 |
td.addElement(mediaHolder); |
314 | 314 |
} |
315 | 315 |
try { |
316 |
Media media = getImageMedia(imageUrl, true);
|
|
316 |
Media media = getImageMedia(imageUrl, READ_MEDIA_DATA, false);
|
|
317 | 317 |
mediaHolder.addMedia(media); |
318 | 318 |
} catch (MalformedURLException e) { |
319 | 319 |
logger.warn("Can't add media: " + e.getMessage()); |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/MarkupDocumentImport.java | ||
---|---|---|
1171 | 1171 |
throw new IllegalStateException("<writer> has no end tag"); |
1172 | 1172 |
} |
1173 | 1173 |
|
1174 |
private void registerFootnotes(MarkupImportState state, |
|
1175 |
AnnotatableEntity entity, List<FootnoteDataHolder> footnotes) { |
|
1174 |
private void registerFootnotes(MarkupImportState state, AnnotatableEntity entity, List<FootnoteDataHolder> footnotes) { |
|
1176 | 1175 |
for (FootnoteDataHolder footNote : footnotes) { |
1177 | 1176 |
registerFootnoteDemand(state, entity, footNote); |
1178 | 1177 |
} |
1179 | 1178 |
} |
1180 | 1179 |
|
1181 |
private void registerGivenFootnote(MarkupImportState state, |
|
1182 |
FootnoteDataHolder footnote) { |
|
1180 |
private void registerGivenFootnote(MarkupImportState state, FootnoteDataHolder footnote) { |
|
1183 | 1181 |
state.registerFootnote(footnote); |
1184 | 1182 |
Set<AnnotatableEntity> demands = state.getFootnoteDemands(footnote.id); |
1185 | 1183 |
if (demands != null) { |
... | ... | |
1189 | 1187 |
} |
1190 | 1188 |
} |
1191 | 1189 |
|
1192 |
private void registerGivenFigure(MarkupImportState state, String id, |
|
1193 |
Media figure) { |
|
1190 |
private void registerGivenFigure(MarkupImportState state, String id, Media figure) { |
|
1194 | 1191 |
state.registerFigure(id, figure); |
1195 | 1192 |
Set<AnnotatableEntity> demands = state.getFigureDemands(id); |
1196 | 1193 |
if (demands != null) { |
... | ... | |
1200 | 1197 |
} |
1201 | 1198 |
} |
1202 | 1199 |
|
1203 |
private void registerFootnoteDemand(MarkupImportState state, |
|
1204 |
AnnotatableEntity entity, FootnoteDataHolder footnote) { |
|
1200 |
private void registerFootnoteDemand(MarkupImportState state, AnnotatableEntity entity, FootnoteDataHolder footnote) { |
|
1205 | 1201 |
FootnoteDataHolder existingFootnote = state.getFootnote(footnote.ref); |
1206 | 1202 |
if (existingFootnote != null) { |
1207 | 1203 |
attachFootnote(state, entity, existingFootnote); |
1208 | 1204 |
} else { |
1209 |
Set<AnnotatableEntity> demands = state |
|
1210 |
.getFootnoteDemands(footnote.ref); |
|
1205 |
Set<AnnotatableEntity> demands = state.getFootnoteDemands(footnote.ref); |
|
1211 | 1206 |
if (demands == null) { |
1212 | 1207 |
demands = new HashSet<AnnotatableEntity>(); |
1213 | 1208 |
state.putFootnoteDemands(footnote.ref, demands); |
... | ... | |
1216 | 1211 |
} |
1217 | 1212 |
} |
1218 | 1213 |
|
1219 |
private void registerFigureDemand(MarkupImportState state, |
|
1220 |
AnnotatableEntity entity, String figureRef) { |
|
1214 |
private void registerFigureDemand(MarkupImportState state, AnnotatableEntity entity, String figureRef) { |
|
1221 | 1215 |
Media existingFigure = state.getFigure(figureRef); |
1222 | 1216 |
if (existingFigure != null) { |
1223 | 1217 |
attachFigure(state, entity, existingFigure); |
... | ... | |
1231 | 1225 |
} |
1232 | 1226 |
} |
1233 | 1227 |
|
1234 |
private void attachFootnote(MarkupImportState state, |
|
1235 |
AnnotatableEntity entity, FootnoteDataHolder footnote) { |
|
1236 |
AnnotationType annotationType = this.getAnnotationType(state, |
|
1237 |
MarkupTransformer.uuidFootnote, "Footnote", |
|
1238 |
"An e-flora footnote", "fn", null); |
|
1228 |
private void attachFootnote(MarkupImportState state, AnnotatableEntity entity, FootnoteDataHolder footnote) { |
|
1229 |
AnnotationType annotationType = this.getAnnotationType(state, MarkupTransformer.uuidFootnote, "Footnote", "An e-flora footnote", "fn", null); |
|
1239 | 1230 |
Annotation annotation = Annotation.NewInstance(footnote.string, |
1240 | 1231 |
annotationType, Language.DEFAULT()); |
1241 | 1232 |
// TODO transient objects |
... | ... | |
1263 | 1254 |
save(entity, state); |
1264 | 1255 |
} |
1265 | 1256 |
|
1266 |
private void handleFigure(MarkupImportState state, XMLEventReader reader, |
|
1267 |
XMLEvent parentEvent) throws XMLStreamException { |
|
1257 |
private void handleFigure(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
1268 | 1258 |
// FigureDataHolder result = new FigureDataHolder(); |
1269 | 1259 |
|
1270 | 1260 |
Map<String, Attribute> attributes = getAttributes(parentEvent); |
... | ... | |
1280 | 1270 |
while (reader.hasNext()) { |
1281 | 1271 |
XMLEvent next = readNoWhitespace(reader); |
1282 | 1272 |
if (isMyEndingElement(next, parentEvent)) { |
1283 |
makeFigure(state, id, type, urlString, legendString, |
|
1284 |
titleString, numString, next); |
|
1273 |
makeFigure(state, id, type, urlString, legendString, titleString, numString, next); |
|
1285 | 1274 |
return; |
1286 | 1275 |
} else if (isStartingElement(next, FIGURE_LEGEND)) { |
1287 | 1276 |
// TODO same as figurestring ? |
... | ... | |
1312 | 1301 |
* @param numString |
1313 | 1302 |
* @param next |
1314 | 1303 |
*/ |
1315 |
private void makeFigure(MarkupImportState state, String id, String type, |
|
1316 |
String urlString, String legendString, String titleString, |
|
1317 |
String numString, XMLEvent next) { |
|
1304 |
private void makeFigure(MarkupImportState state, String id, String type, String urlString, |
|
1305 |
String legendString, String titleString, String numString, XMLEvent next) { |
|
1318 | 1306 |
Media media = null; |
1307 |
boolean isFigure = false; |
|
1319 | 1308 |
try { |
1320 |
URL url = new URL(urlString);
|
|
1309 |
//TODO maybe everything is a figure as it is all taken from a book
|
|
1321 | 1310 |
if ("lineart".equals(type)) { |
1322 |
media = Figure.NewInstance(url.toURI(), null, null,
|
|
1323 |
null);
|
|
1311 |
isFigure = true;
|
|
1312 |
// media = Figure.NewInstance(url.toURI(), null, null, null);
|
|
1324 | 1313 |
} else if (type == null || "photo".equals(type) |
1325 | 1314 |
|| "signature".equals(type) |
1326 | 1315 |
|| "others".equals(type)) { |
1327 |
media = Media.NewInstance(url.toURI(), null, null, null); |
|
1328 | 1316 |
} else { |
1329 | 1317 |
String message = "Unknown figure type '%s'"; |
1330 | 1318 |
message = String.format(message, type); |
1331 |
// TODO location |
|
1332 |
fireWarningEvent(message, "-", 2); |
|
1333 |
media = Media.NewInstance(url.toURI(), null, null, null); |
|
1319 |
fireWarningEvent(message, next, 2); |
|
1334 | 1320 |
} |
1321 |
media = getImageMedia(urlString, READ_MEDIA_DATA, isFigure); |
|
1322 |
|
|
1335 | 1323 |
// title |
1336 | 1324 |
if (StringUtils.isNotBlank(titleString)) { |
1337 | 1325 |
media.putTitle(Language.DEFAULT(), titleString); |
... | ... | |
1343 | 1331 |
if (StringUtils.isNotBlank(numString)) { |
1344 | 1332 |
// TODO use concrete source (e.g. DAPHNIPHYLLACEAE in FM |
1345 | 1333 |
// vol.13) |
1346 |
Reference citation = state.getConfig().getSourceReference(); |
|
1334 |
Reference<?> citation = state.getConfig().getSourceReference();
|
|
1347 | 1335 |
media.addSource(numString, "num", citation, null); |
1348 | 1336 |
// TODO name used in source if available |
1349 | 1337 |
} |
... | ... | |
1362 | 1350 |
String message = "Media uri has incorrect syntax: %s"; |
1363 | 1351 |
message = String.format(message, urlString); |
1364 | 1352 |
fireWarningEvent(message, next, 4); |
1365 |
} catch (URISyntaxException e) { |
|
1366 |
String message = "Media uri has incorrect syntax: %s"; |
|
1367 |
message = String.format(message, urlString); |
|
1368 |
fireWarningEvent(message, next, 4); |
|
1353 |
// } catch (URISyntaxException e) {
|
|
1354 |
// String message = "Media uri has incorrect syntax: %s";
|
|
1355 |
// message = String.format(message, urlString);
|
|
1356 |
// fireWarningEvent(message, next, 4);
|
|
1369 | 1357 |
} |
1370 | 1358 |
|
1371 | 1359 |
registerGivenFigure(state, id, media); |
... | ... | |
1525 | 1513 |
return result; |
1526 | 1514 |
} |
1527 | 1515 |
|
1528 |
private String handleInLineReferences(MarkupImportState state, |
|
1529 |
XMLEventReader reader, XMLEvent parentEvent) |
|
1530 |
throws XMLStreamException { |
|
1516 |
private String handleInLineReferences(MarkupImportState state,XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException { |
|
1531 | 1517 |
checkNoAttributes(parentEvent); |
1532 | 1518 |
|
1533 | 1519 |
boolean hasReference = false; |
... | ... | |
1535 | 1521 |
while (reader.hasNext()) { |
1536 | 1522 |
XMLEvent next = readNoWhitespace(reader); |
1537 | 1523 |
if (isMyEndingElement(next, parentEvent)) { |
1538 |
checkMandatoryElement(hasReference, |
|
1539 |
parentEvent.asStartElement(), REFERENCE); |
|
1524 |
checkMandatoryElement(hasReference, parentEvent.asStartElement(), REFERENCE); |
|
1540 | 1525 |
return text; |
1541 | 1526 |
} else if (isStartingElement(next, REFERENCE)) { |
1542 | 1527 |
text += handleInLineReference(state, reader, next); |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java | ||
---|---|---|
129 | 129 |
|
130 | 130 |
// Reference sec = Database.NewInstance(); |
131 | 131 |
// sec.setTitleCache("XML DATA"); |
132 |
Reference sec = config.getTaxonReference(); |
|
132 |
Reference<?> sec = config.getTaxonReference();
|
|
133 | 133 |
|
134 | 134 |
//create facade |
135 | 135 |
DerivedUnitFacade derivedUnitFacade = getFacade(dataHolder); |
... | ... | |
181 | 181 |
// //add Multimedia URLs |
182 | 182 |
if(dataHolder.multimediaObjects.size() > 0){ |
183 | 183 |
for (String multimediaObject : dataHolder.multimediaObjects){ |
184 |
Media media = getImageMedia(multimediaObject, true);
|
|
184 |
Media media = getImageMedia(multimediaObject, READ_MEDIA_DATA, false);
|
|
185 | 185 |
derivedUnitFacade.addDerivedUnitMedia(media); |
186 | 186 |
} |
187 | 187 |
} |
... | ... | |
1033 | 1033 |
* @param derivedThing |
1034 | 1034 |
* @param sec |
1035 | 1035 |
*/ |
1036 |
private void handleIdentifications(Abcd206ImportConfigurator config, DerivedUnitFacade facade, Reference sec, Abcd206DataHolder dataHolder){ |
|
1036 |
private void handleIdentifications(Abcd206ImportConfigurator config, DerivedUnitFacade facade, Reference<?> sec, Abcd206DataHolder dataHolder){
|
|
1037 | 1037 |
NonViralName<?> taxonName = null; |
1038 | 1038 |
String fullScientificNameString; |
1039 | 1039 |
Taxon taxon = null; |
... | ... | |
1107 | 1107 |
|
1108 | 1108 |
for (String strReference : dataHolder.referenceList){ |
1109 | 1109 |
|
1110 |
Reference reference = ReferenceFactory.newGeneric(); |
|
1110 |
Reference<?> reference = ReferenceFactory.newGeneric();
|
|
1111 | 1111 |
reference.setTitleCache(strReference, true); |
1112 | 1112 |
determinationEvent.addReference(reference); |
1113 | 1113 |
} |
... | ... | |
1133 | 1133 |
IndividualsAssociation individualsAssociation = IndividualsAssociation.NewInstance(); |
1134 | 1134 |
individualsAssociation.setAssociatedSpecimenOrObservation(facade.innerDerivedUnit()); |
1135 | 1135 |
individualsAssociation.setFeature(Feature.INDIVIDUALS_ASSOCIATION()); |
1136 |
for(Reference citation : determinationEvent.getReferences()){ |
|
1136 |
for(Reference<?> citation : determinationEvent.getReferences()){
|
|
1137 | 1137 |
individualsAssociation.addSource(DescriptionElementSource.NewInstance(null, null, citation, null)); |
1138 | 1138 |
} |
1139 | 1139 |
taxonDescription.addElement(individualsAssociation); |
... | ... | |
1157 | 1157 |
if (dataHolder.nomenclatureCode.toString().equals("Botanical")){ |
1158 | 1158 |
taxonName = (BotanicalName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICBN,null); |
1159 | 1159 |
if (taxonName.hasProblem()){ |
1160 |
problem=true;;
|
|
1160 |
problem=true; |
|
1161 | 1161 |
} |
1162 | 1162 |
} |
1163 | 1163 |
if (dataHolder.nomenclatureCode.toString().equals("Bacterial")){ |
Also available in: Unified diff
refactor getImageMedia() to support figures