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());
}
}
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;
}
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);
}
}
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);
}
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());
}
Aggregations