Mercurial > hg > openmind
comparison src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java @ 103:1149eb948036
add isodate tag to XML dump format 4.9.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 14 Nov 2018 18:31:55 +0100 |
parents | 734c0d8c7369 |
children | 93c7dbfaf062 |
comparison
equal
deleted
inserted
replaced
102:68e759210b53 | 103:1149eb948036 |
---|---|
13 import javax.xml.stream.XMLStreamException; | 13 import javax.xml.stream.XMLStreamException; |
14 import javax.xml.stream.XMLStreamWriter; | 14 import javax.xml.stream.XMLStreamWriter; |
15 | 15 |
16 import org.apache.commons.lang.StringUtils; | 16 import org.apache.commons.lang.StringUtils; |
17 import org.apache.log4j.Logger; | 17 import org.apache.log4j.Logger; |
18 import org.joda.time.DateTime; | |
19 import org.joda.time.format.DateTimeFormatter; | |
20 import org.joda.time.format.ISODateTimeFormat; | |
21 import org.json.JSONException; | |
22 import org.json.JSONObject; | |
18 import org.mpi.openmind.repository.bo.Attribute; | 23 import org.mpi.openmind.repository.bo.Attribute; |
19 import org.mpi.openmind.repository.bo.Entity; | 24 import org.mpi.openmind.repository.bo.Entity; |
20 import org.mpi.openmind.repository.bo.Node; | 25 import org.mpi.openmind.repository.bo.Node; |
21 import org.mpi.openmind.repository.bo.Relation; | 26 import org.mpi.openmind.repository.bo.Relation; |
22 import org.mpi.openmind.repository.services.PersistenceService; | 27 import org.mpi.openmind.repository.services.PersistenceService; |
30 * @author jurzua, casties | 35 * @author jurzua, casties |
31 * | 36 * |
32 */ | 37 */ |
33 public class OM4StreamWriter { | 38 public class OM4StreamWriter { |
34 | 39 |
35 protected static final String FORMAT_VERSION = "4.8"; | 40 protected static final String FORMAT_VERSION = "4.9"; |
36 | 41 |
37 private static Logger logger = Logger.getLogger(OM4StreamWriter.class); | 42 private static Logger logger = Logger.getLogger(OM4StreamWriter.class); |
38 | 43 |
39 private static final int itemsPerPage = 500; | 44 private static final int itemsPerPage = 500; |
40 | 45 |
42 public static boolean includeNormalizations = true; | 47 public static boolean includeNormalizations = true; |
43 | 48 |
44 /** key for entity count in attribute counts map */ | 49 /** key for entity count in attribute counts map */ |
45 private static final String ENT_KEY = "<entity-count>"; | 50 private static final String ENT_KEY = "<entity-count>"; |
46 | 51 |
52 /** formatter for isodate tag */ | |
53 public static DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); | |
54 | |
47 /** | 55 /** |
48 * Return the object's string representation or "null" if its null. | 56 * Return the object's string representation or "null" if its null. |
49 * | 57 * |
50 * @param s | 58 * @param s |
51 * @return | 59 * @return |
387 // write normalized value | 395 // write normalized value |
388 writer.writeStartElement(XMLUtil.NORMALIZED); | 396 writer.writeStartElement(XMLUtil.NORMALIZED); |
389 writer.writeCharacters(nov); | 397 writer.writeCharacters(nov); |
390 writer.writeEndElement(); | 398 writer.writeEndElement(); |
391 } | 399 } |
400 // convert date JSON into additional isodate | |
401 if (ov.startsWith("{")) { | |
402 try { | |
403 JSONObject json = new JSONObject(ov); | |
404 JSONObject date = null; | |
405 if (json.has("date")) { | |
406 date = json.getJSONObject("date"); | |
407 } else if (json.has("from")) { | |
408 date = json.getJSONObject("from"); | |
409 } | |
410 if (date != null) { | |
411 int year = date.getInt("year"); | |
412 int month = date.getInt("month"); | |
413 int day = date.getInt("dayOfMonth"); | |
414 DateTime dt = new DateTime(year, month, day, 0, 0); | |
415 writer.writeStartElement(XMLUtil.ISODATE); | |
416 writer.writeCharacters(dateFormatter.print(dt)); | |
417 writer.writeEndElement(); | |
418 } | |
419 } catch (JSONException e) { | |
420 // maybe not JSON... | |
421 } | |
422 } | |
392 } | 423 } |
393 | 424 |
394 writer.writeEndElement(); | 425 writer.writeEndElement(); |
395 } | 426 } |
396 | 427 |