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());
}
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();
}
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;
}
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));
}
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);
}
Aggregations