use of org.jabref.model.metadata.MetaData in project jabref by JabRef.
the class ArgumentProcessor method regenerateBibtexKeys.
private void regenerateBibtexKeys(List<ParserResult> loaded) {
for (ParserResult parserResult : loaded) {
BibDatabase database = parserResult.getDatabase();
MetaData metaData = parserResult.getMetaData();
if (metaData != null) {
LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata"));
for (BibEntry entry : database.getEntries()) {
// try to make a new label
BibtexKeyPatternUtil.makeAndSetLabel(metaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), database, entry, Globals.prefs.getBibtexKeyPatternPreferences());
}
} else {
LOGGER.info(Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys"));
}
}
}
use of org.jabref.model.metadata.MetaData in project jabref by JabRef.
the class ImportInspectionDialog method generateKeyForEntry.
/**
* Generate key for an entry.
*/
private void generateKeyForEntry(BibEntry entry) {
entries.getReadWriteLock().writeLock().lock();
try {
BibDatabase database;
MetaData localMetaData;
// Relate to existing database, if any:
if (panel == null) {
database = new BibDatabase();
localMetaData = new MetaData();
} else {
database = panel.getDatabase();
localMetaData = panel.getBibDatabaseContext().getMetaData();
}
entry.setId(IdGenerator.next());
// Add the entry to the database we are working with:
database.insertEntry(entry);
// Generate a unique key:
BibtexKeyPatternUtil.makeAndSetLabel(localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), database, entry, Globals.prefs.getBibtexKeyPatternPreferences());
// Remove the entry from the database again, since we only added it in
// order to
// make sure the key was unique:
database.removeEntry(entry);
} finally {
entries.getReadWriteLock().writeLock().unlock();
}
glTable.repaint();
}
use of org.jabref.model.metadata.MetaData in project jabref by JabRef.
the class ImportInspectionDialog method generateKeys.
/**
* Generate keys for all entries. All keys will be unique with respect to
* one another, and, if they are destined for an existing database, with
* respect to existing keys in the database.
*/
private void generateKeys() {
entries.getReadWriteLock().writeLock().lock();
try {
BibDatabase database;
MetaData localMetaData;
// Relate to existing database, if any:
if (panel == null) {
database = new BibDatabase();
localMetaData = new MetaData();
} else {
database = panel.getDatabase();
localMetaData = panel.getBibDatabaseContext().getMetaData();
}
List<Optional<String>> keys = new ArrayList<>(entries.size());
// and generate unique keys:
for (BibEntry entry : entries) {
entry.setId(IdGenerator.next());
database.insertEntry(entry);
BibtexKeyPatternUtil.makeAndSetLabel(localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), database, entry, Globals.prefs.getBibtexKeyPatternPreferences());
// Add the generated key to our list: -- TODO: Why??
keys.add(entry.getCiteKeyOptional());
}
preview.update();
preview.repaint();
// control over key uniqueness.
for (BibEntry entry : entries) {
database.removeEntry(entry);
}
} finally {
entries.getReadWriteLock().writeLock().unlock();
}
glTable.repaint();
}
use of org.jabref.model.metadata.MetaData in project jabref by JabRef.
the class BibtexDatabaseWriterTest method setUp.
@Before
public void setUp() {
// Write to a string instead of to a file
databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
database = new BibDatabase();
metaData = new MetaData();
bibtexContext = new BibDatabaseContext(database, metaData, new Defaults(BibDatabaseMode.BIBTEX));
importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Aggregations