use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class BasePanel method insertEntry.
/**
* This method is called from JabRefFrame when the user wants to create a new entry.
*
* @param bibEntry The new entry.
*/
public void insertEntry(final BibEntry bibEntry) {
if (bibEntry != null) {
try {
bibDatabaseContext.getDatabase().insertEntry(bibEntry);
if (Globals.prefs.getBoolean(JabRefPreferences.USE_OWNER)) {
// Set owner field to default value
UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs.getUpdateFieldPreferences());
}
// Create an UndoableInsertEntry object.
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), bibEntry, BasePanel.this));
output(Localization.lang("Added new '%0' entry.", bibEntry.getType()));
// The database just changed.
markBaseChanged();
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) {
selectionListener.editSignalled(bibEntry);
}
highlightEntry(bibEntry);
} catch (KeyCollisionException ex) {
LOGGER.info("Collision for bibtex key" + bibEntry.getId(), ex);
}
}
}
use of org.jabref.model.database.KeyCollisionException 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;
}
use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class StringNameChange method makeChange.
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
if (panel.getDatabase().hasStringLabel(disk)) {
// The name to change to is already in the database, so we can't comply.
LOGGER.info("Cannot rename string '" + mem + "' to '" + disk + "' because the name " + "is already in use.");
}
if (string == null) {
// The string was removed or renamed locally. We guess that it was removed.
BibtexString bs = new BibtexString(disk, content);
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.setName(disk);
undoEdit.addEdit(new UndoableStringChange(panel, string, true, mem, disk));
}
// Update tmp database:
if (tmpString == null) {
BibtexString bs = new BibtexString(disk, content);
secondary.addString(bs);
} else {
tmpString.setName(disk);
}
return true;
}
use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class ImportMenuItem method mergeImportResults.
private ParserResult mergeImportResults(List<ImportFormatReader.UnknownFormatImport> imports) {
BibDatabase database = new BibDatabase();
ParserResult directParserResult = null;
boolean anythingUseful = false;
for (ImportFormatReader.UnknownFormatImport importResult : imports) {
if (importResult == null) {
continue;
}
if (ImportFormatReader.BIBTEX_FORMAT.equals(importResult.format)) {
// Bibtex result. We must merge it into our main base.
ParserResult pr = importResult.parserResult;
anythingUseful = anythingUseful || pr.getDatabase().hasEntries() || (!pr.getDatabase().hasNoStrings());
// Record the parserResult, as long as this is the first bibtex result:
if (directParserResult == null) {
directParserResult = pr;
}
// Merge entries:
for (BibEntry entry : pr.getDatabase().getEntries()) {
database.insertEntry(entry);
}
// Merge strings:
for (BibtexString bs : pr.getDatabase().getStringValues()) {
try {
database.addString((BibtexString) bs.clone());
} catch (KeyCollisionException e) {
// TODO: This means a duplicate string name exists, so it's not
// a very exceptional situation. We should maybe give a warning...?
}
}
} else {
ParserResult pr = importResult.parserResult;
Collection<BibEntry> entries = pr.getDatabase().getEntries();
anythingUseful = anythingUseful | !entries.isEmpty();
// set timestamp and owner
// set timestamp and owner
UpdateField.setAutomaticFields(entries, Globals.prefs.getUpdateFieldPreferences());
boolean markEntries = !openInNew && EntryMarker.shouldMarkEntries();
for (BibEntry entry : entries) {
if (markEntries) {
EntryMarker.markEntry(entry, EntryMarker.IMPORT_MARK_LEVEL, false, new NamedCompound(""));
}
database.insertEntry(entry);
}
}
}
if (!anythingUseful) {
return null;
}
if ((imports.size() == 1) && (directParserResult != null)) {
return directParserResult;
} else {
return new ParserResult(database);
}
}
use of org.jabref.model.database.KeyCollisionException in project jabref by JabRef.
the class BibtexParser method parse.
/**
* Will parse the BibTex-Data found when reading from reader. Ignores any encoding supplied in the file by
* "Encoding: myEncoding".
* <p>
* The reader will be consumed.
* <p>
* Multiple calls to parse() return the same results
*
* @return ParserResult
* @throws IOException
*/
public ParserResult parse(Reader in) throws IOException {
Objects.requireNonNull(in);
pushbackReader = new PushbackReader(in, BibtexParser.LOOKAHEAD);
// Bibtex related contents.
initializeParserResult();
parseDatabaseID();
skipWhitespace();
try {
return parseFileContent();
} catch (KeyCollisionException kce) {
throw new IOException("Duplicate ID in bibtex file: " + kce);
}
}
Aggregations