Search in sources :

Example 1 with FieldFormatterCleanups

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);
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups)

Example 2 with FieldFormatterCleanups

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;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups)

Example 3 with FieldFormatterCleanups

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());
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) CleanupActionsListModel(org.jabref.gui.cleanup.CleanupActionsListModel) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) ListDataListener(javax.swing.event.ListDataListener) Test(org.junit.Test)

Example 4 with FieldFormatterCleanups

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"));
}
Also used : NormalizeMonthFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter) BibEntry(org.jabref.model.entry.BibEntry) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) Test(org.junit.Test)

Example 5 with FieldFormatterCleanups

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"));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) UnitsToLatexFormatter(org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter) Test(org.junit.Test)

Aggregations

FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)26 Test (org.junit.Test)23 FieldFormatterCleanup (org.jabref.model.cleanup.FieldFormatterCleanup)20 LowerCaseFormatter (org.jabref.logic.formatter.casechanger.LowerCaseFormatter)10 BibEntry (org.jabref.model.entry.BibEntry)10 IdentityFormatter (org.jabref.logic.formatter.IdentityFormatter)3 NormalizeDateFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter)3 NormalizePagesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)3 StringReader (java.io.StringReader)2 CleanupActionsListModel (org.jabref.gui.cleanup.CleanupActionsListModel)2 NormalizeMonthFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter)2 ParserResult (org.jabref.logic.importer.ParserResult)2 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 ListDataEvent (javax.swing.event.ListDataEvent)1 ListDataListener (javax.swing.event.ListDataListener)1 ClearFormatter (org.jabref.logic.formatter.bibtexfields.ClearFormatter)1 HtmlToLatexFormatter (org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter)1 LatexCleanupFormatter (org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter)1 UnitsToLatexFormatter (org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter)1