Mercurial > hg > openmind
changeset 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 | 94d354107165 |
children | 742347ef8410 |
files | src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java src/main/java/org/mpi/openmind/repository/utils/XMLUtil.java |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java Fri Apr 26 17:04:07 2019 +0200 +++ b/src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java Fri Apr 26 18:12:23 2019 +0200 @@ -8,6 +8,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; @@ -37,7 +39,7 @@ */ public class OM4StreamWriter { - protected static final String FORMAT_VERSION = "4.9"; + protected static final String FORMAT_VERSION = "4.10"; private static Logger logger = Logger.getLogger(OM4StreamWriter.class); @@ -52,6 +54,9 @@ /** formatter for isodate tag */ public static DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); + /** pattern for bibid in endnote-id attribute */ + public static final Pattern bibidPattern = Pattern.compile("#(\\d+)"); + /** * Return the object's string representation or "null" if its null. * @@ -368,10 +373,11 @@ private static void writeAttribute(Attribute att, XMLStreamWriter writer, boolean includeNorm) throws XMLStreamException { writer.writeStartElement(XMLUtil.ATTRIBUTE); + String name = att.getName(); /* * write XML attributes */ - writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, defaultString(att.getName())); + writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, defaultString(name)); writer.writeAttribute(XMLUtil.ID, defaultString(att.getId())); writer.writeAttribute(XMLUtil.ROW_ID, defaultString(att.getRowId())); writer.writeAttribute(XMLUtil.CONTENT_TYPE, defaultString(att.getContentType())); @@ -397,8 +403,20 @@ writer.writeCharacters(nov); writer.writeEndElement(); } - // convert date JSON into additional isodate - if (ov.startsWith("{")) { + boolean processed = false; + // convert endnote-id into additional bibid element + if (!processed && name.equals("endnote-id")) { + Matcher bibidMatch = bibidPattern.matcher(ov); + if (bibidMatch.find()) { + String bibid = bibidMatch.group(1); + writer.writeStartElement(XMLUtil.BIBID); + writer.writeCharacters(bibid); + writer.writeEndElement(); + processed = true; + } + } + // convert any date JSON into additional isodate element + if (!processed && ov.startsWith("{")) { try { JSONObject json = new JSONObject(ov); JSONObject date = null; @@ -414,7 +432,8 @@ DateTime dt = new DateTime(year, month, day, 0, 0); writer.writeStartElement(XMLUtil.ISODATE); writer.writeCharacters(dateFormatter.print(dt)); - writer.writeEndElement(); + writer.writeEndElement(); + processed = true; } } catch (JSONException e) { // maybe not JSON...
--- a/src/main/java/org/mpi/openmind/repository/utils/XMLUtil.java Fri Apr 26 17:04:07 2019 +0200 +++ b/src/main/java/org/mpi/openmind/repository/utils/XMLUtil.java Fri Apr 26 18:12:23 2019 +0200 @@ -94,6 +94,7 @@ public static String INSERT = "insert"; public static String ISODATE = "isodate"; + public static String BIBID = "bibid"; public static Node getNodeByName(NodeList nodeList, String name){ for(int i=0; i < nodeList.getLength(); i++){