Mercurial > hg > openmind
comparison src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java @ 106:93c7dbfaf062
add bibid tag to xml export of endnote-id attributes.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 26 Apr 2019 18:12:23 +0200 |
parents | 1149eb948036 |
children | 484be3266e54 |
comparison
equal
deleted
inserted
replaced
105:94d354107165 | 106:93c7dbfaf062 |
---|---|
6 import java.text.DecimalFormat; | 6 import java.text.DecimalFormat; |
7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
8 import java.util.HashMap; | 8 import java.util.HashMap; |
9 import java.util.List; | 9 import java.util.List; |
10 import java.util.Map; | 10 import java.util.Map; |
11 import java.util.regex.Matcher; | |
12 import java.util.regex.Pattern; | |
11 | 13 |
12 import javax.xml.stream.XMLOutputFactory; | 14 import javax.xml.stream.XMLOutputFactory; |
13 import javax.xml.stream.XMLStreamException; | 15 import javax.xml.stream.XMLStreamException; |
14 import javax.xml.stream.XMLStreamWriter; | 16 import javax.xml.stream.XMLStreamWriter; |
15 | 17 |
35 * @author jurzua, casties | 37 * @author jurzua, casties |
36 * | 38 * |
37 */ | 39 */ |
38 public class OM4StreamWriter { | 40 public class OM4StreamWriter { |
39 | 41 |
40 protected static final String FORMAT_VERSION = "4.9"; | 42 protected static final String FORMAT_VERSION = "4.10"; |
41 | 43 |
42 private static Logger logger = Logger.getLogger(OM4StreamWriter.class); | 44 private static Logger logger = Logger.getLogger(OM4StreamWriter.class); |
43 | 45 |
44 private static final int itemsPerPage = 500; | 46 private static final int itemsPerPage = 500; |
45 | 47 |
49 /** key for entity count in attribute counts map */ | 51 /** key for entity count in attribute counts map */ |
50 private static final String ENT_KEY = "<entity-count>"; | 52 private static final String ENT_KEY = "<entity-count>"; |
51 | 53 |
52 /** formatter for isodate tag */ | 54 /** formatter for isodate tag */ |
53 public static DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); | 55 public static DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); |
56 | |
57 /** pattern for bibid in endnote-id attribute */ | |
58 public static final Pattern bibidPattern = Pattern.compile("#(\\d+)"); | |
54 | 59 |
55 /** | 60 /** |
56 * Return the object's string representation or "null" if its null. | 61 * Return the object's string representation or "null" if its null. |
57 * | 62 * |
58 * @param s | 63 * @param s |
366 | 371 |
367 | 372 |
368 private static void writeAttribute(Attribute att, XMLStreamWriter writer, boolean includeNorm) throws XMLStreamException { | 373 private static void writeAttribute(Attribute att, XMLStreamWriter writer, boolean includeNorm) throws XMLStreamException { |
369 writer.writeStartElement(XMLUtil.ATTRIBUTE); | 374 writer.writeStartElement(XMLUtil.ATTRIBUTE); |
370 | 375 |
376 String name = att.getName(); | |
371 /* | 377 /* |
372 * write XML attributes | 378 * write XML attributes |
373 */ | 379 */ |
374 writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, defaultString(att.getName())); | 380 writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, defaultString(name)); |
375 writer.writeAttribute(XMLUtil.ID, defaultString(att.getId())); | 381 writer.writeAttribute(XMLUtil.ID, defaultString(att.getId())); |
376 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(att.getRowId())); | 382 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(att.getRowId())); |
377 writer.writeAttribute(XMLUtil.CONTENT_TYPE, defaultString(att.getContentType())); | 383 writer.writeAttribute(XMLUtil.CONTENT_TYPE, defaultString(att.getContentType())); |
378 writer.writeAttribute(XMLUtil.VERSION, defaultString(att.getVersion())); | 384 writer.writeAttribute(XMLUtil.VERSION, defaultString(att.getVersion())); |
379 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(att.getModificationTime())); | 385 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(att.getModificationTime())); |
395 // write normalized value | 401 // write normalized value |
396 writer.writeStartElement(XMLUtil.NORMALIZED); | 402 writer.writeStartElement(XMLUtil.NORMALIZED); |
397 writer.writeCharacters(nov); | 403 writer.writeCharacters(nov); |
398 writer.writeEndElement(); | 404 writer.writeEndElement(); |
399 } | 405 } |
400 // convert date JSON into additional isodate | 406 boolean processed = false; |
401 if (ov.startsWith("{")) { | 407 // convert endnote-id into additional bibid element |
408 if (!processed && name.equals("endnote-id")) { | |
409 Matcher bibidMatch = bibidPattern.matcher(ov); | |
410 if (bibidMatch.find()) { | |
411 String bibid = bibidMatch.group(1); | |
412 writer.writeStartElement(XMLUtil.BIBID); | |
413 writer.writeCharacters(bibid); | |
414 writer.writeEndElement(); | |
415 processed = true; | |
416 } | |
417 } | |
418 // convert any date JSON into additional isodate element | |
419 if (!processed && ov.startsWith("{")) { | |
402 try { | 420 try { |
403 JSONObject json = new JSONObject(ov); | 421 JSONObject json = new JSONObject(ov); |
404 JSONObject date = null; | 422 JSONObject date = null; |
405 if (json.has("date")) { | 423 if (json.has("date")) { |
406 date = json.getJSONObject("date"); | 424 date = json.getJSONObject("date"); |
412 int month = date.getInt("month"); | 430 int month = date.getInt("month"); |
413 int day = date.getInt("dayOfMonth"); | 431 int day = date.getInt("dayOfMonth"); |
414 DateTime dt = new DateTime(year, month, day, 0, 0); | 432 DateTime dt = new DateTime(year, month, day, 0, 0); |
415 writer.writeStartElement(XMLUtil.ISODATE); | 433 writer.writeStartElement(XMLUtil.ISODATE); |
416 writer.writeCharacters(dateFormatter.print(dt)); | 434 writer.writeCharacters(dateFormatter.print(dt)); |
417 writer.writeEndElement(); | 435 writer.writeEndElement(); |
436 processed = true; | |
418 } | 437 } |
419 } catch (JSONException e) { | 438 } catch (JSONException e) { |
420 // maybe not JSON... | 439 // maybe not JSON... |
421 } | 440 } |
422 } | 441 } |