From a6769dd81782a0010681fdd14622c1fcc43519fb Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Fri, 3 Jun 2016 12:10:28 +0200 Subject: [PATCH] Remove umlauts from word export title #421 (#1465) * Split MsBib functionality into Converter classes * Put all mappings inside a mapping class * Fixes #421 Remove LaTeX commands from all BibTeX fields when exporting to Word Bibliography --- CHANGELOG.md | 1 + .../sf/jabref/exporter/MSBibExportFormat.java | 2 +- .../format/LatexToUnicodeFormatter.java | 1 + .../net/sf/jabref/logic/mods/PageNumbers.java | 18 +- .../jabref/logic/msbib/BibTeXConverter.java | 112 ++ .../sf/jabref/logic/msbib/MSBibConverter.java | 143 +++ .../sf/jabref/logic/msbib/MSBibDatabase.java | 57 +- .../net/sf/jabref/logic/msbib/MSBibEntry.java | 1052 +++-------------- .../sf/jabref/logic/msbib/MSBibEntryType.java | 30 + .../sf/jabref/logic/msbib/MSBibMapping.java | 130 ++ .../exporter/MSBibExportFormatTestFiles.java | 5 +- .../exporter/MsBibExportFormatTest.java | 25 - .../fileformat/MsBibImporterTestfiles.java | 2 +- .../NormalizePagesFormatterTest.java | 3 +- .../exporter/MsBibExportFormatUmlauts.bib | 3 + .../exporter/MsBibExportFormatUmlauts.xml | 10 + .../net/sf/jabref/exporter/MsBibLCID.bib | 4 + .../net/sf/jabref/exporter/MsBibLCID.xml | 9 + .../resources/net/sf/jabref/exporter/test.xml | 601 ---------- .../fileformat/MsBibImporterTest1.xml | 1 - .../fileformat/MsBibImporterTest2.bib | 2 + .../fileformat/MsBibImporterTest2.xml | 4 +- .../fileformat/MsBibImporterTest3.xml | 3 +- .../fileformat/MsBibImporterTest4.xml | 3 +- .../fileformat/MsBibImporterTest5.xml | 3 +- .../fileformat/MsBibImporterTest6.xml | 3 +- .../jabref/importer/fileformat/MsBibLCID.bib | 4 + .../jabref/importer/fileformat/MsBibLCID.xml | 7 + 28 files changed, 644 insertions(+), 1594 deletions(-) create mode 100644 src/main/java/net/sf/jabref/logic/msbib/BibTeXConverter.java create mode 100644 src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java create mode 100644 src/main/java/net/sf/jabref/logic/msbib/MSBibEntryType.java create mode 100644 src/main/java/net/sf/jabref/logic/msbib/MSBibMapping.java create mode 100644 src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.bib create mode 100644 src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.xml create mode 100644 src/test/resources/net/sf/jabref/exporter/MsBibLCID.bib create mode 100644 src/test/resources/net/sf/jabref/exporter/MsBibLCID.xml delete mode 100644 src/test/resources/net/sf/jabref/exporter/test.xml create mode 100644 src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.bib create mode 100644 src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 270a522dc4f..1c649f8abff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Fixed [#1457](https://github.com/JabRef/jabref/issues/1457): Support multiple words inside LaTeX commands to RTF export - Entries retain their groupmembership when undoing their cut/deletion - Fixed [#1450](https://github.com/JabRef/jabref/issues/1450): EntryEditor is restored in the correct size after preference changes +- Fixed [#421](https://github.com/JabRef/jabref/issues/421): Remove LaTeX commands from all BibTeX fields when exporting to Word Bibliography ### Removed - Removed possibility to export entries/databases to an `.sql` file, as the logic cannot easily use the correct escape logic diff --git a/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java b/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java index 3ff579d185b..4f4c265f6a5 100644 --- a/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java +++ b/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java @@ -58,7 +58,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String try (VerifyingWriter ps = session.getWriter()) { try { - DOMSource source = new DOMSource(msBibDatabase.getDOMrepresentation()); + DOMSource source = new DOMSource(msBibDatabase.getDOM()); StreamResult result = new StreamResult(ps); Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); diff --git a/src/main/java/net/sf/jabref/logic/layout/format/LatexToUnicodeFormatter.java b/src/main/java/net/sf/jabref/logic/layout/format/LatexToUnicodeFormatter.java index 99c56812c97..abe2818fc41 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/LatexToUnicodeFormatter.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/LatexToUnicodeFormatter.java @@ -48,6 +48,7 @@ public String format(String inField) { return ""; } int i; + // TODO: document what does this do String field = inField.replaceAll("&|\\\\&", "&").replaceAll("[\\n]{1,}", "

").replace("\\$", "$") // Replace \$ with $ .replaceAll("\\$([^\\$]*)\\$", "\\{$1\\}"); diff --git a/src/main/java/net/sf/jabref/logic/mods/PageNumbers.java b/src/main/java/net/sf/jabref/logic/mods/PageNumbers.java index 912a0f7e18d..35e9e1aad4a 100644 --- a/src/main/java/net/sf/jabref/logic/mods/PageNumbers.java +++ b/src/main/java/net/sf/jabref/logic/mods/PageNumbers.java @@ -22,30 +22,24 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -/** - * @author Michael Wrighton - * @author S M Mahbub Murshed - * - */ public class PageNumbers { - private String freeform; private int start; private int end; private static final Pattern PAGE_PATTERN = Pattern.compile("\\s*(\\d+)\\s*-{1,2}\\s*(\\d+)\\s*"); - public PageNumbers(String s) { - parsePageNums(s); + public PageNumbers(String pages) { + parsePageNums(pages); } - private void parsePageNums(String numberString) { - Matcher matcher = PAGE_PATTERN.matcher(numberString); + private void parsePageNums(String pages) { + Matcher matcher = PAGE_PATTERN.matcher(pages); if (matcher.matches()) { start = Integer.parseInt(matcher.group(1)); end = Integer.parseInt(matcher.group(2)); } else { - freeform = numberString; + freeform = pages; } } @@ -75,7 +69,7 @@ public String toString(String separator) { @Override public String toString() { - return toString("--"); + return toString("-"); } } diff --git a/src/main/java/net/sf/jabref/logic/msbib/BibTeXConverter.java b/src/main/java/net/sf/jabref/logic/msbib/BibTeXConverter.java new file mode 100644 index 00000000000..7965ac43375 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/msbib/BibTeXConverter.java @@ -0,0 +1,112 @@ +package net.sf.jabref.logic.msbib; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import net.sf.jabref.importer.fileformat.ImportFormat; +import net.sf.jabref.logic.mods.PersonName; +import net.sf.jabref.model.entry.BibEntry; + +public class BibTeXConverter { + private static final String MSBIB_PREFIX = "msbib-"; + + public static BibEntry convert(MSBibEntry entry) { + BibEntry result; + Map fieldValues = new HashMap<>(); + + if (entry.getCiteKey() == null) { + result = new BibEntry(ImportFormat.DEFAULT_BIBTEXENTRY_ID, MSBibMapping.getBibTeXEntryType(entry.getType())); + } else { + // TODO: the cite key should not be the ID?! + // id assumes an existing database so don't + result = new BibEntry(entry.getCiteKey(), MSBibMapping.getBibTeXEntryType(entry.getType())); + } + + // add String fields + for (Map.Entry field : entry.fields.entrySet()) { + String msField = field.getKey(); + String value = field.getValue(); + + if (value != null && MSBibMapping.getBibTeXField(msField) != null) { + fieldValues.put(MSBibMapping.getBibTeXField(msField), value); + } + } + + // Value must be converted + if (fieldValues.containsKey("language")) { + int lcid = Integer.valueOf(fieldValues.get("language")); + fieldValues.put("language", MSBibMapping.getLanguage(lcid)); + } + + addAuthor(fieldValues, "author", entry.authors); + addAuthor(fieldValues, MSBIB_PREFIX + "bookauthor", entry.bookAuthors); + addAuthor(fieldValues, "editor", entry.editors); + addAuthor(fieldValues, MSBIB_PREFIX + "translator", entry.translators); + addAuthor(fieldValues, MSBIB_PREFIX + "producername", entry.producerNames); + addAuthor(fieldValues, MSBIB_PREFIX + "composer", entry.composers); + addAuthor(fieldValues, MSBIB_PREFIX + "conductor", entry.conductors); + addAuthor(fieldValues, MSBIB_PREFIX + "performer", entry.performers); + addAuthor(fieldValues, MSBIB_PREFIX + "writer", entry.writers); + addAuthor(fieldValues, MSBIB_PREFIX + "director", entry.directors); + addAuthor(fieldValues, MSBIB_PREFIX + "compiler", entry.compilers); + addAuthor(fieldValues, MSBIB_PREFIX + "interviewer", entry.interviewers); + addAuthor(fieldValues, MSBIB_PREFIX + "interviewee", entry.interviewees); + addAuthor(fieldValues, MSBIB_PREFIX + "inventor", entry.inventors); + addAuthor(fieldValues, MSBIB_PREFIX + "counsel", entry.counsels); + + if (entry.pages != null) { + fieldValues.put("pages", entry.pages.toString("--")); + } + + parseStandardNumber(entry.standardNumber, fieldValues); + + if (entry.address != null) { + fieldValues.put("address", entry.address); + } + // TODO: ConferenceName is saved as booktitle when converting from MSBIB to BibTeX + if (entry.conferenceName != null) { + fieldValues.put("organization", entry.conferenceName); + } + + if (entry.dateAccessed != null) { + fieldValues.put(MSBIB_PREFIX + "accessed", entry.dateAccessed); + } + + // set all fields + result.setField(fieldValues); + + return result; + } + + private static void addAuthor(Map map, String type, List authors) { + if (authors == null) { + return; + } + String allAuthors = authors.stream().map(PersonName::getFullname).collect(Collectors.joining(" and ")); + + map.put(type, allAuthors); + } + + private static void parseSingleStandardNumber(String type, String bibtype, String standardNum, Map map) { + Pattern pattern = Pattern.compile(':' + type + ":(.[^:]+)"); + Matcher matcher = pattern.matcher(standardNum); + if (matcher.matches()) { + map.put(bibtype, matcher.group(1)); + } + } + + private static void parseStandardNumber(String standardNum, Map map) { + if (standardNum == null) { + return; + } + parseSingleStandardNumber("ISBN", "isbn", standardNum, map); + parseSingleStandardNumber("ISSN", "issn", standardNum, map); + parseSingleStandardNumber("LCCN", "lccn", standardNum, map); + parseSingleStandardNumber("MRN", "mrnumber", standardNum, map); + parseSingleStandardNumber("DOI", "doi", standardNum, map); + } +} diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java new file mode 100644 index 00000000000..9579d748deb --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java @@ -0,0 +1,143 @@ +package net.sf.jabref.logic.msbib; + +import java.util.ArrayList; +import java.util.List; + +import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter; +import net.sf.jabref.logic.layout.format.RemoveBrackets; +import net.sf.jabref.logic.mods.PageNumbers; +import net.sf.jabref.logic.mods.PersonName; +import net.sf.jabref.model.entry.BibEntry; + +public class MSBibConverter { + private static final String MSBIB_PREFIX = "msbib-"; + private static final String BIBTEX_PREFIX = "BIBTEX_"; + + public static MSBibEntry convert(BibEntry entry) { + MSBibEntry result = new MSBibEntry(); + + // memorize original type + result.fields.put(BIBTEX_PREFIX + "Entry", entry.getType()); + // define new type + String msbibType = result.fields.put("SourceType", MSBibMapping.getMSBibEntryType(entry.getType()).name()); + + for (String field : entry.getFieldNames()) { + // clean field + String unicodeField = removeLaTeX(entry.getField(field)); + + if (MSBibMapping.getMSBibField(field) != null) { + result.fields.put(MSBibMapping.getMSBibField(field), unicodeField); + } + } + + // Duplicate: also added as BookTitle + if (entry.hasField("booktitle")) { + result.conferenceName = entry.getField("booktitle"); + } + + if (entry.hasField("pages")) { + result.pages = new PageNumbers(entry.getField("pages")); + } + + if (entry.hasField(MSBIB_PREFIX + "accessed")) { + result.dateAccessed = entry.getField(MSBIB_PREFIX + "accessed"); + } + + // TODO: currently this can never happen + if ("SoundRecording".equals(msbibType) && (entry.hasField("title"))) { + result.albumTitle = entry.getField("title"); + } + + // TODO: currently this can never happen + if ("Interview".equals(msbibType) && (entry.hasField("title"))) { + result.broadcastTitle = entry.getField("title"); + } + + // Value must be converted + if (entry.hasField("language")) { + result.fields.put("LCID", String.valueOf(MSBibMapping.getLCID(entry.getField("language")))); + } + + result.standardNumber = ""; + if (entry.hasField("isbn")) { + result.standardNumber += " ISBN: " + entry.getField("isbn"); + } + if (entry.hasField("issn")) { + result.standardNumber += " ISSN: " + entry.getField("issn"); + } + if (entry.hasField("lccn")) { + result.standardNumber += " LCCN: " + entry.getField("lccn"); + } + if (entry.hasField("mrnumber")) { + result.standardNumber += " MRN: " + entry.getField("mrnumber"); + } + if (entry.hasField("doi")) { + result.standardNumber += " DOI: " + entry.getField("doi"); + } + if (result.standardNumber.isEmpty()) { + result.standardNumber = null; + } + + if (entry.hasField("address")) { + result.address = entry.getField("address"); + } + + if (entry.hasField("type")) { + result.thesisType = entry.getField("type"); + } else { + if ("techreport".equalsIgnoreCase(entry.getType())) { + result.thesisType = "Tech. rep."; + } else if ("mastersthesis".equalsIgnoreCase(entry.getType())) { + result.thesisType = "Master's thesis"; + } else if ("phdthesis".equalsIgnoreCase(entry.getType())) { + result.thesisType = "Ph.D. dissertation"; + } else if ("unpublished".equalsIgnoreCase(entry.getType())) { + result.thesisType = "unpublished"; + } + } + + // TODO: currently this can never happen + if (("InternetSite".equals(msbibType) || "DocumentFromInternetSite".equals(msbibType)) + && (entry.hasField("title"))) { + result.internetSiteTitle = entry.getField("title"); + } + + // TODO: currently only Misc can happen + if (("ElectronicSource".equals(msbibType) || "Art".equals(msbibType) || "Misc".equals(msbibType)) + && (entry.hasField("title"))) { + result.publicationTitle = entry.getField("title"); + } + + if (entry.hasField("author")) { + result.authors = getAuthors(entry.getField("author")); + } + if (entry.hasField("editor")) { + result.editors = getAuthors(entry.getField("editor")); + } + + return result; + } + + private static List getAuthors(String authors) { + List result = new ArrayList<>(); + + // TODO: case-insensitive?! + if (authors.contains(" and ")) { + String[] names = authors.split(" and "); + for (String name : names) { + result.add(new PersonName(name)); + } + } else { + result.add(new PersonName(authors)); + } + return result; + } + + private static String removeLaTeX(String text) { + // TODO: just use latex free version everywhere in the future + String result = new RemoveBrackets().format(text); + result = new LatexToUnicodeFormatter().format(result); + + return result; + } +} diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibDatabase.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibDatabase.java index 91bfb3e90a1..790026f36d2 100644 --- a/src/main/java/net/sf/jabref/logic/msbib/MSBibDatabase.java +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibDatabase.java @@ -47,13 +47,16 @@ public class MSBibDatabase { private static final Log LOGGER = LogFactory.getLog(MSBibDatabase.class); + public static final String NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/bibliography"; + public static final String PREFIX = "b:"; + private Set entries; public MSBibDatabase() { - // maybe make this sorted later... entries = new HashSet<>(); } + // TODO: why an additonal entry list? entries are included inside database! public MSBibDatabase(BibDatabase database, List entries) { if (entries == null) { addEntries(database.getEntries()); @@ -66,30 +69,28 @@ public List importEntries(BufferedReader reader) { entries = new HashSet<>(); Document inputDocument; try { - DocumentBuilder documentBuilder = DocumentBuilderFactory. - newInstance(). - newDocumentBuilder(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder documentBuilder = factory.newDocumentBuilder(); inputDocument = documentBuilder.parse(new InputSource(reader)); } catch (ParserConfigurationException | SAXException | IOException e) { LOGGER.warn("Could not parse document", e); return Collections.emptyList(); } - String bcol = "b:"; - NodeList rootList = inputDocument.getElementsByTagName("b:Sources"); + NodeList rootList = inputDocument.getElementsByTagNameNS("*", "Sources"); if (rootList.getLength() == 0) { - rootList = inputDocument.getElementsByTagName("Sources"); - bcol = ""; + rootList = inputDocument.getElementsByTagNameNS("*", "Sources"); } List bibitems = new ArrayList<>(); if (rootList.getLength() == 0) { return bibitems; } - NodeList sourceList = ((Element) rootList.item(0)).getElementsByTagName(bcol + "Source"); + NodeList sourceList = ((Element) rootList.item(0)).getElementsByTagNameNS("*", "Source"); for (int i = 0; i < sourceList.getLength(); i++) { - MSBibEntry entry = new MSBibEntry((Element) sourceList.item(i), bcol); + MSBibEntry entry = new MSBibEntry((Element) sourceList.item(i)); entries.add(entry); - bibitems.add(entry.getBibtexRepresentation()); + bibitems.add(BibTeXConverter.convert(entry)); } return bibitems; @@ -98,32 +99,34 @@ public List importEntries(BufferedReader reader) { private void addEntries(List entriesToAdd) { entries = new HashSet<>(); for (BibEntry entry : entriesToAdd) { - MSBibEntry newMods = new MSBibEntry(entry); + MSBibEntry newMods = MSBibConverter.convert(entry); entries.add(newMods); } } - public Document getDOMrepresentation() { - Document result = null; + public Document getDOM() { + Document document = null; try { - DocumentBuilder documentBuilder = DocumentBuilderFactory. - newInstance(). - newDocumentBuilder(); - result = documentBuilder.newDocument(); - Element msbibCollection = result.createElement("b:Sources"); - msbibCollection.setAttribute("SelectedStyle", ""); - msbibCollection.setAttribute("xmlns", "http://schemas.openxmlformats.org/officeDocument/2006/bibliography"); - msbibCollection.setAttribute("xmlns:b", "http://schemas.openxmlformats.org/officeDocument/2006/bibliography"); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder documentBuilder = factory.newDocumentBuilder(); + document = documentBuilder.newDocument(); + + Element rootNode = document.createElementNS(NAMESPACE, PREFIX + "Sources"); + rootNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", NAMESPACE); + rootNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + PREFIX.substring(0, PREFIX.length() - 1), NAMESPACE); + rootNode.setAttribute("SelectedStyle", ""); for (MSBibEntry entry : entries) { - Node node = entry.getDOMrepresentation(result); - msbibCollection.appendChild(node); + Node node = entry.getDOM(document); + rootNode.appendChild(node); } - result.appendChild(msbibCollection); + document.appendChild(rootNode); } catch (ParserConfigurationException e) { - LOGGER.warn("Could not build document", e); + LOGGER.warn("Could not build XML document", e); } - return result; + + return document; } } 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 26766f2b366..0bce537df15 100644 --- a/src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java @@ -21,130 +21,54 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; -import net.sf.jabref.importer.fileformat.ImportFormat; - -import net.sf.jabref.logic.layout.format.RemoveBrackets; import net.sf.jabref.logic.mods.PageNumbers; import net.sf.jabref.logic.mods.PersonName; import net.sf.jabref.logic.util.strings.StringUtil; -import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.model.entry.BibtexEntryTypes; -import net.sf.jabref.model.entry.EntryType; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * Date: May 15, 2007; May 03, 2007 - *

- * History - * May 03, 2007 - Added export functionality - * May 15, 2007 - Added import functionality - * May 16, 2007 - Changed all interger entries to strings, - * except LCID which must be an integer. - * To avoid exception during integer parsing - * the exception is caught and LCID is set to zero. - * Jan 06, 2012 - Changed the XML element ConferenceName to present - * the Booktitle instead of the organization field content + * MSBib entry representation * - * @author S M Mahbub Murshed (udvranto@yahoo.com) - * @version 2.0.0 * @see ms office 2007 bibliography format compared to bibtex * @see deciphering ms office 2007 bibliography format - * See http://www.ecma-international.org/publications/standards/Ecma-376.htm + * @see ECMA Standard */ class MSBibEntry { - - private String sourceType = "Misc"; - private String bibTexEntry; - - private String tag; - private static final String GUID = null; - private int LCID = -1; - - private List authors; - private List bookAuthors; - private List editors; - private List translators; - private List producerNames; - private List composers; - private List conductors; - private List performers; - private List writers; - private List directors; - private List compilers; - private List interviewers; - private List interviewees; - private List inventors; - private List counsels; - - private String title; - private String year; - private String month; - private String day; - - private String shortTitle; - private String comments; - - private PageNumbers pages; - private String volume; - private String numberOfVolumes; - private String edition; - private String standardNumber; - private String publisher; - - private String address; - private String bookTitle; - private String chapterNumber; - private String journalName; - private String issue; - private String periodicalTitle; - private String conferenceName; - private String department; - private String institution; - private String thesisType; - private String internetSiteTitle; - private String dateAccessed; - private String doi; - private String url; - private String productionCompany; - private String publicationTitle; - private String medium; - private String albumTitle; - private String recordingNumber; - private String theater; - private String distributor; - private String broadcastTitle; - private String broadcaster; - private String station; - private String type; - private String patentNumber; - private String court; - private String reporter; - private String caseNumber; - private String abbreviatedCaseNumber; - private String bibTexSeries; - private String bibTexAbstract; - private String bibTexKeyWords; - private String bibTexCrossRef; - private String bibTex_HowPublished; - private String bibTexAffiliation; - private String bibTexContents; - private String bibTexCopyright; - private String bibTexPrice; - private String bibTexSize; - - /* SM 2010.10 intype, paper support */ - private String bibTexInType; - private String bibTexPaper; - - private static final String BIBTEX = "BIBTEX_"; - private static final String MSBIB = "msbib-"; - - private static final String B_COLON = "b:"; + // MSBib fields and values + public Map fields = new HashMap<>(); + + public List authors; + public List bookAuthors; + public List editors; + public List translators; + public List producerNames; + public List composers; + public List conductors; + public List performers; + public List writers; + public List directors; + public List compilers; + public List interviewers; + public List interviewees; + public List inventors; + public List counsels; + + public PageNumbers pages; + + public String standardNumber; + public String address; + public String conferenceName; + public String thesisType; + public String internetSiteTitle; + public String dateAccessed; + public String publicationTitle; + public String albumTitle; + public String broadcastTitle; // reduced subset, supports only "CITY , STATE, COUNTRY" // \b(\w+)\s?[,]?\s?(\w+)\s?[,]?\s?(\w+)\b @@ -156,69 +80,55 @@ class MSBibEntry { // (\d{1,2})\s?[.,-/]\s?(\d{1,2})\s?[.,-/]\s?(\d{2,4}) // 1-2 DIGITS SPACE SEPERATOR SPACE 1-2 DIGITS SPACE SEPERATOR SPACE 2-4 DIGITS // tested using http://www.javaregex.com/test.html - private static final Pattern DATE_PATTERN = Pattern - .compile("(\\d{1,2})\\s*[.,-/]\\s*(\\d{1,2})\\s*[.,-/]\\s*(\\d{2,4})"); + private static final Pattern DATE_PATTERN = Pattern.compile("(\\d{1,2})\\s*[.,-/]\\s*(\\d{1,2})\\s*[.,-/]\\s*(\\d{2,4})"); + public MSBibEntry() { - public MSBibEntry(BibEntry bibtex) { - populateFromBibtex(bibtex); } - public MSBibEntry(Element entry, String bcol) { - populateFromXml(entry, bcol); + public MSBibEntry(Element entry) { + populateFromXml(entry); } - private String getFromXml(String name, Element entry) { + public String getType() { + return fields.get("SourceType"); + } + + public String getCiteKey() { + return fields.get("Tag"); + } + + private String getXmlElementTextContent(String name, Element entry) { String value = null; - NodeList nodeLst = entry.getElementsByTagName(name); + NodeList nodeLst = entry.getElementsByTagNameNS("*", name); if (nodeLst.getLength() > 0) { value = nodeLst.item(0).getTextContent(); } return value; } - private void populateFromXml(Element entry, String bcol) { - String temp; - - sourceType = getFromXml(bcol + "SourceType", entry); + private void populateFromXml(Element entry) { + for (int i = 0; i < entry.getChildNodes().getLength(); i++) { + Node node = entry.getChildNodes().item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + String key = node.getLocalName(); + String value = node.getTextContent(); - tag = getFromXml(bcol + "Tag", entry); - - temp = getFromXml(bcol + "LCID", entry); - if (temp != null) { - try { - LCID = Integer.parseInt(temp); - } catch (NumberFormatException e) { - LCID = -1; + fields.put(key, value); } } - title = getFromXml(bcol + "Title", entry); - year = getFromXml(bcol + "Year", entry); - month = getFromXml(bcol + "Month", entry); - day = getFromXml(bcol + "Day", entry); - - shortTitle = getFromXml(bcol + "ShortTitle", entry); - comments = getFromXml(bcol + "Comments", entry); - - temp = getFromXml(bcol + "Pages", entry); + String temp = getXmlElementTextContent("Pages", entry); if (temp != null) { pages = new PageNumbers(temp); } - volume = getFromXml(bcol + "Volume", entry); - - numberOfVolumes = getFromXml(bcol + "NumberVolumes", entry); - - edition = getFromXml(bcol + "Edition", entry); - - standardNumber = getFromXml(bcol + "StandardNumber", entry); + standardNumber = getXmlElementTextContent("StandardNumber", entry); + conferenceName = getXmlElementTextContent("ConferenceName", entry); - publisher = getFromXml(bcol + "Publisher", entry); - - String city = getFromXml(bcol + "City", entry); - String state = getFromXml(bcol + "StateProvince", entry); - String country = getFromXml(bcol + "CountryRegion", entry); + String city = getXmlElementTextContent("City", entry); + String state = getXmlElementTextContent("StateProvince", entry); + String country = getXmlElementTextContent("CountryRegion", entry); StringBuilder addressBuffer = new StringBuilder(); if (city != null) { addressBuffer.append(city).append(", "); @@ -234,25 +144,10 @@ private void populateFromXml(Element entry, String bcol) { address = null; } - bookTitle = getFromXml(bcol + "BookTitle", entry); - - chapterNumber = getFromXml(bcol + "ChapterNumber", entry); - - journalName = getFromXml(bcol + "JournalName", entry); - - issue = getFromXml(bcol + "Issue", entry); - - periodicalTitle = getFromXml(bcol + "PeriodicalTitle", entry); - - conferenceName = getFromXml(bcol + "ConferenceName", entry); - department = getFromXml(bcol + "Department", entry); - institution = getFromXml(bcol + "Institution", entry); - - thesisType = getFromXml(bcol + "ThesisType", entry); - internetSiteTitle = getFromXml(bcol + "InternetSiteTitle", entry); - String month = getFromXml(bcol + "MonthAccessed", entry); - String day = getFromXml(bcol + "DayAccessed", entry); - String year = getFromXml(bcol + "YearAccessed", entry); + internetSiteTitle = getXmlElementTextContent("InternetSiteTitle", entry); + String month = getXmlElementTextContent("MonthAccessed", entry); + String day = getXmlElementTextContent("DayAccessed", entry); + String year = getXmlElementTextContent("YearAccessed", entry); dateAccessed = ""; if (month != null) { dateAccessed += month + ' '; @@ -268,311 +163,50 @@ private void populateFromXml(Element entry, String bcol) { dateAccessed = null; } - doi = getFromXml(bcol + "DOI", entry); - url = getFromXml(bcol + "URL", entry); - productionCompany = getFromXml(bcol + "ProductionCompany", entry); - - publicationTitle = getFromXml(bcol + "PublicationTitle", entry); - medium = getFromXml(bcol + "Medium", entry); - albumTitle = getFromXml(bcol + "AlbumTitle", entry); - recordingNumber = getFromXml(bcol + "RecordingNumber", entry); - theater = getFromXml(bcol + "Theater", entry); - distributor = getFromXml(bcol + "Distributor", entry); - broadcastTitle = getFromXml(bcol + "BroadcastTitle", entry); - broadcaster = getFromXml(bcol + "Broadcaster", entry); - station = getFromXml(bcol + "Station", entry); - type = getFromXml(bcol + "Type", entry); - patentNumber = getFromXml(bcol + "PatentNumber", entry); - court = getFromXml(bcol + "Court", entry); - reporter = getFromXml(bcol + "Reporter", entry); - caseNumber = getFromXml(bcol + "CaseNumber", entry); - abbreviatedCaseNumber = getFromXml(bcol + "AbbreviatedCaseNumber", entry); - bibTexSeries = getFromXml(bcol + BIBTEX + "Series", entry); - bibTexAbstract = getFromXml(bcol + BIBTEX + "Abstract", entry); - bibTexKeyWords = getFromXml(bcol + BIBTEX + "KeyWords", entry); - bibTexCrossRef = getFromXml(bcol + BIBTEX + "CrossRef", entry); - bibTex_HowPublished = getFromXml(bcol + BIBTEX + "HowPublished", entry); - bibTexAffiliation = getFromXml(bcol + BIBTEX + "Affiliation", entry); - bibTexContents = getFromXml(bcol + BIBTEX + "Contents", entry); - bibTexCopyright = getFromXml(bcol + BIBTEX + "Copyright", entry); - bibTexPrice = getFromXml(bcol + BIBTEX + "Price", entry); - bibTexSize = getFromXml(bcol + BIBTEX + "Size", entry); - - NodeList nodeLst = entry.getElementsByTagName(bcol + "Author"); + NodeList nodeLst = entry.getElementsByTagNameNS("*", "Author"); if (nodeLst.getLength() > 0) { - getAuthors((Element) nodeLst.item(0), bcol); - } - } - - private void populateFromBibtex(BibEntry bibtex) { - - sourceType = getMSBibSourceType(bibtex); - - if (bibtex.hasField(BibEntry.KEY_FIELD)) { - tag = bibtex.getCiteKey(); - } - - if (bibtex.hasField("language")) { - LCID = getLCID(bibtex.getField("language")); - } - - if (bibtex.hasField("title")) { - String temp = bibtex.getField("title"); - // TODO: remove LaTex syntax - title = new RemoveBrackets().format(temp); - } - if (bibtex.hasField("year")) { - year = bibtex.getField("year"); - } - if (bibtex.hasField("month")) { - month = bibtex.getField("month"); - } - if (bibtex.hasField(MSBIB + "day")) { - day = bibtex.getField(MSBIB + "day"); - } - - if (bibtex.hasField(MSBIB + "shorttitle")) { - shortTitle = bibtex.getField(MSBIB + "shorttitle"); - } - if (bibtex.hasField("note")) { - comments = bibtex.getField("note"); - } - - if (bibtex.hasField("pages")) { - pages = new PageNumbers(bibtex.getField("pages")); - } - - if (bibtex.hasField("volume")) { - volume = bibtex.getField("volume"); - } - - if (bibtex.hasField(MSBIB + "numberofvolume")) { - numberOfVolumes = bibtex.getField(MSBIB + "numberofvolume"); - } - - if (bibtex.hasField("edition")) { - edition = bibtex.getField("edition"); - } - - standardNumber = ""; - if (bibtex.hasField("isbn")) { - standardNumber += " ISBN: " + bibtex.getField("isbn"); /* SM: 2010.10: lower case */ - } - if (bibtex.hasField("issn")) { - standardNumber += " ISSN: " + bibtex.getField("issn"); /* SM: 2010.10: lower case */ - } - if (bibtex.hasField("lccn")) { - standardNumber += " LCCN: " + bibtex.getField("lccn"); /* SM: 2010.10: lower case */ - } - if (bibtex.hasField("mrnumber")) { - standardNumber += " MRN: " + bibtex.getField("mrnumber"); - } - /* SM: 2010.10 begin DOI support */ - if (bibtex.hasField("doi")) { - standardNumber += " DOI: " + bibtex.getField("doi"); - } - /* SM: 2010.10 end DOI support */ - if (standardNumber.isEmpty()) { - standardNumber = null; - } - - if (bibtex.hasField("publisher")) { - publisher = bibtex.getField("publisher"); - } - - if (bibtex.hasField("address")) { - address = bibtex.getField("address"); - } - - if (bibtex.hasField("booktitle")) { - bookTitle = bibtex.getField("booktitle"); - } - - if (bibtex.hasField("chapter")) { - chapterNumber = bibtex.getField("chapter"); - } - - if (bibtex.hasField("journal")) { - journalName = bibtex.getField("journal"); - } - - if (bibtex.hasField("number")) { - issue = bibtex.getField("number"); - } - - if (bibtex.hasField(MSBIB + "periodical")) { - periodicalTitle = bibtex.getField(MSBIB + "periodical"); - } - - if (bibtex.hasField("booktitle")) { - conferenceName = bibtex.getField("booktitle"); - } - if (bibtex.hasField("school")) { - department = bibtex.getField("school"); - } - if (bibtex.hasField("institution")) { - institution = bibtex.getField("institution"); - } - - /* SM: 2010.10 Modified for default source types */ - if (bibtex.hasField("type")) { - thesisType = bibtex.getField("type"); - } else { - if ("techreport".equalsIgnoreCase(bibtex.getType())) { - thesisType = "Tech. rep."; - } else if ("mastersthesis".equalsIgnoreCase(bibtex.getType())) { - thesisType = "Master's thesis"; - } else if ("phdthesis".equalsIgnoreCase(bibtex.getType())) { - thesisType = "Ph.D. dissertation"; - } else if ("unpublished".equalsIgnoreCase(bibtex.getType())) { - thesisType = "unpublished"; - } - } - - if (("InternetSite".equals(sourceType) || "DocumentFromInternetSite".equals(sourceType)) - && (bibtex.hasField("title"))) { - internetSiteTitle = bibtex.getField("title"); - } - 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"); + getAuthors((Element) nodeLst.item(0)); } - if (bibtex.hasField(MSBIB + "productioncompany")) { - productionCompany = bibtex.getField(MSBIB + "productioncompany"); - } - - if (("ElectronicSource".equals(sourceType) || "Art".equals(sourceType) || "Misc".equals(sourceType)) - && (bibtex.hasField("title"))) { - publicationTitle = bibtex.getField("title"); - } - if (bibtex.hasField(MSBIB + "medium")) { - medium = bibtex.getField(MSBIB + "medium"); - } - if ("SoundRecording".equals(sourceType) && (bibtex.hasField("title"))) { - albumTitle = bibtex.getField("title"); - } - if (bibtex.hasField(MSBIB + "recordingnumber")) { - recordingNumber = bibtex.getField(MSBIB + "recordingnumber"); - } - if (bibtex.hasField(MSBIB + "theater")) { - theater = bibtex.getField(MSBIB + "theater"); - } - if (bibtex.hasField(MSBIB + "distributor")) { - distributor = bibtex.getField(MSBIB + "distributor"); - } - if ("Interview".equals(sourceType) && (bibtex.hasField("title"))) { - broadcastTitle = bibtex.getField("title"); - } - if (bibtex.hasField(MSBIB + "broadcaster")) { - broadcaster = bibtex.getField(MSBIB + "broadcaster"); - } - if (bibtex.hasField(MSBIB + "station")) { - station = bibtex.getField(MSBIB + "station"); - } - if (bibtex.hasField(MSBIB + "type")) { - type = bibtex.getField(MSBIB + "type"); - } - if (bibtex.hasField(MSBIB + "patentnumber")) { - patentNumber = bibtex.getField(MSBIB + "patentnumber"); - } - if (bibtex.hasField(MSBIB + "court")) { - court = bibtex.getField(MSBIB + "court"); - } - if (bibtex.hasField(MSBIB + "reporter")) { - reporter = bibtex.getField(MSBIB + "reporter"); - } - if (bibtex.hasField(MSBIB + "casenumber")) { - caseNumber = bibtex.getField(MSBIB + "casenumber"); - } - if (bibtex.hasField(MSBIB + "abbreviatedcasenumber")) { - abbreviatedCaseNumber = bibtex.getField(MSBIB + "abbreviatedcasenumber"); - } - - if (bibtex.hasField("series")) { - bibTexSeries = bibtex.getField("series"); - } - if (bibtex.hasField("abstract")) { - bibTexAbstract = bibtex.getField("abstract"); - } - if (bibtex.hasField("keywords")) { - bibTexKeyWords = bibtex.getField("keywords"); - } - if (bibtex.hasField("crossref")) { - bibTexCrossRef = bibtex.getField("crossref"); - } - if (bibtex.hasField("howpublished")) { - bibTex_HowPublished = bibtex.getField("howpublished"); - } - if (bibtex.hasField("affiliation")) { - bibTexAffiliation = bibtex.getField("affiliation"); - } - if (bibtex.hasField("contents")) { - bibTexContents = bibtex.getField("contents"); - } - if (bibtex.hasField("copyright")) { - bibTexCopyright = bibtex.getField("copyright"); - } - if (bibtex.hasField("price")) { - bibTexPrice = bibtex.getField("price"); - } - if (bibtex.hasField("size")) { - bibTexSize = bibtex.getField("size"); - } - - /* SM: 2010.10 end intype, paper support */ - if (bibtex.hasField("intype")) { - bibTexInType = bibtex.getField("intype"); - } - if (bibtex.hasField("paper")) { - bibTexPaper = bibtex.getField("paper"); - } - - if (bibtex.hasField("author")) { - authors = getAuthors(bibtex.getField("author")); - } - if (bibtex.hasField("editor")) { - editors = getAuthors(bibtex.getField("editor")); - } - } - // http://www.microsoft.com/globaldev/reference/lcid-all.mspx - private int getLCID(String language) { - // TODO: add language to LCID mapping - return 0; + private void getAuthors(Element authorsElem) { + authors = getSpecificAuthors("Author", authorsElem); + bookAuthors = getSpecificAuthors("BookAuthor", authorsElem); + editors = getSpecificAuthors("Editor", authorsElem); + translators = getSpecificAuthors("Translator", authorsElem); + producerNames = getSpecificAuthors("ProducerName", authorsElem); + composers = getSpecificAuthors("Composer", authorsElem); + conductors = getSpecificAuthors("Conductor", authorsElem); + performers = getSpecificAuthors("Performer", authorsElem); + writers = getSpecificAuthors("Writer", authorsElem); + directors = getSpecificAuthors("Director", authorsElem); + compilers = getSpecificAuthors("Compiler", authorsElem); + interviewers = getSpecificAuthors("Interviewer", authorsElem); + interviewees = getSpecificAuthors("Interviewee", authorsElem); + inventors = getSpecificAuthors("Inventor", authorsElem); + counsels = getSpecificAuthors("Counsel", authorsElem); } - // http://www.microsoft.com/globaldev/reference/lcid-all.mspx - private String getLanguage(int LCID) { - // TODO: add language to LCID mapping - return "english"; - } - - private List getSpecificAuthors(String type, Element authors, String bcol) { + private List getSpecificAuthors(String type, Element authors) { List result = null; - NodeList nodeLst = authors.getElementsByTagName(bcol + type); + NodeList nodeLst = authors.getElementsByTagNameNS("*", type); if (nodeLst.getLength() <= 0) { return result; } - nodeLst = ((Element) nodeLst.item(0)).getElementsByTagName(bcol + "NameList"); + nodeLst = ((Element) nodeLst.item(0)).getElementsByTagNameNS("*", "NameList"); if (nodeLst.getLength() <= 0) { return result; } - NodeList person = ((Element) nodeLst.item(0)).getElementsByTagName(bcol + "Person"); + NodeList person = ((Element) nodeLst.item(0)).getElementsByTagNameNS("*", "Person"); if (person.getLength() <= 0) { return result; } result = new LinkedList<>(); for (int i = 0; i < person.getLength(); i++) { - NodeList firstName = ((Element) person.item(i)).getElementsByTagName(bcol + "First"); - NodeList lastName = ((Element) person.item(i)).getElementsByTagName(bcol + "Last"); - NodeList middleName = ((Element) person.item(i)).getElementsByTagName(bcol + "Middle"); + NodeList firstName = ((Element) person.item(i)).getElementsByTagNameNS("*", "First"); + NodeList lastName = ((Element) person.item(i)).getElementsByTagNameNS("*", "Last"); + NodeList middleName = ((Element) person.item(i)).getElementsByTagNameNS("*", "Middle"); PersonName name = new PersonName(); if (firstName.getLength() > 0) { name.setFirstname(firstName.item(0).getTextContent()); @@ -589,99 +223,66 @@ private List getSpecificAuthors(String type, Element authors, String return result; } - private void getAuthors(Element authorsElem, String bcol) { - authors = getSpecificAuthors("Author", authorsElem, bcol); - bookAuthors = getSpecificAuthors("BookAuthor", authorsElem, bcol); - editors = getSpecificAuthors("Editor", authorsElem, bcol); - translators = getSpecificAuthors("Translator", authorsElem, bcol); - producerNames = getSpecificAuthors("ProducerName", authorsElem, bcol); - composers = getSpecificAuthors("Composer", authorsElem, bcol); - conductors = getSpecificAuthors("Conductor", authorsElem, bcol); - performers = getSpecificAuthors("Performer", authorsElem, bcol); - writers = getSpecificAuthors("Writer", authorsElem, bcol); - directors = getSpecificAuthors("Director", authorsElem, bcol); - compilers = getSpecificAuthors("Compiler", authorsElem, bcol); - interviewers = getSpecificAuthors("Interviewer", authorsElem, bcol); - interviewees = getSpecificAuthors("Interviewee", authorsElem, bcol); - inventors = getSpecificAuthors("Inventor", authorsElem, bcol); - counsels = getSpecificAuthors("Counsel", authorsElem, bcol); - } + public Element getDOM(Document document) { + Element rootNode = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "Source"); - private List getAuthors(String authors) { - List result = new LinkedList<>(); + for (Map.Entry entry : fields.entrySet()) { + addField(document, rootNode, entry.getKey(), entry.getValue()); + } - if (authors.contains(" and ")) { - String[] names = authors.split(" and "); - for (String name : names) { - result.add(new PersonName(name)); + // based on bibtex content + if (dateAccessed != null) { + Matcher matcher = DATE_PATTERN.matcher(dateAccessed); + if (matcher.matches() && (matcher.groupCount() >= 3)) { + addField(document, rootNode, "Month" + "Accessed", matcher.group(1)); + addField(document, rootNode, "Day" + "Accessed", matcher.group(2)); + addField(document, rootNode, "Year" + "Accessed", matcher.group(3)); } - } else { - result.add(new PersonName(authors)); } - return result; - } - private String getMSBibSourceType(BibEntry bibtex) { - String bibtexType = bibtex.getType(); + Element allAuthors = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "Author"); + + addAuthor(document, allAuthors, "Author", authors); + addAuthor(document, allAuthors, "BookAuthor", bookAuthors); + addAuthor(document, allAuthors, "Editor", editors); + addAuthor(document, allAuthors, "Translator", translators); + addAuthor(document, allAuthors, "ProducerName", producerNames); + addAuthor(document, allAuthors, "Composer", composers); + addAuthor(document, allAuthors, "Conductor", conductors); + addAuthor(document, allAuthors, "Performer", performers); + addAuthor(document, allAuthors, "Writer", writers); + addAuthor(document, allAuthors, "Director", directors); + addAuthor(document, allAuthors, "Compiler", compilers); + addAuthor(document, allAuthors, "Interviewer", interviewers); + addAuthor(document, allAuthors, "Interviewee", interviewees); + addAuthor(document, allAuthors, "Inventor", inventors); + addAuthor(document, allAuthors, "Counsel", counsels); + + rootNode.appendChild(allAuthors); - String result = "Misc"; - if ("book".equalsIgnoreCase(bibtexType)) { - result = "Book"; - } else if ("inbook".equalsIgnoreCase(bibtexType)) { - result = "BookSection"; - bibTexEntry = "inbook"; - } /* SM 2010.10: generalized */ else if ("booklet".equalsIgnoreCase(bibtexType)) { - result = "BookSection"; - bibTexEntry = "booklet"; - } else if ("incollection".equalsIgnoreCase(bibtexType)) { - result = "BookSection"; - bibTexEntry = "incollection"; - } else if ("article".equalsIgnoreCase(bibtexType)) { - result = "JournalArticle"; - } else if ("inproceedings".equalsIgnoreCase(bibtexType)) { - result = "ConferenceProceedings"; - bibTexEntry = "inproceedings"; - } /* SM 2010.10: generalized */ else if ("conference".equalsIgnoreCase(bibtexType)) { - result = "ConferenceProceedings"; - bibTexEntry = "conference"; - } else if ("proceedings".equalsIgnoreCase(bibtexType)) { - result = "ConferenceProceedings"; - bibTexEntry = "proceedings"; - } else if ("collection".equalsIgnoreCase(bibtexType)) { - result = "ConferenceProceedings"; - bibTexEntry = "collection"; - } else if ("techreport".equalsIgnoreCase(bibtexType)) { - result = "Report"; - bibTexEntry = "techreport"; - } /* SM 2010.10: generalized */ else if ("manual".equalsIgnoreCase(bibtexType)) { - result = "Report"; - bibTexEntry = "manual"; - } else if ("mastersthesis".equalsIgnoreCase(bibtexType)) { - result = "Report"; - bibTexEntry = "mastersthesis"; - } else if ("phdthesis".equalsIgnoreCase(bibtexType)) { - result = "Report"; - bibTexEntry = "phdthesis"; - } else if ("unpublished".equalsIgnoreCase(bibtexType)) { - result = "Report"; - bibTexEntry = "unpublished"; - } else if ("patent".equalsIgnoreCase(bibtexType)) { - result = "Patent"; - } else if ("misc".equalsIgnoreCase(bibtexType)) { - result = "Misc"; - } else if ("electronic".equalsIgnoreCase(bibtexType)) { - result = "Misc"; - bibTexEntry = "electronic"; + if (pages != null) { + addField(document, rootNode, "Pages", pages.toString("-")); } + addField(document, rootNode, "StandardNumber", standardNumber); + addField(document, rootNode, "ConferenceName", conferenceName); - return result; + addAddress(document, rootNode, address); + + addField(document, rootNode, "ThesisType", thesisType); + addField(document, rootNode, "InternetSiteTitle", internetSiteTitle); + + addField(document, rootNode, "PublicationTitle", publicationTitle); + addField(document, rootNode, "AlbumTitle", albumTitle); + addField(document, rootNode, "BroadcastTitle", broadcastTitle); + + return rootNode; } private void addField(Document document, Element parent, String name, String value) { if (value == null) { return; } - Element elem = document.createElement(B_COLON + name); + Element elem = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + name); elem.appendChild(document.createTextNode(StringUtil.stripNonValidXMLCharacters(value))); parent.appendChild(elem); } @@ -690,10 +291,10 @@ private void addAuthor(Document document, Element allAuthors, String entryName, if (authorsLst == null) { return; } - Element authorTop = document.createElement(B_COLON + entryName); - Element nameList = document.createElement(B_COLON + "NameList"); + Element authorTop = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + entryName); + Element nameList = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "NameList"); for (PersonName name : authorsLst) { - Element person = document.createElement(B_COLON + "Person"); + Element person = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "Person"); addField(document, person, "Last", name.getSurname()); addField(document, person, "Middle", name.getMiddlename()); addField(document, person, "First", name.getFirstname()); @@ -715,384 +316,7 @@ private void addAddress(Document document, Element parent, String address) { addField(document, parent, "StateProvince", matcher.group(2)); addField(document, parent, "CountryRegion", matcher.group(3)); } else { - /* SM: 2010.10 generalized */ addField(document, parent, "City", address); } } - - private void addDate(Document document, Element parent, String date, String extra) { - if (date == null) { - return; - } - - Matcher matcher = DATE_PATTERN.matcher(date); - if (matcher.matches() && (matcher.groupCount() >= 3)) { - addField(document, parent, "Month" + extra, matcher.group(1)); - addField(document, parent, "Day" + extra, matcher.group(2)); - addField(document, parent, "Year" + extra, matcher.group(3)); - } - } - - public Element getDOMrepresentation(Document document) { - - Element msbibEntry = document.createElement(B_COLON + "Source"); - - addField(document, msbibEntry, "SourceType", sourceType); - addField(document, msbibEntry, BIBTEX + "Entry", bibTexEntry); - - addField(document, msbibEntry, "Tag", tag); - addField(document, msbibEntry, "GUID", GUID); - if (LCID >= 0) { - addField(document, msbibEntry, "LCID", Integer.toString(LCID)); - } - addField(document, msbibEntry, "Title", title); - addField(document, msbibEntry, "Year", year); - addField(document, msbibEntry, "ShortTitle", shortTitle); - addField(document, msbibEntry, "Comments", comments); - - Element allAuthors = document.createElement(B_COLON + "Author"); - - addAuthor(document, allAuthors, "Author", authors); - String bookAuthor = "BookAuthor"; - addAuthor(document, allAuthors, bookAuthor, bookAuthors); - addAuthor(document, allAuthors, "Editor", editors); - addAuthor(document, allAuthors, "Translator", translators); - addAuthor(document, allAuthors, "ProducerName", producerNames); - addAuthor(document, allAuthors, "Composer", composers); - addAuthor(document, allAuthors, "Conductor", conductors); - addAuthor(document, allAuthors, "Performer", performers); - addAuthor(document, allAuthors, "Writer", writers); - addAuthor(document, allAuthors, "Director", directors); - addAuthor(document, allAuthors, "Compiler", compilers); - addAuthor(document, allAuthors, "Interviewer", interviewers); - addAuthor(document, allAuthors, "Interviewee", interviewees); - addAuthor(document, allAuthors, "Inventor", inventors); - addAuthor(document, allAuthors, "Counsel", counsels); - - msbibEntry.appendChild(allAuthors); - - if (pages != null) { - addField(document, msbibEntry, "Pages", pages.toString("-")); - } - addField(document, msbibEntry, "Volume", volume); - addField(document, msbibEntry, "NumberVolumes", numberOfVolumes); - addField(document, msbibEntry, "Edition", edition); - addField(document, msbibEntry, "StandardNumber", standardNumber); - addField(document, msbibEntry, "Publisher", publisher); - - addAddress(document, msbibEntry, address); - - addField(document, msbibEntry, "BookTitle", bookTitle); - addField(document, msbibEntry, "ChapterNumber", chapterNumber); - - addField(document, msbibEntry, "JournalName", journalName); - addField(document, msbibEntry, "Issue", issue); - addField(document, msbibEntry, "PeriodicalTitle", periodicalTitle); - addField(document, msbibEntry, "ConferenceName", conferenceName); - - addField(document, msbibEntry, "Department", department); - addField(document, msbibEntry, "Institution", institution); - addField(document, msbibEntry, "ThesisType", thesisType); - addField(document, msbibEntry, "InternetSiteTitle", internetSiteTitle); - - addDate(document, msbibEntry, dateAccessed, "Accessed"); - - /* 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); - addField(document, msbibEntry, "Medium", medium); - addField(document, msbibEntry, "AlbumTitle", albumTitle); - addField(document, msbibEntry, "RecordingNumber", recordingNumber); - addField(document, msbibEntry, "Theater", theater); - addField(document, msbibEntry, "Distributor", distributor); - addField(document, msbibEntry, "BroadcastTitle", broadcastTitle); - addField(document, msbibEntry, "Broadcaster", broadcaster); - addField(document, msbibEntry, "Station", station); - addField(document, msbibEntry, "Type", type); - addField(document, msbibEntry, "PatentNumber", patentNumber); - addField(document, msbibEntry, "Court", court); - addField(document, msbibEntry, "Reporter", reporter); - addField(document, msbibEntry, "CaseNumber", caseNumber); - addField(document, msbibEntry, "AbbreviatedCaseNumber", abbreviatedCaseNumber); - - addField(document, msbibEntry, BIBTEX + "Series", bibTexSeries); - addField(document, msbibEntry, BIBTEX + "Abstract", bibTexAbstract); - addField(document, msbibEntry, BIBTEX + "KeyWords", bibTexKeyWords); - addField(document, msbibEntry, BIBTEX + "CrossRef", bibTexCrossRef); - addField(document, msbibEntry, BIBTEX + "HowPublished", bibTex_HowPublished); - addField(document, msbibEntry, BIBTEX + "Affiliation", bibTexAffiliation); - addField(document, msbibEntry, BIBTEX + "Contents", bibTexContents); - addField(document, msbibEntry, BIBTEX + "Copyright", bibTexCopyright); - addField(document, msbibEntry, BIBTEX + "Price", bibTexPrice); - addField(document, msbibEntry, BIBTEX + "Size", bibTexSize); - - /* SM: 2010.10 end intype, paper support */ - addField(document, msbibEntry, BIBTEX + "InType", bibTexInType); - addField(document, msbibEntry, BIBTEX + "Paper", bibTexPaper); - - return msbibEntry; - } - - private void parseSingleStandardNumber(String type, String bibtype, String standardNum, Map map) { - // tested using http://www.javaregex.com/test.html - Pattern pattern = Pattern.compile(':' + type + ":(.[^:]+)"); - Matcher matcher = pattern.matcher(standardNum); - if (matcher.matches()) { - map.put(bibtype, matcher.group(1)); - } - } - - private void parseStandardNumber(String standardNum, Map map) { - if (standardNumber == null) { - return; - } - parseSingleStandardNumber("ISBN", "isbn", standardNum, map); /* SM: 2010.10: lower case */ - parseSingleStandardNumber("ISSN", "issn", standardNum, map); /* SM: 2010.10: lower case */ - parseSingleStandardNumber("LCCN", "lccn", standardNum, map); /* SM: 2010.10: lower case */ - parseSingleStandardNumber("MRN", "mrnumber", standardNum, map); - /* SM: 2010.10 begin DOI support */ - parseSingleStandardNumber("DOI", "doi", standardNum, map); - /* SM: 2010.10 end DOI support */ - } - - private void addAuthor(Map map, String type, List authors) { - if (authors == null) { - return; - } - String allAuthors = authors.stream().map(PersonName::getFullname).collect(Collectors.joining(" and ")); - - map.put(type, allAuthors); - } - - private EntryType mapMSBibToBibtexType(String msbib) { - EntryType bibtex; - switch (msbib) { - case "Book": - bibtex = BibtexEntryTypes.BOOK; - break; - case "BookSection": - bibtex = BibtexEntryTypes.INBOOK; - break; - case "JournalArticle": - case "ArticleInAPeriodical": - bibtex = BibtexEntryTypes.ARTICLE; - break; - case "ConferenceProceedings": - bibtex = BibtexEntryTypes.CONFERENCE; - break; - case "Report": - bibtex = BibtexEntryTypes.TECHREPORT; - break; - case "InternetSite": - case "DocumentFromInternetSite": - case "ElectronicSource": - case "Art": - case "SoundRecording": - case "Performance": - case "Film": - case "Interview": - case "Patent": - case "Case": - default: - bibtex = BibtexEntryTypes.MISC; - break; - } - - return bibtex; - } - - public BibEntry getBibtexRepresentation() { - - BibEntry entry; - if (tag == null) { - entry = new BibEntry(ImportFormat.DEFAULT_BIBTEXENTRY_ID, mapMSBibToBibtexType(sourceType).getName()); - } else { - entry = new BibEntry(tag, mapMSBibToBibtexType(sourceType).getName()); // id assumes an existing database so don't - } - - // Todo: add check for BibTexEntry types - - Map hm = new HashMap<>(); - - if (tag != null) { - hm.put(BibEntry.KEY_FIELD, tag); - } - - if (LCID >= 0) { - hm.put("language", getLanguage(LCID)); - } - if (title != null) { - hm.put("title", title); - } - if (year != null) { - hm.put("year", year); - } - if (shortTitle != null) { - hm.put(MSBIB + "shorttitle", shortTitle); - } - if (comments != null) { - hm.put("note", comments); - } - - addAuthor(hm, "author", authors); - addAuthor(hm, MSBIB + "bookauthor", bookAuthors); - addAuthor(hm, "editor", editors); - addAuthor(hm, MSBIB + "translator", translators); - addAuthor(hm, MSBIB + "producername", producerNames); - addAuthor(hm, MSBIB + "composer", composers); - addAuthor(hm, MSBIB + "conductor", conductors); - addAuthor(hm, MSBIB + "performer", performers); - addAuthor(hm, MSBIB + "writer", writers); - addAuthor(hm, MSBIB + "director", directors); - addAuthor(hm, MSBIB + "compiler", compilers); - addAuthor(hm, MSBIB + "interviewer", interviewers); - addAuthor(hm, MSBIB + "interviewee", interviewees); - addAuthor(hm, MSBIB + "inventor", inventors); - addAuthor(hm, MSBIB + "counsel", counsels); - - if (pages != null) { - hm.put("pages", pages.toString("--")); - } - if (volume != null) { - hm.put("volume", volume); - } - if (numberOfVolumes != null) { - hm.put(MSBIB + "numberofvolume", numberOfVolumes); - } - if (edition != null) { - hm.put("edition", edition); - } - if (edition != null) { - hm.put("edition", edition); - } - parseStandardNumber(standardNumber, hm); - - if (publisher != null) { - hm.put("publisher", publisher); - } - if (publisher != null) { - hm.put("publisher", publisher); - } - if (address != null) { - hm.put("address", address); - } - if (bookTitle != null) { - hm.put("booktitle", bookTitle); - } - if (chapterNumber != null) { - hm.put("chapter", chapterNumber); - } - if (journalName != null) { - hm.put("journal", journalName); - } - if (issue != null) { - hm.put("number", issue); - } - if (month != null) { - hm.put("month", month); - } - if (periodicalTitle != null) { - hm.put("organization", periodicalTitle); - } - if (conferenceName != null) { - hm.put("organization", conferenceName); - } - if (department != null) { - hm.put("school", department); - } - if (institution != null) { - hm.put("institution", institution); - } - - if (dateAccessed != null) { - hm.put(MSBIB + "accessed", dateAccessed); - } - if (doi != null) { - hm.put("doi", doi); - } - if (url != null) { - hm.put("url", url); - } - if (productionCompany != null) { - hm.put(MSBIB + "productioncompany", productionCompany); - } - - if (medium != null) { - hm.put(MSBIB + "medium", medium); - } - - if (recordingNumber != null) { - hm.put(MSBIB + "recordingnumber", recordingNumber); - } - if (theater != null) { - hm.put(MSBIB + "theater", theater); - } - if (distributor != null) { - hm.put(MSBIB + "distributor", distributor); - } - - if (broadcaster != null) { - hm.put(MSBIB + "broadcaster", broadcaster); - } - if (station != null) { - hm.put(MSBIB + "station", station); - } - if (type != null) { - hm.put(MSBIB + "type", type); - } - if (patentNumber != null) { - hm.put(MSBIB + "patentnumber", patentNumber); - } - if (court != null) { - hm.put(MSBIB + "court", court); - } - if (reporter != null) { - hm.put(MSBIB + "reporter", reporter); - } - if (caseNumber != null) { - hm.put(MSBIB + "casenumber", caseNumber); - } - if (abbreviatedCaseNumber != null) { - hm.put(MSBIB + "abbreviatedcasenumber", abbreviatedCaseNumber); - } - - if (bibTexSeries != null) { - hm.put("series", bibTexSeries); - } - if (bibTexAbstract != null) { - hm.put("abstract", bibTexAbstract); - } - if (bibTexKeyWords != null) { - hm.put("keywords", bibTexKeyWords); - } - if (bibTexCrossRef != null) { - hm.put("crossref", bibTexCrossRef); - } - if (bibTex_HowPublished != null) { - hm.put("howpublished", bibTex_HowPublished); - } - if (bibTexAffiliation != null) { - hm.put("affiliation", bibTexAffiliation); - } - if (bibTexContents != null) { - hm.put("contents", bibTexContents); - } - if (bibTexCopyright != null) { - hm.put("copyright", bibTexCopyright); - } - if (bibTexPrice != null) { - hm.put("price", bibTexPrice); - } - if (bibTexSize != null) { - hm.put("size", bibTexSize); - } - - entry.setField(hm); - return entry; - } - } diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibEntryType.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibEntryType.java new file mode 100644 index 00000000000..d83f1c331d2 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibEntryType.java @@ -0,0 +1,30 @@ +package net.sf.jabref.logic.msbib; + +/** + * This class represents all supported MSBib entry types. + *

+ * Book, BookSection, JournalArticle, ArticleInAPeriodical, ConferenceProceedings, Report, + * InternetSite, DocumentFromInternetSite, ElectronicSource, Art, SoundRecording, Performance, + * Film, Interview, Patent, Case, Misc + * + * See BIBFORM.XML, shared-bibliography.xsd (ECMA standard) + */ +public enum MSBibEntryType { + ArticleInAPeriodical, + Book, + BookSection, + JournalArticle, + ConferenceProceedings, + Report, + SoundRecording, + Performance, + Art, + DocumentFromInternetSite, + InternetSite, + Film, + Interview, + Patent, + ElectronicSource, + Case, + Misc +} diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibMapping.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibMapping.java new file mode 100644 index 00000000000..f9561b37e5b --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibMapping.java @@ -0,0 +1,130 @@ +package net.sf.jabref.logic.msbib; + +import java.util.Map; +import java.util.TreeMap; + +import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.model.entry.BibtexEntryTypes; + +import com.google.common.collect.HashBiMap; + +public class MSBibMapping { + private static final String BIBTEX_PREFIX = "BIBTEX_"; + private static final String MSBIB_PREFIX = "msbib-"; + + private static final HashBiMap bibtexToMSBib = HashBiMap.create(); + + static { + bibtexToMSBib.put(BibEntry.KEY_FIELD, "Tag"); + bibtexToMSBib.put("title", "Title"); + bibtexToMSBib.put("year", "Year"); + bibtexToMSBib.put("month", "Month"); + bibtexToMSBib.put("note", "Comments"); + bibtexToMSBib.put("volume", "Volume"); + bibtexToMSBib.put("language", "LCID"); + bibtexToMSBib.put("edition", "Edition"); + bibtexToMSBib.put("publisher", "Publisher"); + bibtexToMSBib.put("booktitle", "BookTitle"); + //bibtexToMSBib.put("booktitle", "ConferenceName"); + //bibtexToMSBib.put("pages", "Pages"); + bibtexToMSBib.put("chapter", "ChapterNumber"); + bibtexToMSBib.put("journal", "JournalName"); + bibtexToMSBib.put("number", "Issue"); + bibtexToMSBib.put("school", "Department"); + bibtexToMSBib.put("institution", "Institution"); + bibtexToMSBib.put("doi", "DOI"); + bibtexToMSBib.put("url", "URL"); + // BibTeX only fields + bibtexToMSBib.put("series", BIBTEX_PREFIX + "Series"); + bibtexToMSBib.put("abstract", BIBTEX_PREFIX + "Abstract"); + bibtexToMSBib.put("keywords", BIBTEX_PREFIX + "KeyWords"); + bibtexToMSBib.put("crossref", BIBTEX_PREFIX + "CrossRef"); + bibtexToMSBib.put("howpublished", BIBTEX_PREFIX + "HowPublished"); + bibtexToMSBib.put("affiliation", BIBTEX_PREFIX + "Affiliation"); + bibtexToMSBib.put("contents", BIBTEX_PREFIX + "Contents"); + bibtexToMSBib.put("copyright", BIBTEX_PREFIX + "Copyright"); + bibtexToMSBib.put("price", BIBTEX_PREFIX + "Price"); + bibtexToMSBib.put("size", BIBTEX_PREFIX + "Size"); + bibtexToMSBib.put("intype", BIBTEX_PREFIX + "InType"); + bibtexToMSBib.put("paper", BIBTEX_PREFIX + "Paper"); + // MSBib only fields + bibtexToMSBib.put(MSBIB_PREFIX + "shorttitle", "ShortTitle"); + bibtexToMSBib.put(MSBIB_PREFIX + "numberofvolume", "NumberVolumes"); + bibtexToMSBib.put(MSBIB_PREFIX + "periodical", "PeriodicalTitle"); + //bibtexToMSBib.put(MSBIB_PREFIX + "day", "Day"); + //bibtexToMSBib.put(PREFIX + "accessed", "Accessed"); + bibtexToMSBib.put(MSBIB_PREFIX + "medium", "Medium"); + bibtexToMSBib.put(MSBIB_PREFIX + "recordingnumber", "RecordingNumber"); + bibtexToMSBib.put(MSBIB_PREFIX + "theater", "Theater"); + bibtexToMSBib.put(MSBIB_PREFIX + "distributor", "Distributor"); + bibtexToMSBib.put(MSBIB_PREFIX + "broadcaster", "Broadcaster"); + bibtexToMSBib.put(MSBIB_PREFIX + "station", "Station"); + bibtexToMSBib.put(MSBIB_PREFIX + "type", "Type"); + bibtexToMSBib.put(MSBIB_PREFIX + "patentnumber", "PatentNumber"); + bibtexToMSBib.put(MSBIB_PREFIX + "court", "Court"); + bibtexToMSBib.put(MSBIB_PREFIX + "reporter", "Reporter"); + bibtexToMSBib.put(MSBIB_PREFIX + "casenumber", "CaseNumber"); + bibtexToMSBib.put(MSBIB_PREFIX + "abbreviatedcasenumber", "AbbreviatedCaseNumber"); + bibtexToMSBib.put(MSBIB_PREFIX + "productioncompany", "ProductionCompany"); + } + + public static String getBibTeXEntryType(String msbibType) { + final String defaultType = BibtexEntryTypes.MISC.getName(); + + Map entryTypeMapping = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + entryTypeMapping.put("Book", BibtexEntryTypes.BOOK.getName()); + entryTypeMapping.put("BookSection", BibtexEntryTypes.INBOOK.getName()); + entryTypeMapping.put("JournalArticle", BibtexEntryTypes.ARTICLE.getName()); + entryTypeMapping.put("ArticleInAPeriodical", BibtexEntryTypes.ARTICLE.getName()); + entryTypeMapping.put("ConferenceProceedings", BibtexEntryTypes.CONFERENCE.getName()); + entryTypeMapping.put("Report", BibtexEntryTypes.TECHREPORT.getName()); + + return entryTypeMapping.getOrDefault(msbibType, defaultType); + } + + public static MSBibEntryType getMSBibEntryType(String bibtexType) { + Map entryTypeMapping = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + entryTypeMapping.put("book", MSBibEntryType.Book); + entryTypeMapping.put("inbook", MSBibEntryType.BookSection); + entryTypeMapping.put("booklet", MSBibEntryType.BookSection); + entryTypeMapping.put("incollection", MSBibEntryType.BookSection); + entryTypeMapping.put("article", MSBibEntryType.JournalArticle); + entryTypeMapping.put("inproceedings", MSBibEntryType.ConferenceProceedings); + entryTypeMapping.put("conference", MSBibEntryType.ConferenceProceedings); + entryTypeMapping.put("proceedings", MSBibEntryType.ConferenceProceedings); + entryTypeMapping.put("collection", MSBibEntryType.ConferenceProceedings); + entryTypeMapping.put("techreport", MSBibEntryType.Report); + entryTypeMapping.put("manual", MSBibEntryType.Report); + entryTypeMapping.put("mastersthesis", MSBibEntryType.Report); + entryTypeMapping.put("phdthesis", MSBibEntryType.Report); + entryTypeMapping.put("unpublished", MSBibEntryType.Report); + entryTypeMapping.put("patent", MSBibEntryType.Patent); + entryTypeMapping.put("misc", MSBibEntryType.Misc); + entryTypeMapping.put("electronic", MSBibEntryType.Misc); + + return entryTypeMapping.getOrDefault(bibtexType, MSBibEntryType.Misc); + } + + // http://www.microsoft.com/globaldev/reference/lcid-all.mspx + public static int getLCID(String language) { + // TODO: add language to LCID mapping + // 0 is English + return 0; + } + + // http://www.microsoft.com/globaldev/reference/lcid-all.mspx + public static String getLanguage(int LCID) { + // TODO: add language to LCID mapping + return "english"; + } + + public static String getMSBibField(String bibtexFieldName) { + return bibtexToMSBib.get(bibtexFieldName); + } + + public static String getBibTeXField(String msbibFieldName) { + return bibtexToMSBib.inverse().get(msbibFieldName); + } +} diff --git a/src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java b/src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java index 3c140f8bc55..b9c1841fb7f 100644 --- a/src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java +++ b/src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java @@ -8,6 +8,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -54,7 +55,7 @@ public class MSBibExportFormatTestFiles { public static Collection fileNames() throws IOException { try (Stream stream = Files.list(Paths.get(PATH_TO_FILE))) { return stream.map(n -> n.getFileName().toString()).filter(n -> n.endsWith(".bib")) - .filter(n -> n.startsWith("MsBibExportFormat")).collect(Collectors.toList()); + .filter(n -> n.startsWith("MsBib")).collect(Collectors.toList()); } } @@ -80,6 +81,8 @@ public final void testPerformExport() throws IOException, URISyntaxException { List expected = Files.readAllLines(Paths.get(PATH_TO_FILE + xmlFileName)); List exported = Files.readAllLines(Paths.get(tempFilename)); + Collections.sort(expected); + Collections.sort(exported); assertEquals(expected, exported); } } diff --git a/src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java b/src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java index dbe8178d1cd..0b0d8b643d2 100644 --- a/src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java +++ b/src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java @@ -1,13 +1,9 @@ package net.sf.jabref.exporter; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -15,8 +11,6 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; -import net.sf.jabref.importer.ParserResult; -import net.sf.jabref.importer.fileformat.BibtexParser; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; @@ -27,7 +21,6 @@ import org.junit.rules.TemporaryFolder; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class MsBibExportFormatTest { @@ -57,22 +50,4 @@ public final void testPerformExportWithNoEntry() throws IOException { msBibExportFormat.performExport(databaseContext, tempFileName, charset, entries); assertEquals(Collections.emptyList(), Files.readAllLines(tempFile.toPath())); } - - @Test - public final void testPerformExportWithTestBib() throws IOException { - try (FileInputStream stream = new FileInputStream("src/test/resources/net/sf/jabref/bibtexFiles/test.bib"); - InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { - ParserResult result = BibtexParser.parse(reader); - BibDatabase database = result.getDatabase(); - String tempFilename = tempFile.getCanonicalPath(); - List entries = database.getEntries(); - assertNotNull(entries); - msBibExportFormat.performExport(databaseContext, tempFile.getPath(), charset, entries); - List expected = Files.readAllLines(Paths.get("src/test/resources/net/sf/jabref/exporter/test.xml")); - List exported = Files.readAllLines(Paths.get(tempFilename)); - Collections.sort(expected); - Collections.sort(exported); - assertEquals(expected, exported); - } - } } diff --git a/src/test/java/net/sf/jabref/importer/fileformat/MsBibImporterTestfiles.java b/src/test/java/net/sf/jabref/importer/fileformat/MsBibImporterTestfiles.java index 3e8d1e6d350..3b9c229fa40 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/MsBibImporterTestfiles.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/MsBibImporterTestfiles.java @@ -39,7 +39,7 @@ public void setUp() throws URISyntaxException { @Parameters(name = "{index}: {0}") public static Collection fileNames() { Object[][] data = new Object[][] {{"MsBibImporterTest1"}, {"MsBibImporterTest2"}, {"MsBibImporterTest3"}, - {"MsBibImporterTest4"}, {"MsBibImporterTest5"}, {"MsBibImporterTest6"}}; + {"MsBibImporterTest4"}, {"MsBibImporterTest5"}, {"MsBibImporterTest6"}, {"MsBibLCID"}}; return Arrays.asList(data); } diff --git a/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java b/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java index 0d2ecd85bfa..8a72fc6f866 100644 --- a/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java +++ b/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java @@ -36,8 +36,9 @@ public void ignoreWhitespaceInPageNumbers() { } @Test - public void removeWhitespaceForSinglePageNumber() { + public void removeWhitespace() { expectCorrect(" 1 ", "1"); + expectCorrect(" 1 -- 2 ", "1--2"); } @Test diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.bib b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.bib new file mode 100644 index 00000000000..27656236633 --- /dev/null +++ b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.bib @@ -0,0 +1,3 @@ +@unpublished{, + title = {Uml{\"a}uts are f\"unny} +} diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.xml b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.xml new file mode 100644 index 00000000000..c96fa94ee04 --- /dev/null +++ b/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.xml @@ -0,0 +1,10 @@ + + + +Report +unpublished +Umläuts are fünny + +unpublished + + diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibLCID.bib b/src/test/resources/net/sf/jabref/exporter/MsBibLCID.bib new file mode 100644 index 00000000000..b62dcc57b97 --- /dev/null +++ b/src/test/resources/net/sf/jabref/exporter/MsBibLCID.bib @@ -0,0 +1,4 @@ +@Article{, + language = {english} +} + diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibLCID.xml b/src/test/resources/net/sf/jabref/exporter/MsBibLCID.xml new file mode 100644 index 00000000000..12661954648 --- /dev/null +++ b/src/test/resources/net/sf/jabref/exporter/MsBibLCID.xml @@ -0,0 +1,9 @@ + + + +JournalArticle +0 + +article + + diff --git a/src/test/resources/net/sf/jabref/exporter/test.xml b/src/test/resources/net/sf/jabref/exporter/test.xml deleted file mode 100644 index 3cbf4c63a0f..00000000000 --- a/src/test/resources/net/sf/jabref/exporter/test.xml +++ /dev/null @@ -1,601 +0,0 @@ - - - -ConferenceProceedings -inproceedings -1358810 -Human-in-the-loop: rethinking security in mobile and pervasive systems -2008 - - - - -Kostakos -Vassilis - - - - -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 -CHI '08: CHI '08 extended abstracts on Human factors in computing systems -CHI '08: CHI '08 extended abstracts on Human factors in computing systems - - -JournalArticle -820136 -Design and usability in security systems: daily life as a context of use? -2002 - - - - -Clear -Tony - - - - -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 -SIGCSE Bull. -4 - - -JournalArticle -1373163 -Useful Computer Security -2008 - - - - -Churchill -Elizabeth - - -Nelson -Les - - -Smetters -K. -Diana - - - - -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 -NJ -USA -IEEE Internet Computing -3 - - -ConferenceProceedings -inproceedings -00000000 -Are Usability and Security Two Opposite Directions in Computer Systems? -2004 - - - - -Rozinov -Konstantin - - - - - - -JournalArticle -1025014 -Password Memorability and Security: Empirical Results -2004 - - - - -Yan -Jeff - - -Blackwell -Alan - - -Anderson -Ross - - -Grant -Alasdair - - - - -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 -NJ -USA -IEEE Security and Privacy -5 - - -JournalArticle -1102917 -The trouble with login: on usability and computer security in ubiquitous computing -2005 - - - - -Bardram -E. - - - - -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 -U -K -Personal Ubiquitous Comput. -6 - - -ConferenceProceedings -inproceedings -1137631 -Extending XP practices to support security requirements engineering -2006 - - - - -Bostr\"{o}m -Gustav - - -W\"{a}yrynen -Jaana - - -Bod\'{e}n -Marine - - -Beznosov -Konstantin - - -Kruchten -Philippe - - - - -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 -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems - - -ConferenceProceedings -inproceedings -1233448 -Increasing security and usability of computer systems with graphical passwords -2007 - - - - -Hinds -Cheryl - - -Ekwueme -Chinedu - - - - -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 -ACM-SE 45: Proceedings of the 45th annual southeast regional conference -ACM-SE 45: Proceedings of the 45th annual southeast regional conference - - -JournalArticle -10250999 -Article with complex Authornames -2004 - - - - -von Hippel -Eric - - -Reagle -Joseph M. -Jr., - - -Sherry -F., Jr. -John - - -van den Huevel -Johan A. -Jr., - - - - -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 -NJ -USA -IEEE Security and Privacy -5 - - -ConferenceProceedings -inproceedings -1132768 -Security and usability: the case of the user authentication methods -2006 - - - - -Braz -Christina - - -Robert -Jean-Marc - - - - -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 -IHM '06: Proceedings of the 18th International Conferenceof the Association Francophone d'Interaction Homme-Machine -IHM '06: Proceedings of the 18th International Conferenceof the Association Francophone d'Interaction Homme-Machine - - -ConferenceProceedings -inproceedings -1251435 -Why Johnny can't encrypt: a usability evaluation of PGP 5.0 -1999 - - - - -Whitten -Alma - - -Tygar -D. -J. - - - - -14-14 -USENIX Association -Berkeley -CA -USA -SSYM'99: Proceedings of the 8th conference on USENIX Security Symposium -SSYM'99: Proceedings of the 8th conference on USENIX Security Symposium - - -ConferenceProceedings -inproceedings -1182529 -Question-based authentication using context data -2006 - - - - -Nosseir -Ann - - -Connor -Richard - - -Revie -Crawford - - -Terzis -Sotirios - - - - -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 -NordiCHI '06: Proceedings of the 4th Nordic conference on Human-computer interaction -NordiCHI '06: Proceedings of the 4th Nordic conference on Human-computer interaction - - -ConferenceProceedings -inproceedings -1137636 -Trust and tamper-proof software delivery -2006 - - - - -Naedele -Martin - - -Koch -E. -Thomas - - - - -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 -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems - - -ConferenceProceedings -inproceedings -1314293 -Randomized radon transforms for biometric authentication via fingerprint hashing -2007 - - - - -Jakubowski -H. -Mariusz - - -Venkatesan -Ramarathnam - - - - -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 -DRM '07: Proceedings of the 2007 ACM workshop on Digital Rights Management -DRM '07: Proceedings of the 2007 ACM workshop on Digital Rights Management - - -ConferenceProceedings -inproceedings -1137628 -Introduction to software engineering for secure systems: SESS06 -- secure by design -2006 - - - - -Bruschi -Danilo - - -Win -De -Bart - - -Monga -Mattia - - - - -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 -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems - - -ConferenceProceedings -inproceedings -1073004 -Two experiences designing for effective security -2005 - - - - -de Paula -Rog\'{e}rio - - -Ding -Xianghua - - -Dourish -Paul - - -Nies -Kari - - -Pillet -Ben - - -Redmiles -David - - -Ren -Jie - - -Rode -Jennifer - - -Filho -Silva -Roberto - - - - -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 -SOUPS '05: Proceedings of the 2005 symposium on Usable privacy and security -SOUPS '05: Proceedings of the 2005 symposium on Usable privacy and security - - -ConferenceProceedings -inproceedings -1137633 -How secure is AOP and what can we do about it? -2006 - - - - -Win -De -Bart - - -Piessens -Frank - - -Joosen -Wouter - - - - -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 -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems -SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems - - -Book -1098730 -Security and Usability -2005 - - - - -Cranor -Lorrie - - -Garfinkel -Simson - - - - - ISBN: 0596008279 -O'Reilly Media, Inc. - - -ConferenceProceedings -inproceedings -1143122 -Aligning usability and security: a usability study of Polaris -2006 - - - - -DeWitt -J. -Alexander - - -Kuljis -Jasna - - - - -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 -SOUPS '06: Proceedings of the second symposium on Usable privacy and security -SOUPS '06: Proceedings of the second symposium on Usable privacy and security - - diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest1.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest1.xml index 649ba172958..0b5670840fe 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest1.xml +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest1.xml @@ -5,7 +5,6 @@ raey 0 Agile Entwicklung Web-basierter Systeme -BookSection 2002 237-248 44 diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.bib b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.bib index 282796f3be7..1907e883d4b 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.bib +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.bib @@ -11,6 +11,7 @@ @Article{ copyright = {cop}, crossref = {cross}, edition = {10}, + language = {english}, howpublished = {how}, institution = {Institution}, msbib-abbreviatedcasenumber = {abb}, @@ -29,6 +30,7 @@ @Article{ msbib-station = {stat}, msbib-theater = {th}, msbib-type = {type}, + msbib-periodical = {Besondere Turingmaschinen}, organization = {Besondere Turingmaschinen}, price = {10}, school = {Gymnasium Unterrieden}, diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.xml index 1d57a98ff77..8a475457cfd 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.xml +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest2.xml @@ -21,13 +21,13 @@ Stuttgart Bawü Deutschland -z +0 July 3 2010 Turingmaschinen 3 -Besondere TuringMaschinen +Besondere Turingmaschinen Besondere Turingmaschinen Gymnasium Unterrieden Institution diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest3.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest3.xml index bc251f1d8b2..a927f422eff 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest3.xml +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest3.xml @@ -16,7 +16,6 @@ 0 Agile Entwicklung Web-basierter Systeme -BookSection 2002 237-248 44 @@ -26,5 +25,5 @@ 3 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/importer/fileformat/MsBibImporterTest4.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest4.xml index e466ea7198f..3473e80bd88 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest4.xml +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest4.xml @@ -5,7 +5,6 @@ raey 0 Agile Entwicklung Web-basierter Systeme -BookSection 2002 237-248 44 @@ -15,5 +14,5 @@ 3 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/importer/fileformat/MsBibImporterTest5.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest5.xml index 7688a2b051e..87eb55d1792 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest5.xml +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest5.xml @@ -5,7 +5,6 @@ 0 Agile Entwicklung Web-basierter Systeme -BookSection 2002 237-248 44 @@ -15,5 +14,5 @@ 3 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/importer/fileformat/MsBibImporterTest6.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest6.xml index 45fa51229b7..13f34bd052c 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest6.xml +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibImporterTest6.xml @@ -5,7 +5,6 @@ 0 Agile Entwicklung Web-basierter Systeme -BookSection 2002 237-248 44 @@ -15,5 +14,5 @@ 3 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/importer/fileformat/MsBibLCID.bib b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.bib new file mode 100644 index 00000000000..b62dcc57b97 --- /dev/null +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.bib @@ -0,0 +1,4 @@ +@Article{, + language = {english} +} + diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.xml new file mode 100644 index 00000000000..7eb75b14172 --- /dev/null +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MsBibLCID.xml @@ -0,0 +1,7 @@ + + + +JournalArticle +0 + +