Commit | Line | Data |
---|---|---|
0ffa4754 NR |
1 | package be.nikiroo.fanfix.supported; |
2 | ||
3 | import be.nikiroo.fanfix.Instance; | |
4 | import be.nikiroo.fanfix.bundles.StringId; | |
5 | ||
6 | /** | |
7 | * The supported input types for which we can get a {@link BasicSupport} object. | |
8 | * | |
9 | * @author niki | |
10 | */ | |
11 | public enum SupportType { | |
12 | /** EPUB files created with this program */ | |
13 | EPUB, | |
14 | /** Pure text file with some rules */ | |
15 | TEXT, | |
16 | /** TEXT but with associated .info file */ | |
17 | INFO_TEXT, | |
18 | /** My Little Pony fanfictions */ | |
19 | FIMFICTION, | |
20 | /** Fanfictions from a lot of different universes */ | |
21 | FANFICTION, | |
22 | /** Website with lots of Mangas */ | |
23 | MANGAFOX, | |
24 | /** Furry website with comics support */ | |
25 | E621, | |
26 | /** Furry website with stories */ | |
27 | YIFFSTAR, | |
28 | /** Comics and images groups, mostly but not only NSFW */ | |
29 | E_HENTAI, | |
30 | /** CBZ files */ | |
31 | CBZ, | |
32 | /** HTML files */ | |
33 | HTML; | |
34 | ||
35 | /** | |
36 | * A description of this support type (more information than the | |
37 | * {@link BasicSupport#getSourceName()}). | |
38 | * | |
39 | * @return the description | |
40 | */ | |
41 | public String getDesc() { | |
42 | String desc = Instance.getTrans().getStringX(StringId.INPUT_DESC, | |
43 | this.name()); | |
44 | ||
45 | if (desc == null) { | |
46 | desc = Instance.getTrans().getString(StringId.INPUT_DESC, this); | |
47 | } | |
48 | ||
49 | return desc; | |
50 | } | |
51 | ||
52 | /** | |
53 | * The name of this support type (a short version). | |
54 | * | |
55 | * @return the name | |
56 | */ | |
57 | public String getSourceName() { | |
58 | BasicSupport support = BasicSupport.getSupport(this, null); | |
59 | if (support != null) { | |
60 | return support.getSourceName(); | |
61 | } | |
62 | ||
63 | return null; | |
64 | } | |
65 | ||
66 | @Override | |
67 | public String toString() { | |
68 | return super.toString().toLowerCase(); | |
69 | } | |
70 | ||
71 | /** | |
72 | * Call {@link SupportType#valueOf(String)} after conversion to upper case. | |
73 | * | |
74 | * @param typeName | |
75 | * the possible type name | |
76 | * | |
77 | * @return NULL or the type | |
78 | */ | |
79 | public static SupportType valueOfUC(String typeName) { | |
80 | return SupportType.valueOf(typeName == null ? null : typeName | |
81 | .toUpperCase()); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Call {@link SupportType#valueOf(String)} after conversion to upper case | |
86 | * but return NULL for NULL instead of raising exception. | |
87 | * | |
88 | * @param typeName | |
89 | * the possible type name | |
90 | * | |
91 | * @return NULL or the type | |
92 | */ | |
93 | public static SupportType valueOfNullOkUC(String typeName) { | |
94 | if (typeName == null) { | |
95 | return null; | |
96 | } | |
97 | ||
98 | return SupportType.valueOfUC(typeName); | |
99 | } | |
100 | ||
101 | /** | |
102 | * Call {@link SupportType#valueOf(String)} after conversion to upper case | |
103 | * but return NULL in case of error instead of raising an exception. | |
104 | * | |
105 | * @param typeName | |
106 | * the possible type name | |
107 | * | |
108 | * @return NULL or the type | |
109 | */ | |
110 | public static SupportType valueOfAllOkUC(String typeName) { | |
111 | try { | |
112 | return SupportType.valueOfUC(typeName); | |
113 | } catch (Exception e) { | |
114 | return null; | |
115 | } | |
116 | } | |
117 | } |