Search in sources :

Example 6 with Month

use of org.jabref.model.entry.Month in project jabref by JabRef.

the class BibDatabase method resolveString.

/**
     * If the label represents a string contained in this database, returns
     * that string's content. Resolves references to other strings, taking
     * care not to follow a circular reference pattern.
     * If the string is undefined, returns null.
     */
private String resolveString(String label, Set<String> usedIds, Set<String> allUsedIds) {
    Objects.requireNonNull(label);
    Objects.requireNonNull(usedIds);
    Objects.requireNonNull(allUsedIds);
    for (BibtexString string : bibtexStrings.values()) {
        if (string.getName().equalsIgnoreCase(label)) {
            // infinite recursion.
            if (usedIds.contains(string.getId())) {
                LOGGER.info("Stopped due to circular reference in strings: " + label);
                return label;
            }
            // If not, log this string's ID now.
            usedIds.add(string.getId());
            if (allUsedIds != null) {
                allUsedIds.add(string.getId());
            }
            // Ok, we found the string. Now we must make sure we
            // resolve any references to other strings in this one.
            String result = string.getContent();
            result = resolveContent(result, usedIds, allUsedIds);
            // Finished with recursing this branch, so we remove our
            // ID again:
            usedIds.remove(string.getId());
            return result;
        }
    }
    // If we get to this point, the string has obviously not been defined locally.
    // Check if one of the standard BibTeX month strings has been used:
    Optional<Month> month = Month.getMonthByShortName(label);
    return month.map(Month::getFullName).orElse(null);
}
Also used : Month(org.jabref.model.entry.Month) BibtexString(org.jabref.model.entry.BibtexString) BibtexString(org.jabref.model.entry.BibtexString)

Aggregations

Month (org.jabref.model.entry.Month)6 BibEntry (org.jabref.model.entry.BibEntry)5 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 TypedBibEntry (org.jabref.logic.TypedBibEntry)1 ParserResult (org.jabref.logic.importer.ParserResult)1 OAI2Handler (org.jabref.logic.importer.util.OAI2Handler)1 BibtexString (org.jabref.model.entry.BibtexString)1 JSONArray (org.json.JSONArray)1 DefaultHandler (org.xml.sax.helpers.DefaultHandler)1