Skip to content

Commit

Permalink
add meaningful names in DublinCoreExtractor and use StringUtils.isNul…
Browse files Browse the repository at this point in the history
…lOrEmpty
  • Loading branch information
johannes-manner committed Feb 16, 2018
1 parent 9cc529f commit 366aeed
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.Month;
import org.jabref.model.strings.StringUtil;

import com.microsoft.applicationinsights.agent.internal.common.StringUtils;
import org.apache.xmpbox.DateConverter;
import org.apache.xmpbox.schema.DublinCoreSchema;

Expand Down Expand Up @@ -69,16 +71,16 @@ private void extractYearAndMonth() {
List<String> dates = dcSchema.getUnqualifiedSequenceValueList("date");
if ((dates != null) && !dates.isEmpty()) {
String date = dates.get(0).trim();
Calendar c = null;
Calendar calender = null;
try {
c = DateConverter.toCalendar(date);
calender = DateConverter.toCalendar(date);
} catch (IOException ignored) {
// Ignored
}
if (c != null) {
bibEntry.setField(FieldName.YEAR, String.valueOf(c.get(Calendar.YEAR)));
if (calender != null) {
bibEntry.setField(FieldName.YEAR, String.valueOf(calender.get(Calendar.YEAR)));
if (date.length() > 4) {
Optional<Month> month = Month.getMonthByNumber(c.get(Calendar.MONTH) + 1);
Optional<Month> month = Month.getMonthByNumber(calender.get(Calendar.MONTH) + 1);
month.ifPresent(bibEntry::setMonth);
}
}
Expand All @@ -92,9 +94,9 @@ private void extractYearAndMonth() {
* @param dcSchema Metadata in DublinCore format.
*/
private void extractAbstract() {
String s = dcSchema.getDescription();
if (s != null) {
bibEntry.setField(FieldName.ABSTRACT, s);
String description = dcSchema.getDescription();
if (!StringUtil.isNullOrEmpty(description)) {
bibEntry.setField(FieldName.ABSTRACT, description);
}
}

Expand All @@ -105,9 +107,9 @@ private void extractAbstract() {
* @param dcSchema Metadata in DublinCore format.
*/
private void extractDOI() {
String s = dcSchema.getIdentifier();
if (s != null) {
bibEntry.setField(FieldName.DOI, s);
String identifier = dcSchema.getIdentifier();
if (!StringUtils.isNullOrEmpty(identifier)) {
bibEntry.setField(FieldName.DOI, identifier);
}
}

Expand Down Expand Up @@ -154,9 +156,9 @@ private void extractBibTexFields() {
* @param dcSchema Metadata in DublinCore format.
*/
private void extractRights() {
String s = dcSchema.getRights();
if (s != null) {
bibEntry.setField("rights", s);
String rights = dcSchema.getRights();
if (!StringUtils.isNullOrEmpty(rights)) {
bibEntry.setField("rights", rights);
}
}

Expand All @@ -167,9 +169,9 @@ private void extractRights() {
* @param dcSchema Metadata in DublinCore format.
*/
private void extractSource() {
String s = dcSchema.getSource();
if (s != null) {
bibEntry.setField("source", s);
String source = dcSchema.getSource();
if (!StringUtils.isNullOrEmpty(source)) {
bibEntry.setField("source", source);
}
}

Expand All @@ -180,7 +182,7 @@ private void extractSource() {
*/
private void extractSubject() {
List<String> subjects = dcSchema.getSubjects();
if (subjects != null) {
if ((subjects != null) && !subjects.isEmpty()) {
bibEntry.addKeywords(subjects, xmpPreferences.getKeywordSeparator());
}
}
Expand All @@ -192,9 +194,9 @@ private void extractSubject() {
* @param dcSchema Metadata in DublinCore format.
*/
private void extractTitle() {
String s = dcSchema.getTitle();
if (s != null) {
bibEntry.setField(FieldName.TITLE, s);
String title = dcSchema.getTitle();
if (!StringUtil.isNullOrEmpty(title)) {
bibEntry.setField(FieldName.TITLE, title);
}
}

Expand All @@ -205,11 +207,11 @@ private void extractTitle() {
* @param dcSchema Metadata in DublinCore format.
*/
private void extractType() {
List<String> l = dcSchema.getTypes();
if ((l != null) && !l.isEmpty()) {
String s = l.get(0);
if (s != null) {
bibEntry.setType(s);
List<String> types = dcSchema.getTypes();
if ((types != null) && !types.isEmpty()) {

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Feb 16, 2018

Member

Gotcha :-P

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Feb 16, 2018

Member

We even have an overloaded of that is null or empty which also works on optoinals

This comment has been minimized.

Copy link
@johannes-manner

johannes-manner Feb 16, 2018

Author Collaborator

I need a method that works for Collections/ Lists?

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Feb 16, 2018

Member

Ah oversaw that. My fault 🤦‍♂️

String type = types.get(0);
if (!StringUtils.isNullOrEmpty(type)) {
bibEntry.setType(type);
}
}
}
Expand Down

0 comments on commit 366aeed

Please sign in to comment.