Search in sources :

Example 6 with BibtexString

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

the class BibtexParser method parseBibtexString.

private void parseBibtexString() throws IOException {
    BibtexString bibtexString = parseString();
    bibtexString.setParsedSerialization(dumpTextReadSoFarToString());
    try {
        database.addString(bibtexString);
    } catch (KeyCollisionException ex) {
        parserResult.addWarning(Localization.lang("Duplicate string name") + ": " + bibtexString.getName());
    }
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) BibtexString(org.jabref.model.entry.BibtexString)

Example 7 with BibtexString

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

the class BibDatabase method getUsedStrings.

/**
     * Get all strings used in the entries.
     */
public Collection<BibtexString> getUsedStrings(Collection<BibEntry> entries) {
    List<BibtexString> result = new ArrayList<>();
    Set<String> allUsedIds = new HashSet<>();
    // All entries
    for (BibEntry entry : entries) {
        for (String fieldContent : entry.getFieldValues()) {
            resolveContent(fieldContent, new HashSet<>(), allUsedIds);
        }
    }
    // Preamble
    if (preamble != null) {
        resolveContent(preamble, new HashSet<>(), allUsedIds);
    }
    for (String stringId : allUsedIds) {
        result.add((BibtexString) bibtexStrings.get(stringId).clone());
    }
    return result;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) BibtexString(org.jabref.model.entry.BibtexString) BibtexString(org.jabref.model.entry.BibtexString) HashSet(java.util.HashSet)

Example 8 with BibtexString

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

the class BibDatabase method copyStrings.

/**
     * Copies all Strings from another BibDatabase.
     *
     * @param database another BibDatabase
     */
public void copyStrings(BibDatabase database) {
    for (String key : database.getStringKeySet()) {
        BibtexString string = database.getString(key);
        addString(string);
    }
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) BibtexString(org.jabref.model.entry.BibtexString)

Example 9 with BibtexString

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

the class BibtexStringComparatorTest method test.

@Test
public void test() {
    BibtexString bs1 = new BibtexString("VLSI", "Very Large Scale Integration");
    BibtexString bs2 = new BibtexString("DSP", "Digital Signal Processing");
    BibtexString bs3 = new BibtexString("DSP", "Digital Signal Processing");
    // Same string
    assertEquals(0, bsc1.compare(bs1, bs1));
    // Same content
    assertEquals(0, bsc1.compare(bs2, bs3));
    // Alphabetical order
    assertTrue(bsc1.compare(bs1, bs2) > 0);
    assertTrue(bsc1.compare(bs2, bs1) < 0);
    // Same, but with the comparator checking for internal strings (none)
    assertEquals(0, bsc2.compare(bs1, bs1));
    assertEquals(0, bsc2.compare(bs2, bs3));
    assertTrue(bsc2.compare(bs1, bs2) > 0);
    assertTrue(bsc2.compare(bs2, bs1) < 0);
    // Create string with internal string
    BibtexString bs4 = new BibtexString("DSPVLSI", "#VLSI# #DSP#");
    // bs4 before bs1 if not considering that bs4 contains bs1
    assertTrue(bsc1.compare(bs1, bs4) > 0);
    assertTrue(bsc1.compare(bs4, bs1) < 0);
    // bs4 after bs1 if considering that bs4 contains bs1
    assertTrue(bsc2.compare(bs1, bs4) < 0);
    assertTrue(bsc2.compare(bs4, bs1) > 0);
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 10 with BibtexString

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

the class BibtexDatabaseWriterTest method writeString.

@Test
public void writeString() throws Exception {
    database.addString(new BibtexString("name", "content"));
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences());
    assertEquals(OS.NEWLINE + "@String{name = {content}}" + OS.NEWLINE, session.getStringValue());
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Aggregations

BibtexString (org.jabref.model.entry.BibtexString)40 Test (org.junit.Test)24 ParserResult (org.jabref.logic.importer.ParserResult)8 BibEntry (org.jabref.model.entry.BibEntry)7 StringReader (java.io.StringReader)6 KeyCollisionException (org.jabref.model.database.KeyCollisionException)5 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NamedCompound (org.jabref.gui.undo.NamedCompound)2 UndoableStringChange (org.jabref.gui.undo.UndoableStringChange)2 BibDatabase (org.jabref.model.database.BibDatabase)2 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Scanner (java.util.Scanner)1 Matcher (java.util.regex.Matcher)1