From 56d4e021629f61bb50fa8a7f398c234f6750a73b Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Thu, 19 May 2016 12:07:43 +0200 Subject: [PATCH 1/3] Resolves #973 Add DOI field for English version of MS Office 2007 XML --- .../sf/jabref/exporter/MSBibExportFormat.java | 17 +++++++---------- .../net/sf/jabref/logic/msbib/MSBibEntry.java | 13 ++++++++++--- .../jabref/exporter/MsBibExportFormatTest2.bib | 5 +++-- .../jabref/exporter/MsBibExportFormatTest2.xml | 2 ++ .../jabref/exporter/MsBibExportFormatTest4.xml | 1 + 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java b/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java index 980a54f02f9..3ff579d185b 100644 --- a/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java +++ b/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java @@ -49,19 +49,16 @@ public void performExport(final BibDatabaseContext databaseContext, final String Objects.requireNonNull(databaseContext); Objects.requireNonNull(entries); - if (entries.isEmpty()) { // Only export if entries exist + if (entries.isEmpty()) { return; } - // forcing to use UTF8 output format for some problems with - // xml export in other encodings - SaveSession ss = new SaveSession(StandardCharsets.UTF_8, false); - MSBibDatabase md = new MSBibDatabase(databaseContext.getDatabase(), entries); - try (VerifyingWriter ps = ss.getWriter()) { - - // PS: DOES NOT SUPPORT EXPORTING ONLY A SET OF ENTRIES + // forcing to use UTF8 output format for some problems with xml export in other encodings + SaveSession session = new SaveSession(StandardCharsets.UTF_8, false); + MSBibDatabase msBibDatabase = new MSBibDatabase(databaseContext.getDatabase(), entries); + try (VerifyingWriter ps = session.getWriter()) { try { - DOMSource source = new DOMSource(md.getDOMrepresentation()); + DOMSource source = new DOMSource(msBibDatabase.getDOMrepresentation()); StreamResult result = new StreamResult(ps); Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); @@ -69,7 +66,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String } catch (TransformerException | IllegalArgumentException | TransformerFactoryConfigurationError e) { throw new Error(e); } - finalizeSaveSession(ss, new File(file)); + finalizeSaveSession(session, new File(file)); } catch (SaveException | IOException ex) { throw new IOException(ex.getMessage()); } diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java index 5a3ff1a5b23..26766f2b366 100644 --- a/src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java @@ -108,6 +108,7 @@ class MSBibEntry { private String thesisType; private String internetSiteTitle; private String dateAccessed; + private String doi; private String url; private String productionCompany; private String publicationTitle; @@ -267,6 +268,7 @@ private void populateFromXml(Element entry, String bcol) { dateAccessed = null; } + doi = getFromXml(bcol + "DOI", entry); url = getFromXml(bcol + "URL", entry); productionCompany = getFromXml(bcol + "ProductionCompany", entry); @@ -434,8 +436,11 @@ private void populateFromBibtex(BibEntry bibtex) { if (bibtex.hasField(MSBIB + "accessed")) { dateAccessed = bibtex.getField(MSBIB + "accessed"); } + if (bibtex.hasField("doi")) { + doi = bibtex.getField("doi"); + } if (bibtex.hasField("url")) { - url = bibtex.getField("url"); /* SM: 2010.10: lower case */ + url = bibtex.getField("url"); } if (bibtex.hasField(MSBIB + "productioncompany")) { productionCompany = bibtex.getField(MSBIB + "productioncompany"); @@ -539,14 +544,12 @@ private void populateFromBibtex(BibEntry bibtex) { // http://www.microsoft.com/globaldev/reference/lcid-all.mspx private int getLCID(String language) { // TODO: add language to LCID mapping - return 0; } // http://www.microsoft.com/globaldev/reference/lcid-all.mspx private String getLanguage(int LCID) { // TODO: add language to LCID mapping - return "english"; } @@ -797,6 +800,7 @@ public Element getDOMrepresentation(Document document) { /* SM 2010.10 added month export */ addField(document, msbibEntry, "Month", month); + addField(document, msbibEntry, "DOI", doi); addField(document, msbibEntry, "URL", url); addField(document, msbibEntry, "ProductionCompany", productionCompany); addField(document, msbibEntry, "PublicationTitle", publicationTitle); @@ -1007,6 +1011,9 @@ public BibEntry getBibtexRepresentation() { if (dateAccessed != null) { hm.put(MSBIB + "accessed", dateAccessed); } + if (doi != null) { + hm.put("doi", doi); + } if (url != null) { hm.put("url", url); } diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.bib b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.bib index ef5214ba7a3..5b771c4c591 100644 --- a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.bib +++ b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.bib @@ -1,14 +1,15 @@ @phdthesis{2002, title = {Agile Entwicklung Web-basierter Systeme}, year = {2002}, - type = {type}, + type = {type}, number = {3}, - address = {a}, + address = {a}, journal = {Wirtschaftsinformatik}, keywords = {software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development}, language = {english}, pages = {237--248}, publisher = {Gabler Verlag}, + doi = {10.1007/BF03250842}, url = {http://dx.doi.org/10.1007/BF03250842}, volume = {44}, } diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.xml b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.xml index 99b753ce23a..2f47866a2f5 100644 --- a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.xml +++ b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.xml @@ -10,11 +10,13 @@ 237-248 44 + DOI: 10.1007/BF03250842 Gabler Verlag a Wirtschaftsinformatik 3 type +10.1007/BF03250842 http://dx.doi.org/10.1007/BF03250842 software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.xml b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.xml index d35b5b92ddc..9719402e2cf 100644 --- a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.xml +++ b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.xml @@ -14,6 +14,7 @@ Gabler Verlag Wirtschaftsinformatik 3 +10.1000/182 http://dx.doi.org/10.1007/BF03250842 software development processes; agile software development environments; time-to-market; Extreme Programming; Crystal methods family; Adaptive Software Development From a088e766429069573d446925b1cbf7bdb59200f6 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Thu, 19 May 2016 12:10:19 +0200 Subject: [PATCH 2/3] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ccf27f0709..788191bda48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Fixed sourceforge bug 1000: shorttitleINI can generate the initials of the shorttitle - Fixed [#1394](https://github.com/JabRef/jabref/issues/1394): Personal journal abbrevations could not be saved - Fixed [#1400](https://github.com/JabRef/jabref/issues/1400): Detect path constructs wrong path for Windows +- Fixed [#973](https://github.com/JabRef/jabref/issues/973): Add additional DOI field for English version of MS Office 2007 XML ### Removed - Removed possibility to export entries/databases to an `.sql` file, as the logic cannot easily use the correct escape logic From 7f4cc28d747e025dbeaa94ee68a2aee9bcb5d400 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Thu, 19 May 2016 13:34:16 +0200 Subject: [PATCH 3/3] Fix tests --- .../resources/net/sf/jabref/exporter/test.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/resources/net/sf/jabref/exporter/test.xml b/src/test/resources/net/sf/jabref/exporter/test.xml index fd9958930af..3cbf4c63a0f 100644 --- a/src/test/resources/net/sf/jabref/exporter/test.xml +++ b/src/test/resources/net/sf/jabref/exporter/test.xml @@ -17,6 +17,7 @@ 3075-3080 +http://doi.acm.org/10.1145/1358628.1358810 ISBN: 978-1-60558-012-X DOI: http://doi.acm.org/10.1145/1358628.1358810 ACM New York, NY, USA @@ -40,6 +41,7 @@ 13-14 34 +http://doi.acm.org/10.1145/820127.820136 ISSN: 0097-8418 DOI: http://doi.acm.org/10.1145/820127.820136 ACM New York, NY, USA @@ -72,6 +74,7 @@ 10-12 12 +http://dx.doi.org/10.1109/MIC.2008.67 ISSN: 1089-7801 DOI: http://dx.doi.org/10.1109/MIC.2008.67 IEEE Educational Activities Department Piscataway @@ -126,6 +129,7 @@ 25-31 2 +http://dx.doi.org/10.1109/MSP.2004.81 ISSN: 1540-7993 DOI: http://dx.doi.org/10.1109/MSP.2004.81 IEEE Educational Activities Department Piscataway @@ -151,6 +155,7 @@ 357-367 9 +http://dx.doi.org/10.1007/s00779-005-0347-6 ISSN: 1617-4909 DOI: http://dx.doi.org/10.1007/s00779-005-0347-6 Springer-Verlag London @@ -192,6 +197,7 @@ 11-18 +http://doi.acm.org/10.1145/1137627.1137631 ISBN: 1-59593-411-1 DOI: http://doi.acm.org/10.1145/1137627.1137631 ACM New York, NY, USA @@ -219,6 +225,7 @@ 529-530 +http://doi.acm.org/10.1145/1233341.1233448 ISBN: 978-1-59593-629-5 DOI: http://doi.acm.org/10.1145/1233341.1233448 ACM New York, NY, USA @@ -257,6 +264,7 @@ 25-31 2 +http://dx.doi.org/10.1109/MSP.2004.81 ISSN: 1540-7993 DOI: http://dx.doi.org/10.1109/MSP.2004.81 IEEE Educational Activities Department Piscataway @@ -286,6 +294,7 @@ 199-203 +http://doi.acm.org/10.1145/1132736.1132768 ISBN: 1-59593-350-6 DOI: http://doi.acm.org/10.1145/1132736.1132768 ACM New York, NY, USA @@ -350,6 +359,7 @@ 429-432 +http://doi.acm.org/10.1145/1182475.1182529 ISBN: 1-59593-325-5 DOI: http://doi.acm.org/10.1145/1182475.1182529 ACM New York, NY, USA @@ -378,6 +388,7 @@ 51-58 +http://doi.acm.org/10.1145/1137627.1137636 ISBN: 1-59593-411-1 DOI: http://doi.acm.org/10.1145/1137627.1137636 ACM New York, NY, USA @@ -406,6 +417,7 @@ 90-94 +http://doi.acm.org/10.1145/1314276.1314293 ISBN: 978-1-59593-884-8 DOI: http://doi.acm.org/10.1145/1314276.1314293 ACM New York, NY, USA @@ -438,6 +450,7 @@ 1-2 +http://doi.acm.org/10.1145/1137627.1137628 ISBN: 1-59593-411-1 DOI: http://doi.acm.org/10.1145/1137627.1137628 ACM New York, NY, USA @@ -494,6 +507,7 @@ 25-34 +http://doi.acm.org/10.1145/1073001.1073004 ISBN: 1-59593-178-3 DOI: http://doi.acm.org/10.1145/1073001.1073004 ACM New York, NY, USA @@ -526,6 +540,7 @@ 27-34 +http://doi.acm.org/10.1145/1137627.1137633 ISBN: 1-59593-411-1 DOI: http://doi.acm.org/10.1145/1137627.1137633 ACM New York, NY, USA @@ -576,6 +591,7 @@ 1-7 +http://doi.acm.org/10.1145/1143120.1143122 ISBN: 1-59593-448-0 DOI: http://doi.acm.org/10.1145/1143120.1143122 ACM New York, NY, USA