use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.
the class CleanupPreset method loadFromPreferences.
public static CleanupPreset loadFromPreferences(JabRefPreferences preferences) {
Set<CleanupStep> activeJobs = EnumSet.noneOf(CleanupStep.class);
if (preferences.getBoolean(JabRefPreferences.CLEANUP_DOI)) {
activeJobs.add(CleanupStep.CLEAN_UP_DOI);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_ISSN)) {
activeJobs.add(CleanupStep.CLEAN_UP_ISSN);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_MOVE_PDF)) {
activeJobs.add(CleanupStep.MOVE_PDF);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_MAKE_PATHS_RELATIVE)) {
activeJobs.add(CleanupStep.MAKE_PATHS_RELATIVE);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_RENAME_PDF)) {
activeJobs.add(CleanupStep.RENAME_PDF);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_RENAME_PDF_ONLY_RELATIVE_PATHS)) {
activeJobs.add(CleanupStep.RENAME_PDF_ONLY_RELATIVE_PATHS);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_UPGRADE_EXTERNAL_LINKS)) {
activeJobs.add(CleanupStep.CLEAN_UP_UPGRADE_EXTERNAL_LINKS);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_CONVERT_TO_BIBLATEX)) {
activeJobs.add(CleanupStep.CONVERT_TO_BIBLATEX);
}
if (preferences.getBoolean(JabRefPreferences.CLEANUP_FIX_FILE_LINKS)) {
activeJobs.add(CleanupStep.FIX_FILE_LINKS);
}
FieldFormatterCleanups formatterCleanups = Cleanups.parse(preferences.getStringList(JabRefPreferences.CLEANUP_FORMATTERS));
return new CleanupPreset(activeJobs, formatterCleanups);
}
use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.
the class BibDatabaseWriter method applySaveActions.
private static List<FieldChange> applySaveActions(List<BibEntry> toChange, MetaData metaData) {
List<FieldChange> changes = new ArrayList<>();
Optional<FieldFormatterCleanups> saveActions = metaData.getSaveActions();
saveActions.ifPresent(actions -> {
for (BibEntry entry : toChange) {
changes.addAll(actions.applySaveActions(entry));
}
});
return changes;
}
use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.
the class CleanupActionsListModelTest method resetFiresItemsChanged.
@Test
public void resetFiresItemsChanged() throws Exception {
CleanupActionsListModel model = new CleanupActionsListModel(Collections.emptyList());
ListDataListener listener = mock(ListDataListener.class);
model.addListDataListener(listener);
FieldFormatterCleanups defaultFormatters = mock(FieldFormatterCleanups.class);
model.reset(defaultFormatters);
ArgumentCaptor<ListDataEvent> argument = ArgumentCaptor.forClass(ListDataEvent.class);
verify(listener).contentsChanged(argument.capture());
assertEquals(ListDataEvent.CONTENTS_CHANGED, argument.getValue().getType());
}
use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.
the class CleanupWorkerTest method cleanupWithDisabledFieldFormatterChangesNothing.
@Test
public void cleanupWithDisabledFieldFormatterChangesNothing() {
CleanupPreset preset = new CleanupPreset(new FieldFormatterCleanups(false, Collections.singletonList(new FieldFormatterCleanup("month", new NormalizeMonthFormatter()))));
BibEntry entry = new BibEntry();
entry.setField("month", "01");
worker.cleanup(preset, entry);
Assert.assertEquals(Optional.of("01"), entry.getField("month"));
}
use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.
the class CleanupWorkerTest method cleanupUnitsConvertsOneAmpereToLatex.
@Test
public void cleanupUnitsConvertsOneAmpereToLatex() {
CleanupPreset preset = new CleanupPreset(new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup("title", new UnitsToLatexFormatter()))));
BibEntry entry = new BibEntry();
entry.setField("title", "1 A");
worker.cleanup(preset, entry);
Assert.assertEquals(Optional.of("1~{A}"), entry.getField("title"));
}
Aggregations