Search in sources :

Example 16 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class DBMSSynchronizerTest method testApplyMetaData.

@Test
public void testApplyMetaData() {
    BibEntry bibEntry = getBibEntryExample(1);
    bibDatabase.insertEntry(bibEntry);
    MetaData testMetaData = new MetaData();
    testMetaData.setSaveActions(new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup("author", new LowerCaseFormatter()))));
    dbmsSynchronizer.setMetaData(testMetaData);
    dbmsSynchronizer.applyMetaData();
    Assert.assertEquals("wirthlin, michael j1", bibEntry.getField("author").get());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) MetaData(org.jabref.model.metadata.MetaData) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 17 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class FieldFormatterCleanupsPanel method getSelectorPanel.

/**
     * This panel contains the two comboboxes and the Add button
     * @return Returns the created JPanel
     */
private JPanel getSelectorPanel() {
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref:grow, 4dlu, left:pref:grow, 4dlu, fill:pref:grow, 4dlu, right:pref", "fill:pref:grow, 2dlu, pref, 2dlu"));
    List<String> fieldNames = InternalBibtexFields.getAllPublicAndInternalFieldNames();
    fieldNames.add(BibEntry.KEY_FIELD);
    Collections.sort(fieldNames);
    String[] allPlusKey = fieldNames.toArray(new String[fieldNames.size()]);
    selectFieldCombobox = new JComboBox<>(allPlusKey);
    selectFieldCombobox.setEditable(true);
    builder.add(selectFieldCombobox).xy(1, 1);
    List<String> formatterNames = Cleanups.getAvailableFormatters().stream().map(Formatter::getName).collect(Collectors.toList());
    List<String> formatterDescriptions = Cleanups.getAvailableFormatters().stream().map(Formatter::getDescription).collect(Collectors.toList());
    formattersCombobox = new JComboBox<>(formatterNames.toArray());
    formattersCombobox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if ((-1 < index) && (index < formatterDescriptions.size()) && (value != null)) {
                setToolTipText(formatterDescriptions.get(index));
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    formattersCombobox.addItemListener(e -> updateDescription());
    builder.add(formattersCombobox).xy(3, 1);
    addButton = new JButton(Localization.lang("Add"));
    addButton.addActionListener(e -> {
        FieldFormatterCleanup newAction = getFieldFormatterCleanup();
        if (newAction == null) {
            return;
        }
        ((CleanupActionsListModel) actionsList.getModel()).addCleanupAction(newAction);
    });
    builder.add(addButton).xy(5, 1);
    return builder.getPanel();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) Component(java.awt.Component)

Example 18 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class Cleanups method parse.

public static List<FieldFormatterCleanup> parse(String formatterString) {
    if ((formatterString == null) || formatterString.isEmpty()) {
        // no save actions defined in the meta data
        return new ArrayList<>();
    }
    List<FieldFormatterCleanup> actions = new ArrayList<>();
    //read concrete actions
    int startIndex = 0;
    // first remove all newlines for easier parsing
    String remainingString = formatterString;
    remainingString = StringUtil.unifyLineBreaks(remainingString, "");
    try {
        while (startIndex < formatterString.length()) {
            // read the field name
            int currentIndex = remainingString.indexOf('[');
            String fieldKey = remainingString.substring(0, currentIndex);
            int endIndex = remainingString.indexOf(']');
            startIndex += endIndex + 1;
            //read each formatter
            int tokenIndex = remainingString.indexOf(',');
            do {
                boolean doBreak = false;
                if ((tokenIndex == -1) || (tokenIndex > endIndex)) {
                    tokenIndex = remainingString.indexOf(']');
                    doBreak = true;
                }
                String formatterKey = remainingString.substring(currentIndex + 1, tokenIndex);
                actions.add(new FieldFormatterCleanup(fieldKey, getFormatterFromString(formatterKey)));
                remainingString = remainingString.substring(tokenIndex + 1);
                if (remainingString.startsWith("]") || doBreak) {
                    break;
                }
                tokenIndex = remainingString.indexOf(',');
                currentIndex = -1;
            } while (true);
        }
    } catch (StringIndexOutOfBoundsException ignore) {
        // Thus we stop parsing and take what we have parsed until now
        return actions;
    }
    return actions;
}
Also used : ArrayList(java.util.ArrayList) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup)

Example 19 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class DoiCleanup method removeFieldValue.

private void removeFieldValue(BibEntry entry, String field, List<FieldChange> changes) {
    CleanupJob eraser = new FieldFormatterCleanup(field, new ClearFormatter());
    changes.addAll(eraser.cleanup(entry));
}
Also used : FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) ClearFormatter(org.jabref.logic.formatter.bibtexfields.ClearFormatter) CleanupJob(org.jabref.model.cleanup.CleanupJob)

Example 20 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class MedlineFetcher method doPostCleanup.

@Override
public void doPostCleanup(BibEntry entry) {
    new FieldFormatterCleanup("journal-abbreviation", new ClearFormatter()).cleanup(entry);
    new FieldFormatterCleanup("status", new ClearFormatter()).cleanup(entry);
    new FieldFormatterCleanup("copyright", new ClearFormatter()).cleanup(entry);
    new FieldFormatterCleanup(FieldName.MONTH, new NormalizeMonthFormatter()).cleanup(entry);
}
Also used : NormalizeMonthFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) ClearFormatter(org.jabref.logic.formatter.bibtexfields.ClearFormatter)

Aggregations

FieldFormatterCleanup (org.jabref.model.cleanup.FieldFormatterCleanup)33 Test (org.junit.Test)22 FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)20 LowerCaseFormatter (org.jabref.logic.formatter.casechanger.LowerCaseFormatter)10 BibEntry (org.jabref.model.entry.BibEntry)9 ClearFormatter (org.jabref.logic.formatter.bibtexfields.ClearFormatter)7 NormalizePagesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)5 MoveFieldCleanup (org.jabref.logic.cleanup.MoveFieldCleanup)3 IdentityFormatter (org.jabref.logic.formatter.IdentityFormatter)3 NormalizeDateFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter)3 NormalizeMonthFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter)3 StringReader (java.io.StringReader)2 NormalizeNamesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter)2 RemoveBracesFormatter (org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter)2 UpperCaseFormatter (org.jabref.logic.formatter.casechanger.UpperCaseFormatter)2 ParserResult (org.jabref.logic.importer.ParserResult)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1