/
FileAnnotationType.java
76 lines (65 loc) · 2.47 KB
/
FileAnnotationType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.jabref.model.pdf;
import java.util.Locale;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 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", false),
HIGHLIGHT("Highlight", true),
SQUIGGLY("Squiggly", true),
UNDERLINE("Underline", true),
STRIKEOUT("StrikeOut", true),
POLYGON("Polygon", false),
POPUP("Popup", false),
LINE("Line", false),
CIRCLE("Circle", false),
FREETEXT("FreeText", false),
INK("Ink", false),
UNKNOWN("Unknown", false),
NONE("None", false);
private static final Logger LOGGER = LoggerFactory.getLogger(FileAnnotationType.class);
private final String name;
private final boolean linkedFileAnnotationType;
FileAnnotationType(String name, boolean linkedFileAnnotationType) {
this.name = name;
this.linkedFileAnnotationType = linkedFileAnnotationType;
}
/**
* 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;
}
}
/**
* Determines if a String is a supported marked FileAnnotation type.
*
* @param annotationType a type descriptor
* @return true if annotationType is a supported marked FileAnnotation type
*/
public static boolean isMarkedFileAnnotationType(String annotationType) {
try {
return FileAnnotationType.valueOf(annotationType.toUpperCase(Locale.ROOT)).linkedFileAnnotationType;
} catch (IllegalArgumentException e) {
return false;
}
}
public boolean isLinkedFileAnnotationType() {
return linkedFileAnnotationType;
}
public String toString() {
return this.name;
}
}