1 package be
.nikiroo
.fanfix
.data
;
3 import java
.io
.Serializable
;
4 import java
.util
.ArrayList
;
7 import be
.nikiroo
.utils
.Image
;
8 import be
.nikiroo
.utils
.StringUtils
;
11 * The meta data associated to a {@link Story} object.
13 * Note that some earlier version of the program did not save the resume as an
14 * external file; for those stories, the resume is not fetched until the story
17 * The cover is never fetched until the story is.
21 public class MetaData
implements Cloneable
, Comparable
<MetaData
>, Serializable
{
22 private static final long serialVersionUID
= 1L;
25 private String author
;
27 private Chapter resume
;
28 private List
<String
> tags
;
30 private String subject
;
31 private String source
;
36 private String publisher
;
38 private boolean imageDocument
;
40 private String creationDate
;
41 private boolean fakeCover
;
44 * Create an empty {@link MetaData}.
50 * The title of the story.
54 public String
getTitle() {
59 * The title of the story.
64 public void setTitle(String title
) {
69 * The author of the story.
73 public String
getAuthor() {
78 * The author of the story.
83 public void setAuthor(String author
) {
88 * The story publication date.
92 public String
getDate() {
97 * The story publication date.
102 public void setDate(String date
) {
107 * The tags associated with this story.
111 public List
<String
> getTags() {
116 * The tags associated with this story.
121 public void setTags(List
<String
> tags
) {
126 * The story resume (a.k.a. description).
128 * This can be NULL if we don't have a resume for this {@link Story}.
130 * Note that some earlier version of the program did not save the resume as
131 * an external file; for those stories, the resume is not fetched until the
136 public Chapter
getResume() {
141 * The story resume (a.k.a. description).
143 * Note that some earlier version of the program did not save the resume as
144 * an external file; for those stories, the resume is not fetched until the
150 public void setResume(Chapter resume
) {
151 this.resume
= resume
;
155 * The cover image of the story if any (can be NULL).
157 * The cover is not fetched until the story is.
161 public Image
getCover() {
166 * The cover image of the story if any (can be NULL).
168 * The cover is not fetched until the story is.
173 public void setCover(Image cover
) {
178 * The subject of the story (or instance, if it is a fanfiction, what is the
179 * original work; if it is a technical text, what is the technical
182 * @return the subject
184 public String
getSubject() {
189 * The subject of the story (for instance, if it is a fanfiction, what is
190 * the original work; if it is a technical text, what is the technical
196 public void setSubject(String subject
) {
197 this.subject
= subject
;
201 * The source of this story (which online library it was downloaded from).
205 public String
getSource() {
210 * The source of this story (which online library it was downloaded from).
215 public void setSource(String source
) {
216 this.source
= source
;
220 * The original URL from which this {@link Story} was imported.
224 public String
getUrl() {
229 * The original URL from which this {@link Story} was imported.
234 public void setUrl(String url
) {
239 * A unique value representing the story (it is often a URL).
243 public String
getUuid() {
248 * A unique value representing the story (it is often a URL).
253 public void setUuid(String uuid
) {
258 * A unique value representing the story in the local library.
262 public String
getLuid() {
267 * A unique value representing the story in the local library.
272 public void setLuid(String luid
) {
277 * The 2-letter code language of this story.
281 public String
getLang() {
286 * The 2-letter code language of this story.
291 public void setLang(String lang
) {
296 * The story publisher (other the same as the source).
298 * @return the publisher
300 public String
getPublisher() {
305 * The story publisher (other the same as the source).
308 * the publisher to set
310 public void setPublisher(String publisher
) {
311 this.publisher
= publisher
;
315 * The output type this {@link Story} is in.
317 * @return the type the type
319 public String
getType() {
324 * The output type this {@link Story} is in.
327 * the new type to set
329 public void setType(String type
) {
334 * Document catering mostly to image files.
336 * @return the imageDocument state
338 public boolean isImageDocument() {
339 return imageDocument
;
343 * Document catering mostly to image files.
345 * @param imageDocument
346 * the imageDocument state to set
348 public void setImageDocument(boolean imageDocument
) {
349 this.imageDocument
= imageDocument
;
353 * The number of words in the related {@link Story}.
355 * @return the number of words
357 public long getWords() {
362 * The number of words in the related {@link Story}.
365 * the number of words to set
367 public void setWords(long words
) {
372 * The (Fanfix) {@link Story} creation date.
374 * @return the creationDate
376 public String
getCreationDate() {
381 * The (Fanfix) {@link Story} creation date.
383 * @param creationDate
384 * the creationDate to set
386 public void setCreationDate(String creationDate
) {
387 this.creationDate
= creationDate
;
391 * The cover in this {@link MetaData} object is "fake", in the sens that it
392 * comes from the actual content images.
394 * @return TRUE for a fake cover
396 public boolean isFakeCover() {
401 * The cover in this {@link MetaData} object is "fake", in the sens that it
402 * comes from the actual content images
405 * TRUE for a fake cover
407 public void setFakeCover(boolean fakeCover
) {
408 this.fakeCover
= fakeCover
;
412 public int compareTo(MetaData o
) {
417 String id
= (getTitle() == null ?
"" : getTitle())
418 + (getUuid() == null ?
"" : getUuid())
419 + (getLuid() == null ?
"" : getLuid());
420 String oId
= (getTitle() == null ?
"" : o
.getTitle())
421 + (getUuid() == null ?
"" : o
.getUuid())
422 + (o
.getLuid() == null ?
"" : o
.getLuid());
424 return id
.compareToIgnoreCase(oId
);
428 public boolean equals(Object obj
) {
429 if (!(obj
instanceof MetaData
)) {
433 return compareTo((MetaData
) obj
) == 0;
437 public int hashCode() {
438 String uuid
= getUuid();
440 uuid
= "" + title
+ author
+ source
;
443 return uuid
.hashCode();
447 public MetaData
clone() {
448 MetaData meta
= null;
450 meta
= (MetaData
) super.clone();
451 } catch (CloneNotSupportedException e
) {
452 // Did the clones rebel?
453 System
.err
.println(e
);
457 meta
.tags
= new ArrayList
<String
>(tags
);
460 if (resume
!= null) {
461 meta
.resume
= resume
.clone();
468 * Display a DEBUG {@link String} representation of this object.
470 * This is not efficient, nor intended to be.
473 public String
toString() {
475 if (getTitle() != null) {
479 StringBuilder tags
= new StringBuilder();
480 if (getTags() != null) {
481 for (String tag
: getTags()) {
482 if (tags
.length() > 0) {
490 if (getResume() != null) {
491 for (Paragraph para
: getResume()) {
493 resume
+= para
.toString().substring(0,
494 Math
.min(para
.toString().length(), 120));
499 String cover
= "none";
500 if (getCover() != null) {
501 cover
= StringUtils
.formatNumber(getCover().getSize())
505 return String
.format(
506 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]\n\tWord count: [%s]"
507 + "\n\tResume: [%s]\n\tCover: [%s]",
508 luid
, title
, getAuthor(), getDate(), tags
.toString(),
509 "" + words
, resume
, cover
);