Revision 47fdce61
Added by Andreas Müller over 12 years ago
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); |
Also available in: Unified diff
refactor getImageMedia() to support figures