Search in sources :

Example 26 with BibtexString

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

the class BibDatabaseTest method circularStringResolvingLongerCycle.

@Test
public void circularStringResolvingLongerCycle() {
    BibtexString string = new BibtexString("AAA", "#BBB#");
    database.addString(string);
    string = new BibtexString("BBB", "#CCC#");
    database.addString(string);
    string = new BibtexString("CCC", "#DDD#");
    database.addString(string);
    string = new BibtexString("DDD", "#AAA#");
    database.addString(string);
    assertEquals(database.resolveForStrings("#AAA#"), "AAA");
    assertEquals(database.resolveForStrings("#BBB#"), "BBB");
    assertEquals(database.resolveForStrings("#CCC#"), "CCC");
    assertEquals(database.resolveForStrings("#DDD#"), "DDD");
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 27 with BibtexString

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

the class BibDatabaseTest method hasStringLabelFindsString.

@Test
public void hasStringLabelFindsString() {
    BibtexString string = new BibtexString("DSP", "Digital Signal Processing");
    database.addString(string);
    assertTrue(database.hasStringLabel("DSP"));
    assertFalse(database.hasStringLabel("VLSI"));
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 28 with BibtexString

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

the class BibDatabaseTest method resolveForStringsOddHashMarkAtTheEnd.

@Test
public void resolveForStringsOddHashMarkAtTheEnd() {
    BibtexString string = new BibtexString("AAA", "aaa");
    database.addString(string);
    assertEquals(database.resolveForStrings("AAA#AAA#AAA#"), "AAAaaaAAA#");
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 29 with BibtexString

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

the class BibDatabaseTest method getUsedStringsNoString.

@Test
public void getUsedStringsNoString() {
    BibEntry entry = new BibEntry();
    entry.setField("author", "Oscar Gustafsson");
    BibtexString string = new BibtexString("AAA", "Some other text");
    database.addString(string);
    database.insertEntry(entry);
    Collection<BibtexString> usedStrings = database.getUsedStrings(Arrays.asList(entry));
    assertEquals(Collections.emptyList(), usedStrings);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 30 with BibtexString

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

the class StringChange method makeChange.

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
    if (string == null) {
        // The string was removed or renamed locally. We guess that it was removed.
        BibtexString bs = new BibtexString(label, disk);
        try {
            panel.getDatabase().addString(bs);
            undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
        } catch (KeyCollisionException ex) {
            LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
        }
    } else {
        string.setContent(disk);
        undoEdit.addEdit(new UndoableStringChange(panel, string, false, mem, disk));
    }
    // Update tmp database:
    if (tmpString == null) {
        BibtexString bs = new BibtexString(label, disk);
        secondary.addString(bs);
    } else {
        tmpString.setContent(disk);
    }
    return true;
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) UndoableInsertString(org.jabref.gui.undo.UndoableInsertString) UndoableStringChange(org.jabref.gui.undo.UndoableStringChange) BibtexString(org.jabref.model.entry.BibtexString)

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