Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fixFileDlgs
Browse files Browse the repository at this point in the history
* upstream/master:
  Do not log an exception if side pane was not found (#2791)
  Added 'Ink' to the supported FileAnnotationType (required to close #2777)
  Renamed parseFileAnnotationType() to parse()
  Fixes handling of unknown PDAnnotation types.
  • Loading branch information
Siedlerchr committed Apr 25, 2017
2 parents 1b3d27f + 4e25cc6 commit e413442
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ private static Map<Class<? extends SidePaneComponent>, Integer> getPreferredPosi
Class<? extends SidePaneComponent> componentClass = (Class<? extends SidePaneComponent>) Class.forName(componentName);
preferredPositions.put(componentClass, Integer.parseInt(componentPositions.get(i)));
} catch (ClassNotFoundException e) {
LOGGER.error("Following side pane could not be found: " + componentName, e);
LOGGER.debug("Following side pane could not be found: " + componentName, e);
} catch (ClassCastException e) {
LOGGER.error("Following Class is no side pane: '" + componentName, e);
LOGGER.debug("Following Class is no side pane: '" + componentName, e);
} catch (NumberFormatException e) {
LOGGER.info("Invalid number format for side pane component '" + componentName + "'.", e);
LOGGER.debug("Invalid number format for side pane component '" + componentName + "'.", e);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/model/pdf/FileAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -51,7 +50,7 @@ public FileAnnotation(final String author, final LocalDateTime timeModified, fin
public FileAnnotation(final PDAnnotation annotation, final int pageNumber) {
this(annotation.getDictionary().getString(COSName.T),
extractModifiedTime(annotation.getModifiedDate()),
pageNumber, annotation.getContents(), FileAnnotationType.valueOf(annotation.getSubtype().toUpperCase(Locale.ROOT)), Optional.empty());
pageNumber, annotation.getContents(), FileAnnotationType.parse(annotation), Optional.empty());
}

/**
Expand All @@ -64,7 +63,7 @@ public FileAnnotation(final PDAnnotation annotation, final int pageNumber) {
*/
public FileAnnotation(final PDAnnotation annotation, final int pageNumber, FileAnnotation linkedFileAnnotation) {
this(annotation.getDictionary().getString(COSName.T), extractModifiedTime(annotation.getModifiedDate()),
pageNumber, annotation.getContents(), FileAnnotationType.valueOf(annotation.getSubtype().toUpperCase(Locale.ROOT)), Optional.of(linkedFileAnnotation));
pageNumber, annotation.getContents(), FileAnnotationType.parse(annotation), Optional.of(linkedFileAnnotation));
}

/**
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/jabref/model/pdf/FileAnnotationType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package org.jabref.model.pdf;

import java.util.Locale;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;

/**
* Our representation of the type of the FileAnnotation. This is needed as some FileAnnotationTypes require special
* handling (e.g., Highlight or Underline), because of the linked FileAnnotations.
*/

public enum FileAnnotationType {
TEXT("Text"),
HIGHLIGHT("Highlight"),
Expand All @@ -11,14 +22,34 @@ public enum FileAnnotationType {
FREETEXT("FreeText"),
STRIKEOUT("Strikeout"),
LINK("Link"),
INK("Ink"),
UNKNOWN("Unknown"),
NONE("None");

private static final Log LOGGER = LogFactory.getLog(FileAnnotationType.class);

private final String name;

FileAnnotationType(String name) {
this.name = name;
}

/**
* Determines the FileAnnotationType of a raw PDAnnotation. Returns 'UNKNOWN' if the type is currently not in our
* list of FileAnnotationTypes.
*
* @param annotation the raw PDAnnotation
* @return The determined FileAnnotationType
*/
public static FileAnnotationType parse(PDAnnotation annotation) {
try {
return FileAnnotationType.valueOf(annotation.getSubtype().toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
LOGGER.info(String.format("FileAnnotationType %s is not supported and was converted into 'Unknown'!", annotation.getSubtype()));
return UNKNOWN;
}
}

public String toString() {
return this.name;
}
Expand Down

0 comments on commit e413442

Please sign in to comment.