1 package be
.nikiroo
.fanfix
.data
;
3 import java
.util
.ArrayList
;
6 import be
.nikiroo
.utils
.Image
;
9 * The meta data associated to a {@link Story} object.
13 public class MetaData
implements Cloneable
, Comparable
<MetaData
> {
15 private String author
;
17 private Chapter resume
;
18 private List
<String
> tags
;
20 private String subject
;
21 private String source
;
26 private String publisher
;
28 private boolean imageDocument
;
30 private String creationDate
;
31 private boolean fakeCover
;
34 * The title of the story.
38 public String
getTitle() {
43 * The title of the story.
48 public void setTitle(String title
) {
53 * The author of the story.
57 public String
getAuthor() {
62 * The author of the story.
67 public void setAuthor(String author
) {
72 * The story publication date.
76 public String
getDate() {
81 * The story publication date.
86 public void setDate(String date
) {
91 * The tags associated with this story.
95 public List
<String
> getTags() {
100 * The tags associated with this story.
105 public void setTags(List
<String
> tags
) {
110 * The story resume (a.k.a. description).
114 public Chapter
getResume() {
119 * The story resume (a.k.a. description).
124 public void setResume(Chapter resume
) {
125 this.resume
= resume
;
129 * The cover image of the story if any (can be NULL).
133 public Image
getCover() {
138 * The cover image of the story if any (can be NULL).
143 public void setCover(Image cover
) {
148 * The subject of the story (or instance, if it is a fanfiction, what is the
149 * original work; if it is a technical text, what is the technical
152 * @return the subject
154 public String
getSubject() {
159 * The subject of the story (for instance, if it is a fanfiction, what is
160 * the original work; if it is a technical text, what is the technical
166 public void setSubject(String subject
) {
167 this.subject
= subject
;
171 * The source of this story (which online library it was downloaded from).
175 public String
getSource() {
180 * The source of this story (which online library it was downloaded from).
185 public void setSource(String source
) {
186 this.source
= source
;
190 * The original URL from which this {@link Story} was imported.
194 public String
getUrl() {
199 * The original URL from which this {@link Story} was imported.
204 public void setUrl(String url
) {
209 * A unique value representing the story (it is often a URL).
213 public String
getUuid() {
218 * A unique value representing the story (it is often a URL).
223 public void setUuid(String uuid
) {
228 * A unique value representing the story in the local library.
232 public String
getLuid() {
237 * A unique value representing the story in the local library.
242 public void setLuid(String luid
) {
247 * The 2-letter code language of this story.
251 public String
getLang() {
256 * The 2-letter code language of this story.
261 public void setLang(String lang
) {
266 * The story publisher (other the same as the source).
268 * @return the publisher
270 public String
getPublisher() {
275 * The story publisher (other the same as the source).
278 * the publisher to set
280 public void setPublisher(String publisher
) {
281 this.publisher
= publisher
;
285 * The output type this {@link Story} is in.
287 * @return the type the type
289 public String
getType() {
294 * The output type this {@link Story} is in.
297 * the new type to set
299 public void setType(String type
) {
304 * Document catering mostly to image files.
306 * @return the imageDocument state
308 public boolean isImageDocument() {
309 return imageDocument
;
313 * Document catering mostly to image files.
315 * @param imageDocument
316 * the imageDocument state to set
318 public void setImageDocument(boolean imageDocument
) {
319 this.imageDocument
= imageDocument
;
323 * The number of words in the related {@link Story}.
325 * @return the number of words
327 public long getWords() {
332 * The number of words in the related {@link Story}.
335 * the number of words to set
337 public void setWords(long words
) {
342 * The (Fanfix) {@link Story} creation date.
344 * @return the creationDate
346 public String
getCreationDate() {
351 * The (Fanfix) {@link Story} creation date.
353 * @param creationDate
354 * the creationDate to set
356 public void setCreationDate(String creationDate
) {
357 this.creationDate
= creationDate
;
361 * The cover in this {@link MetaData} object is "fake", in the sens that it
362 * comes from the actual content images.
364 * @return TRUE for a fake cover
366 public boolean isFakeCover() {
371 * The cover in this {@link MetaData} object is "fake", in the sens that it
372 * comes from the actual content images
375 * TRUE for a fake cover
377 public void setFakeCover(boolean fakeCover
) {
378 this.fakeCover
= fakeCover
;
382 public int compareTo(MetaData o
) {
387 String id
= (getUuid() == null ?
"" : getUuid())
388 + (getLuid() == null ?
"" : getLuid());
389 String oId
= (getUuid() == null ?
"" : o
.getUuid())
390 + (o
.getLuid() == null ?
"" : o
.getLuid());
392 return id
.compareTo(oId
);
396 public boolean equals(Object obj
) {
397 if (!(obj
instanceof MetaData
)) {
401 return compareTo((MetaData
) obj
) == 0;
405 public int hashCode() {
406 String uuid
= getUuid();
408 uuid
= "" + title
+ author
+ source
;
411 return uuid
.hashCode();
415 public MetaData
clone() {
416 MetaData meta
= null;
418 meta
= (MetaData
) super.clone();
419 } catch (CloneNotSupportedException e
) {
420 // Did the clones rebel?
421 System
.err
.println(e
);
425 meta
.tags
= new ArrayList
<String
>(tags
);
428 if (resume
!= null) {
429 meta
.resume
= resume
.clone();
436 * Display a DEBUG {@link String} representation of this object.
438 * This is not efficient, nor intended to be.
441 public String
toString() {
443 if (getTitle() != null) {
447 StringBuilder tags
= new StringBuilder();
448 if (getTags() != null) {
449 for (String tag
: getTags()) {
450 if (tags
.length() > 0) {
458 if (getResume() != null) {
459 for (Paragraph para
: getResume()) {
461 resume
+= para
.toString().substring(0,
462 Math
.min(para
.toString().length(), 120));
467 String cover
= "none";
468 if (getCover() != null) {
471 int size
= getCover().getData().length
;
481 cover
= size
+ cover
;
484 return String
.format(
485 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]"
486 + "\n\tResume: [%s]\n\tCover: [%s]", luid
, title
,
487 getAuthor(), getDate(), tags
.toString(), resume
, cover
);