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.
15 public class MetaData
implements Cloneable
, Comparable
<MetaData
>, Serializable
{
16 private static final long serialVersionUID
= 1L;
19 private String author
;
21 private Chapter resume
;
22 private List
<String
> tags
;
24 private String subject
;
25 private String source
;
30 private String publisher
;
32 private boolean imageDocument
;
34 private String creationDate
;
35 private boolean fakeCover
;
38 * Create an empty {@link MetaData}.
44 * The title of the story.
48 public String
getTitle() {
53 * The title of the story.
58 public void setTitle(String title
) {
63 * The author of the story.
67 public String
getAuthor() {
72 * The author of the story.
77 public void setAuthor(String author
) {
82 * The story publication date.
86 public String
getDate() {
91 * The story publication date.
96 public void setDate(String date
) {
101 * The tags associated with this story.
105 public List
<String
> getTags() {
110 * The tags associated with this story.
115 public void setTags(List
<String
> tags
) {
120 * The story resume (a.k.a. description).
122 * This can be NULL if we don't have a resume for this {@link Story}.
126 public Chapter
getResume() {
131 * The story resume (a.k.a. description).
136 public void setResume(Chapter resume
) {
137 this.resume
= resume
;
141 * The cover image of the story if any (can be NULL).
145 public Image
getCover() {
150 * The cover image of the story if any (can be NULL).
155 public void setCover(Image cover
) {
160 * The subject of the story (or instance, if it is a fanfiction, what is the
161 * original work; if it is a technical text, what is the technical
164 * @return the subject
166 public String
getSubject() {
171 * The subject of the story (for instance, if it is a fanfiction, what is
172 * the original work; if it is a technical text, what is the technical
178 public void setSubject(String subject
) {
179 this.subject
= subject
;
183 * The source of this story (which online library it was downloaded from).
187 public String
getSource() {
192 * The source of this story (which online library it was downloaded from).
197 public void setSource(String source
) {
198 this.source
= source
;
202 * The original URL from which this {@link Story} was imported.
206 public String
getUrl() {
211 * The original URL from which this {@link Story} was imported.
216 public void setUrl(String url
) {
221 * A unique value representing the story (it is often a URL).
225 public String
getUuid() {
230 * A unique value representing the story (it is often a URL).
235 public void setUuid(String uuid
) {
240 * A unique value representing the story in the local library.
244 public String
getLuid() {
249 * A unique value representing the story in the local library.
254 public void setLuid(String luid
) {
259 * The 2-letter code language of this story.
263 public String
getLang() {
268 * The 2-letter code language of this story.
273 public void setLang(String lang
) {
278 * The story publisher (other the same as the source).
280 * @return the publisher
282 public String
getPublisher() {
287 * The story publisher (other the same as the source).
290 * the publisher to set
292 public void setPublisher(String publisher
) {
293 this.publisher
= publisher
;
297 * The output type this {@link Story} is in.
299 * @return the type the type
301 public String
getType() {
306 * The output type this {@link Story} is in.
309 * the new type to set
311 public void setType(String type
) {
316 * Document catering mostly to image files.
318 * @return the imageDocument state
320 public boolean isImageDocument() {
321 return imageDocument
;
325 * Document catering mostly to image files.
327 * @param imageDocument
328 * the imageDocument state to set
330 public void setImageDocument(boolean imageDocument
) {
331 this.imageDocument
= imageDocument
;
335 * The number of words in the related {@link Story}.
337 * @return the number of words
339 public long getWords() {
344 * The number of words in the related {@link Story}.
347 * the number of words to set
349 public void setWords(long words
) {
354 * The (Fanfix) {@link Story} creation date.
356 * @return the creationDate
358 public String
getCreationDate() {
363 * The (Fanfix) {@link Story} creation date.
365 * @param creationDate
366 * the creationDate to set
368 public void setCreationDate(String creationDate
) {
369 this.creationDate
= creationDate
;
373 * The cover in this {@link MetaData} object is "fake", in the sens that it
374 * comes from the actual content images.
376 * @return TRUE for a fake cover
378 public boolean isFakeCover() {
383 * The cover in this {@link MetaData} object is "fake", in the sens that it
384 * comes from the actual content images
387 * TRUE for a fake cover
389 public void setFakeCover(boolean fakeCover
) {
390 this.fakeCover
= fakeCover
;
394 public int compareTo(MetaData o
) {
399 String id
= (getTitle() == null ?
"" : getTitle())
400 + (getUuid() == null ?
"" : getUuid())
401 + (getLuid() == null ?
"" : getLuid());
402 String oId
= (getTitle() == null ?
"" : o
.getTitle())
403 + (getUuid() == null ?
"" : o
.getUuid())
404 + (o
.getLuid() == null ?
"" : o
.getLuid());
406 return id
.compareToIgnoreCase(oId
);
410 public boolean equals(Object obj
) {
411 if (!(obj
instanceof MetaData
)) {
415 return compareTo((MetaData
) obj
) == 0;
419 public int hashCode() {
420 String uuid
= getUuid();
422 uuid
= "" + title
+ author
+ source
;
425 return uuid
.hashCode();
429 public MetaData
clone() {
430 MetaData meta
= null;
432 meta
= (MetaData
) super.clone();
433 } catch (CloneNotSupportedException e
) {
434 // Did the clones rebel?
435 System
.err
.println(e
);
439 meta
.tags
= new ArrayList
<String
>(tags
);
442 if (resume
!= null) {
443 meta
.resume
= resume
.clone();
450 * Display a DEBUG {@link String} representation of this object.
452 * This is not efficient, nor intended to be.
455 public String
toString() {
457 if (getTitle() != null) {
461 StringBuilder tags
= new StringBuilder();
462 if (getTags() != null) {
463 for (String tag
: getTags()) {
464 if (tags
.length() > 0) {
472 if (getResume() != null) {
473 for (Paragraph para
: getResume()) {
475 resume
+= para
.toString().substring(0,
476 Math
.min(para
.toString().length(), 120));
481 String cover
= "none";
482 if (getCover() != null) {
483 cover
= StringUtils
.formatNumber(getCover().getSize())
487 return String
.format(
488 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]\n\tWord count: [%s]"
489 + "\n\tResume: [%s]\n\tCover: [%s]",
490 luid
, title
, getAuthor(), getDate(), tags
.toString(),
491 "" + words
, resume
, cover
);