| 1 | package be.nikiroo.fanfix.data; |
| 2 | |
| 3 | import java.awt.image.BufferedImage; |
| 4 | import java.util.ArrayList; |
| 5 | import java.util.List; |
| 6 | |
| 7 | /** |
| 8 | * The meta data associated to a {@link Story} object. |
| 9 | * |
| 10 | * @author niki |
| 11 | */ |
| 12 | public class MetaData implements Cloneable, Comparable<MetaData> { |
| 13 | private String title; |
| 14 | private String author; |
| 15 | private String date; |
| 16 | private Chapter resume; |
| 17 | private List<String> tags; |
| 18 | private BufferedImage cover; |
| 19 | private String subject; |
| 20 | private String source; |
| 21 | private String url; |
| 22 | private String uuid; |
| 23 | private String luid; |
| 24 | private String lang; |
| 25 | private String publisher; |
| 26 | private String type; |
| 27 | private boolean imageDocument; |
| 28 | private long words; |
| 29 | private String creationDate; |
| 30 | |
| 31 | /** |
| 32 | * The title of the story. |
| 33 | * |
| 34 | * @return the title |
| 35 | */ |
| 36 | public String getTitle() { |
| 37 | return title; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * The title of the story. |
| 42 | * |
| 43 | * @param title |
| 44 | * the title to set |
| 45 | */ |
| 46 | public void setTitle(String title) { |
| 47 | this.title = title; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * The author of the story. |
| 52 | * |
| 53 | * @return the author |
| 54 | */ |
| 55 | public String getAuthor() { |
| 56 | return author; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * The author of the story. |
| 61 | * |
| 62 | * @param author |
| 63 | * the author to set |
| 64 | */ |
| 65 | public void setAuthor(String author) { |
| 66 | this.author = author; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * The story publication date. |
| 71 | * |
| 72 | * @return the date |
| 73 | */ |
| 74 | public String getDate() { |
| 75 | return date; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * The story publication date. |
| 80 | * |
| 81 | * @param date |
| 82 | * the date to set |
| 83 | */ |
| 84 | public void setDate(String date) { |
| 85 | this.date = date; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * The tags associated with this story. |
| 90 | * |
| 91 | * @return the tags |
| 92 | */ |
| 93 | public List<String> getTags() { |
| 94 | return tags; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * The tags associated with this story. |
| 99 | * |
| 100 | * @param tags |
| 101 | * the tags to set |
| 102 | */ |
| 103 | public void setTags(List<String> tags) { |
| 104 | this.tags = tags; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * The story resume (a.k.a. description). |
| 109 | * |
| 110 | * @return the resume |
| 111 | */ |
| 112 | public Chapter getResume() { |
| 113 | return resume; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * The story resume (a.k.a. description). |
| 118 | * |
| 119 | * @param resume |
| 120 | * the resume to set |
| 121 | */ |
| 122 | public void setResume(Chapter resume) { |
| 123 | this.resume = resume; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * The cover image of the story if any (can be NULL). |
| 128 | * |
| 129 | * @return the cover |
| 130 | */ |
| 131 | public BufferedImage getCover() { |
| 132 | return cover; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * The cover image of the story if any (can be NULL). |
| 137 | * |
| 138 | * @param cover |
| 139 | * the cover to set |
| 140 | */ |
| 141 | public void setCover(BufferedImage cover) { |
| 142 | this.cover = cover; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * The subject of the story (or instance, if it is a fanfiction, what is the |
| 147 | * original work; if it is a technical text, what is the technical |
| 148 | * subject...). |
| 149 | * |
| 150 | * @return the subject |
| 151 | */ |
| 152 | public String getSubject() { |
| 153 | return subject; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * The subject of the story (for instance, if it is a fanfiction, what is |
| 158 | * the original work; if it is a technical text, what is the technical |
| 159 | * subject...). |
| 160 | * |
| 161 | * @param subject |
| 162 | * the subject to set |
| 163 | */ |
| 164 | public void setSubject(String subject) { |
| 165 | this.subject = subject; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * The source of this story (which online library it was downloaded from). |
| 170 | * |
| 171 | * @return the source |
| 172 | */ |
| 173 | public String getSource() { |
| 174 | return source; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * The source of this story (which online library it was downloaded from). |
| 179 | * |
| 180 | * @param source |
| 181 | * the source to set |
| 182 | */ |
| 183 | public void setSource(String source) { |
| 184 | this.source = source; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * The original URL from which this {@link Story} was imported. |
| 189 | * |
| 190 | * @return the url |
| 191 | */ |
| 192 | public String getUrl() { |
| 193 | return url; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * The original URL from which this {@link Story} was imported. |
| 198 | * |
| 199 | * @param url |
| 200 | * the new url to set |
| 201 | */ |
| 202 | public void setUrl(String url) { |
| 203 | this.url = url; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * A unique value representing the story (it is often a URL). |
| 208 | * |
| 209 | * @return the uuid |
| 210 | */ |
| 211 | public String getUuid() { |
| 212 | return uuid; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * A unique value representing the story (it is often a URL). |
| 217 | * |
| 218 | * @param uuid |
| 219 | * the uuid to set |
| 220 | */ |
| 221 | public void setUuid(String uuid) { |
| 222 | this.uuid = uuid; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * A unique value representing the story in the local library. |
| 227 | * |
| 228 | * @return the luid |
| 229 | */ |
| 230 | public String getLuid() { |
| 231 | return luid; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * A unique value representing the story in the local library. |
| 236 | * |
| 237 | * @param uuid |
| 238 | * the luid to set |
| 239 | */ |
| 240 | public void setLuid(String luid) { |
| 241 | this.luid = luid; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * The 2-letter code language of this story. |
| 246 | * |
| 247 | * @return the lang |
| 248 | */ |
| 249 | public String getLang() { |
| 250 | return lang; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * The 2-letter code language of this story. |
| 255 | * |
| 256 | * @param lang |
| 257 | * the lang to set |
| 258 | */ |
| 259 | public void setLang(String lang) { |
| 260 | this.lang = lang; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * The story publisher (other the same as the source). |
| 265 | * |
| 266 | * @return the publisher |
| 267 | */ |
| 268 | public String getPublisher() { |
| 269 | return publisher; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * The story publisher (other the same as the source). |
| 274 | * |
| 275 | * @param publisher |
| 276 | * the publisher to set |
| 277 | */ |
| 278 | public void setPublisher(String publisher) { |
| 279 | this.publisher = publisher; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * The output type this {@link Story} is in. |
| 284 | * |
| 285 | * @return the type the type |
| 286 | */ |
| 287 | public String getType() { |
| 288 | return type; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * The output type this {@link Story} is in. |
| 293 | * |
| 294 | * @param type |
| 295 | * the new type to set |
| 296 | */ |
| 297 | public void setType(String type) { |
| 298 | this.type = type; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Document catering mostly to image files. |
| 303 | * |
| 304 | * @return the imageDocument state |
| 305 | */ |
| 306 | public boolean isImageDocument() { |
| 307 | return imageDocument; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Document catering mostly to image files. |
| 312 | * |
| 313 | * @param imageDocument |
| 314 | * the imageDocument state to set |
| 315 | */ |
| 316 | public void setImageDocument(boolean imageDocument) { |
| 317 | this.imageDocument = imageDocument; |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * The number of words in the related {@link Story}. |
| 322 | * |
| 323 | * @return the number of words |
| 324 | */ |
| 325 | public long getWords() { |
| 326 | return words; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * The number of words in the related {@link Story}. |
| 331 | * |
| 332 | * @param words |
| 333 | * the number of words to set |
| 334 | */ |
| 335 | public void setWords(long words) { |
| 336 | this.words = words; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * The (Fanfix) {@link Story} creation date. |
| 341 | * |
| 342 | * @return the creationDate |
| 343 | */ |
| 344 | public String getCreationDate() { |
| 345 | return creationDate; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * The (Fanfix) {@link Story} creation date. |
| 350 | * |
| 351 | * @param creationDate |
| 352 | * the creationDate to set |
| 353 | */ |
| 354 | public void setCreationDate(String creationDate) { |
| 355 | this.creationDate = creationDate; |
| 356 | } |
| 357 | |
| 358 | public int compareTo(MetaData o) { |
| 359 | String oUuid = o == null ? null : o.getUuid(); |
| 360 | return getUuid().compareTo(oUuid); |
| 361 | } |
| 362 | |
| 363 | @Override |
| 364 | public MetaData clone() { |
| 365 | MetaData meta = null; |
| 366 | try { |
| 367 | meta = (MetaData) super.clone(); |
| 368 | } catch (CloneNotSupportedException e) { |
| 369 | // Did the clones rebel? |
| 370 | System.err.println(e); |
| 371 | } |
| 372 | |
| 373 | if (tags != null) { |
| 374 | meta.tags = new ArrayList<String>(); |
| 375 | meta.tags.addAll(tags); |
| 376 | } |
| 377 | if (resume != null) { |
| 378 | meta.resume = new Chapter(resume.getNumber(), resume.getName()); |
| 379 | for (Paragraph para : resume) { |
| 380 | meta.resume.getParagraphs().add(para); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | return meta; |
| 385 | } |
| 386 | } |