use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class RisKeywords method format.
@Override
public String format(String s) {
if (s == null) {
return "";
}
StringBuilder sb = new StringBuilder();
KeywordList keywords = KeywordList.parse(s, ',');
int i = 0;
for (Keyword keyword : keywords) {
sb.append("KW - ");
sb.append(keyword.toString());
if (i < (keywords.size() - 1)) {
sb.append(OS.NEWLINE);
}
i++;
}
return sb.toString();
}
use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class SpecialFieldsUtils method syncSpecialFieldsFromKeywords.
/**
* Updates special field values according to keywords
*/
public static List<FieldChange> syncSpecialFieldsFromKeywords(BibEntry entry, Character keywordDelimiter) {
List<FieldChange> fieldChanges = new ArrayList<>();
if (!entry.hasField(FieldName.KEYWORDS)) {
return fieldChanges;
}
KeywordList keywordList = entry.getKeywords(keywordDelimiter);
for (SpecialField field : SpecialField.values()) {
fieldChanges.addAll(SpecialFieldsUtils.importKeywordsForField(keywordList, field, entry));
}
return fieldChanges;
}
use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class SpecialFieldsUtils method importKeywordsForField.
private static List<FieldChange> importKeywordsForField(KeywordList keywordList, SpecialField field, BibEntry entry) {
List<FieldChange> fieldChanges = new ArrayList<>();
KeywordList values = field.getKeyWords();
Optional<Keyword> newValue = Optional.empty();
for (Keyword keyword : values) {
if (keywordList.contains(keyword)) {
newValue = Optional.of(keyword);
break;
}
}
UpdateField.updateNonDisplayableField(entry, field.getFieldName(), newValue.map(Keyword::toString).orElse(null)).ifPresent(fieldChange -> {
fieldChanges.add(fieldChange);
});
return fieldChanges;
}
use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class SpecialFieldsUtils method synchronizeSpecialFields.
public static void synchronizeSpecialFields(KeywordList keywordsToAdd, KeywordList keywordsToRemove) {
// we need to check whether a special field is added
// for each field:
// check if something is added
// if yes, add all keywords of that special fields to the keywords to be removed
KeywordList clone;
// Priority
clone = keywordsToAdd.createClone();
for (SpecialField field : SpecialField.values()) {
clone.retainAll(field.getKeyWords());
if (!clone.isEmpty()) {
keywordsToRemove.addAll(field.getKeyWords());
}
}
}
use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class WordKeywordGroup method add.
@Override
public List<FieldChange> add(List<BibEntry> entriesToAdd) {
Objects.requireNonNull(entriesToAdd);
List<FieldChange> changes = new ArrayList<>();
for (BibEntry entry : entriesToAdd) {
if (!contains(entry)) {
String oldContent = entry.getField(searchField).orElse("");
KeywordList wordlist = KeywordList.parse(oldContent, keywordSeparator);
wordlist.add(searchExpression);
String newContent = wordlist.getAsString(keywordSeparator);
entry.setField(searchField, newContent).ifPresent(changes::add);
}
}
return changes;
}
Aggregations