use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class BibDatabaseModeDetectionTest method ignoreUnknownTypesForBibtexDecision.
@Test
public void ignoreUnknownTypesForBibtexDecision() {
BibEntry custom = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0)).getName());
BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE.getName());
BibEntry biblatex = new BibEntry(BiblatexEntryTypes.ARTICLE.getName());
Collection<BibEntry> entries = Arrays.asList(custom, bibtex, biblatex);
assertEquals(BibDatabaseMode.BIBTEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries)));
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class EntryTypesTest method overwriteCustomEntryTypeFields.
@Test
public void overwriteCustomEntryTypeFields() {
EntryTypes.addOrModifyCustomEntryType(newCustomType, mode);
CustomEntryType newCustomEntryTypeAuthorRequired = new CustomEntryType("customType", FieldName.AUTHOR, "optional");
EntryTypes.addOrModifyCustomEntryType(newCustomEntryTypeAuthorRequired, mode);
assertEquals(Optional.of(newCustomEntryTypeAuthorRequired), EntryTypes.getType("customType", mode));
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class CheckForNewEntryTypesAction method performAction.
@Override
public void performAction(BasePanel panel, ParserResult parserResult) {
BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult);
List<EntryType> typesToStore = determineEntryTypesToSave(panel, getListOfUnknownAndUnequalCustomizations(parserResult), mode);
if (!typesToStore.isEmpty()) {
typesToStore.forEach(type -> EntryTypes.addOrModifyCustomEntryType((CustomEntryType) type, mode));
CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
}
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class JabRefPreferences method loadCustomEntryTypes.
public List<CustomEntryType> loadCustomEntryTypes(BibDatabaseMode bibDatabaseMode) {
List<CustomEntryType> storedEntryTypes = new ArrayList<>();
Preferences prefsNode = getPrefsNodeForCustomizedEntryTypes(bibDatabaseMode);
try {
Arrays.stream(prefsNode.keys()).map(key -> prefsNode.get(key, null)).filter(Objects::nonNull).forEach(typeString -> CustomEntryType.parse(typeString).ifPresent(storedEntryTypes::add));
} catch (BackingStoreException e) {
LOGGER.info("Parsing customized entry types failed.", e);
}
return storedEntryTypes;
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class BibtexDatabaseWriterTest method writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration.
@Test
public void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception {
try {
EntryTypes.addOrModifyCustomEntryType(new CustomEntryType("customizedType", "required", "optional"), BibDatabaseMode.BIBTEX);
BibEntry entry = new BibEntry();
entry.setType("customizedType");
database.insertEntry(entry);
StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.singletonList(entry), new SavePreferences());
assertEquals(OS.NEWLINE + "@Customizedtype{," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-entrytype: Customizedtype: req[required] opt[optional]}" + OS.NEWLINE, session.getStringValue());
} finally {
EntryTypes.removeAllCustomEntryTypes();
}
}
Aggregations