separate support name and BasicSupport
[fanfix.git] / src / be / nikiroo / fanfix / supported / SupportType.java
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 /** Website with lots of Mangas, in French */
31 MANGA_LEL,
32 /** CBZ files */
33 CBZ,
34 /** HTML files */
35 HTML;
36
37 /**
38 * The name of this support type (a short version).
39 *
40 * @return the name
41 */
42 public String getSourceName() {
43 switch (this) {
44 case CBZ:
45 return "cbz";
46 case E621:
47 return "e621.net";
48 case E_HENTAI:
49 return "e-hentai.org";
50 case EPUB:
51 return "epub";
52 case FANFICTION:
53 return "Fanfiction.net";
54 case FIMFICTION:
55 return "FimFiction.net";
56 case HTML:
57 return "html";
58 case INFO_TEXT:
59 return "info-text";
60 case MANGA_LEL:
61 return "MangaLel.com";
62 case MANGAFOX:
63 return "MangaFox.me";
64 case TEXT:
65 return "text";
66 case YIFFSTAR:
67 return "YiffStar";
68 }
69
70 return "";
71 }
72
73 /**
74 * A description of this support type (more information than
75 * {@link SupportType#getSourceName()}).
76 *
77 * @return the description
78 */
79 public String getDesc() {
80 String desc = Instance.getTrans().getStringX(StringId.INPUT_DESC,
81 this.name());
82
83 if (desc == null) {
84 desc = Instance.getTrans().getString(StringId.INPUT_DESC, this);
85 }
86
87 return desc;
88 }
89
90 @Override
91 public String toString() {
92 return super.toString().toLowerCase();
93 }
94
95 /**
96 * Call {@link SupportType#valueOf(String)} after conversion to upper case.
97 *
98 * @param typeName
99 * the possible type name
100 *
101 * @return NULL or the type
102 */
103 public static SupportType valueOfUC(String typeName) {
104 return SupportType.valueOf(typeName == null ? null : typeName
105 .toUpperCase());
106 }
107
108 /**
109 * Call {@link SupportType#valueOf(String)} after conversion to upper case
110 * but return NULL for NULL instead of raising exception.
111 *
112 * @param typeName
113 * the possible type name
114 *
115 * @return NULL or the type
116 */
117 public static SupportType valueOfNullOkUC(String typeName) {
118 if (typeName == null) {
119 return null;
120 }
121
122 return SupportType.valueOfUC(typeName);
123 }
124
125 /**
126 * Call {@link SupportType#valueOf(String)} after conversion to upper case
127 * but return NULL in case of error instead of raising an exception.
128 *
129 * @param typeName
130 * the possible type name
131 *
132 * @return NULL or the type
133 */
134 public static SupportType valueOfAllOkUC(String typeName) {
135 try {
136 return SupportType.valueOfUC(typeName);
137 } catch (Exception e) {
138 return null;
139 }
140 }
141 }