1 package be
.nikiroo
.fanfix
.data
;
3 import java
.io
.Serializable
;
4 import java
.util
.ArrayList
;
7 import be
.nikiroo
.fanfix
.supported
.SupportType
;
8 import be
.nikiroo
.utils
.Image
;
9 import be
.nikiroo
.utils
.StringUtils
;
12 * The meta data associated to a {@link Story} object.
14 * Note that some earlier version of the program did not save the resume as an
15 * external file; for those stories, the resume is not fetched until the story
18 * The cover is never fetched until the story is.
22 public class MetaData
implements Cloneable
, Comparable
<MetaData
>, Serializable
{
23 private static final long serialVersionUID
= 1L;
26 private String author
;
28 private Chapter resume
;
29 private List
<String
> tags
;
31 private String subject
;
32 private String source
;
37 private String publisher
;
39 private boolean imageDocument
;
41 private String creationDate
;
42 private boolean fakeCover
;
45 * Create an empty {@link MetaData}.
51 * The title of the story.
55 public String
getTitle() {
60 * The title of the story.
65 public void setTitle(String title
) {
70 * The author of the story.
74 public String
getAuthor() {
79 * The author of the story.
84 public void setAuthor(String author
) {
89 * The story publication date, we try to use "YYYY-mm-dd" when possible.
93 public String
getDate() {
98 * The story publication date, we try to use "YYYY-mm-dd" when possible.
103 public void setDate(String date
) {
108 * The tags associated with this story.
112 public List
<String
> getTags() {
117 * The tags associated with this story.
122 public void setTags(List
<String
> tags
) {
127 * The story resume (a.k.a. description).
129 * This can be NULL if we don't have a resume for this {@link Story}.
131 * Note that some earlier version of the program did not save the resume as
132 * an external file; for those stories, the resume is not fetched until the
137 public Chapter
getResume() {
142 * The story resume (a.k.a. description).
144 * Note that some earlier version of the program did not save the resume as
145 * an external file; for those stories, the resume is not fetched until the
151 public void setResume(Chapter resume
) {
152 this.resume
= resume
;
156 * The cover image of the story, if any (can be NULL).
158 * The cover is not fetched until the story is.
162 public Image
getCover() {
167 * The cover image of the story, if any (can be NULL).
169 * The cover is not fetched until the story is.
174 public void setCover(Image cover
) {
179 * The subject of the story (for instance, if it is a fanfiction, what is the
180 * original work; if it is a technical text, what is the technical
183 * @return the subject
185 public String
getSubject() {
190 * The subject of the story (for instance, if it is a fanfiction, what is
191 * the original work; if it is a technical text, what is the technical
197 public void setSubject(String subject
) {
198 this.subject
= subject
;
202 * The source of this story -- a very user-visible piece of data.
204 * It is initialised with the same value as {@link MetaData#getPublisher()},
205 * but the user is allowed to change it into any value -- this is a sort of
210 public String
getSource() {
215 * The source of this story -- a very user-visible piece of data.
217 * It is initialised with the same value as {@link MetaData#getPublisher()},
218 * but the user is allowed to change it into any value -- this is a sort of
224 public void setSource(String source
) {
225 this.source
= source
;
229 * The original URL from which this {@link Story} was imported.
233 public String
getUrl() {
238 * The original URL from which this {@link Story} was imported.
243 public void setUrl(String url
) {
248 * A unique value representing the story (it is often a URL).
252 public String
getUuid() {
257 * A unique value representing the story (it is often a URL).
262 public void setUuid(String uuid
) {
267 * A unique value representing the story in the local library (usually a
268 * numerical value 0-padded with a minimum size of 3; but this is subject to
269 * change and you can also obviously have more than 1000 stories --
270 * <strong>a luid may potentially be anything else, including non-numeric
271 * characters</strong>).
273 * A NULL or empty luid represents an incomplete, corrupted or fake
278 public String
getLuid() {
283 * A unique value representing the story in the local library (usually a
284 * numerical value 0-padded with a minimum size of 3; but this is subject to
285 * change and you can also obviously have more than 1000 stories --
286 * <strong>a luid may potentially be anything else, including non-numeric
287 * characters</strong>).
289 * A NULL or empty luid represents an incomplete, corrupted or fake
295 public void setLuid(String luid
) {
300 * The 2-letter code language of this story.
304 public String
getLang() {
309 * The 2-letter code language of this story.
314 public void setLang(String lang
) {
319 * The story publisher -- which is also the user representation of the
320 * output type this {@link Story} is in (see {@link SupportType}).
322 * It allows you to know where the {@link Story} comes from, and is not
323 * supposed to change.
325 * It's the user representation of the enum
326 * ({@link SupportType#getSourceName()}, not
327 * {@link SupportType#toString()}).
329 * @return the publisher
331 public String
getPublisher() {
336 * The story publisher -- which is also the user representation of the
337 * output type this {@link Story} is in (see {@link SupportType}).
339 * It allows you to know where the {@link Story} comes from, and is not
340 * supposed to change.
342 * It's the user representation of the enum
343 * ({@link SupportType#getSourceName()}, not
344 * {@link SupportType#toString()}).
347 * the publisher to set
349 public void setPublisher(String publisher
) {
350 this.publisher
= publisher
;
354 * The output type this {@link Story} is in (see {@link SupportType}).
356 * It allows you to know where the {@link Story} comes from, and is not
357 * supposed to change.
359 * It's the direct representation of the enum
360 * ({@link SupportType#toString()}, not
361 * {@link SupportType#getSourceName()}).
363 * @return the type the type
365 public String
getType() {
370 * The output type this {@link Story} is in (see {@link SupportType}).
372 * It allows you to know where the {@link Story} comes from, and is not
373 * supposed to change.
375 * It's the direct representation of the enum
376 * ({@link SupportType#toString()}, not
377 * {@link SupportType#getSourceName()}).
380 * the new type to set
382 public void setType(String type
) {
387 * Document catering mostly to image files.
389 * I.E., this is a comics or a manga, not a textual story with actual words.
391 * In image documents, all the paragraphs are supposed to be images.
393 * @return the imageDocument state
395 public boolean isImageDocument() {
396 return imageDocument
;
400 * Document catering mostly to image files.
402 * I.E., this is a comics or a manga, not a textual story with actual words.
404 * In image documents, all the paragraphs are supposed to be images.
406 * @param imageDocument
407 * the imageDocument state to set
409 public void setImageDocument(boolean imageDocument
) {
410 this.imageDocument
= imageDocument
;
414 * The number of words (or images if this is an image document -- see
415 * {@link MetaData#isImageDocument()}) in the related {@link Story}.
417 * @return the number of words/images
419 public long getWords() {
424 * The number of words (or images if this is an image document -- see
425 * {@link MetaData#isImageDocument()}) in the related {@link Story}.
428 * the number of words/images to set
430 public void setWords(long words
) {
435 * The (Fanfix) {@link Story} creation date, i.e., when the {@link Story}
436 * was fetched via Fanfix.
438 * @return the creation date
440 public String
getCreationDate() {
445 * The (Fanfix) {@link Story} creation date, i.e., when the {@link Story}
446 * was fetched via Fanfix.
448 * @param creationDate
449 * the creation date to set
451 public void setCreationDate(String creationDate
) {
452 this.creationDate
= creationDate
;
456 * The cover in this {@link MetaData} object is "fake", in the sense that it
457 * comes from the actual content images.
459 * @return TRUE for a fake cover
461 public boolean isFakeCover() {
466 * The cover in this {@link MetaData} object is "fake", in the sense that it
467 * comes from the actual content images
470 * TRUE for a fake cover
472 public void setFakeCover(boolean fakeCover
) {
473 this.fakeCover
= fakeCover
;
477 public int compareTo(MetaData o
) {
482 String id
= (getTitle() == null ?
"" : getTitle())
483 + (getUuid() == null ?
"" : getUuid())
484 + (getLuid() == null ?
"" : getLuid());
485 String oId
= (getTitle() == null ?
"" : o
.getTitle())
486 + (getUuid() == null ?
"" : o
.getUuid())
487 + (o
.getLuid() == null ?
"" : o
.getLuid());
489 return id
.compareToIgnoreCase(oId
);
493 public boolean equals(Object obj
) {
494 if (!(obj
instanceof MetaData
)) {
498 return compareTo((MetaData
) obj
) == 0;
502 public int hashCode() {
503 String uuid
= getUuid();
505 uuid
= "" + title
+ author
+ source
;
508 return uuid
.hashCode();
512 public MetaData
clone() {
513 MetaData meta
= null;
515 meta
= (MetaData
) super.clone();
516 } catch (CloneNotSupportedException e
) {
517 // Did the clones rebel?
518 System
.err
.println(e
);
522 meta
.tags
= new ArrayList
<String
>(tags
);
525 if (resume
!= null) {
526 meta
.resume
= resume
.clone();
533 * Display a DEBUG {@link String} representation of this object.
535 * This is not efficient, nor intended to be.
538 public String
toString() {
540 if (getTitle() != null) {
544 StringBuilder tags
= new StringBuilder();
545 if (getTags() != null) {
546 for (String tag
: getTags()) {
547 if (tags
.length() > 0) {
555 if (getResume() != null) {
556 for (Paragraph para
: getResume()) {
558 resume
+= para
.toString().substring(0,
559 Math
.min(para
.toString().length(), 120));
564 String cover
= "none";
565 if (getCover() != null) {
566 cover
= StringUtils
.formatNumber(getCover().getSize())
570 return String
.format(
571 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]\n\tWord count: [%s]"
572 + "\n\tResume: [%s]\n\tCover: [%s]",
573 luid
, title
, getAuthor(), getDate(), tags
.toString(),
574 "" + words
, resume
, cover
);