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 * The title of the story.
42 public String
getTitle() {
47 * The title of the story.
52 public void setTitle(String title
) {
57 * The author of the story.
61 public String
getAuthor() {
66 * The author of the story.
71 public void setAuthor(String author
) {
76 * The story publication date.
80 public String
getDate() {
85 * The story publication date.
90 public void setDate(String date
) {
95 * The tags associated with this story.
99 public List
<String
> getTags() {
104 * The tags associated with this story.
109 public void setTags(List
<String
> tags
) {
114 * The story resume (a.k.a. description).
116 * This can be NULL if we don't have a resume for this {@link Story}.
120 public Chapter
getResume() {
125 * The story resume (a.k.a. description).
130 public void setResume(Chapter resume
) {
131 this.resume
= resume
;
135 * The cover image of the story if any (can be NULL).
139 public Image
getCover() {
144 * The cover image of the story if any (can be NULL).
149 public void setCover(Image cover
) {
154 * The subject of the story (or instance, if it is a fanfiction, what is the
155 * original work; if it is a technical text, what is the technical
158 * @return the subject
160 public String
getSubject() {
165 * The subject of the story (for instance, if it is a fanfiction, what is
166 * the original work; if it is a technical text, what is the technical
172 public void setSubject(String subject
) {
173 this.subject
= subject
;
177 * The source of this story (which online library it was downloaded from).
181 public String
getSource() {
186 * The source of this story (which online library it was downloaded from).
191 public void setSource(String source
) {
192 this.source
= source
;
196 * The original URL from which this {@link Story} was imported.
200 public String
getUrl() {
205 * The original URL from which this {@link Story} was imported.
210 public void setUrl(String url
) {
215 * A unique value representing the story (it is often a URL).
219 public String
getUuid() {
224 * A unique value representing the story (it is often a URL).
229 public void setUuid(String uuid
) {
234 * A unique value representing the story in the local library.
238 public String
getLuid() {
243 * A unique value representing the story in the local library.
248 public void setLuid(String luid
) {
253 * The 2-letter code language of this story.
257 public String
getLang() {
262 * The 2-letter code language of this story.
267 public void setLang(String lang
) {
272 * The story publisher (other the same as the source).
274 * @return the publisher
276 public String
getPublisher() {
281 * The story publisher (other the same as the source).
284 * the publisher to set
286 public void setPublisher(String publisher
) {
287 this.publisher
= publisher
;
291 * The output type this {@link Story} is in.
293 * @return the type the type
295 public String
getType() {
300 * The output type this {@link Story} is in.
303 * the new type to set
305 public void setType(String type
) {
310 * Document catering mostly to image files.
312 * @return the imageDocument state
314 public boolean isImageDocument() {
315 return imageDocument
;
319 * Document catering mostly to image files.
321 * @param imageDocument
322 * the imageDocument state to set
324 public void setImageDocument(boolean imageDocument
) {
325 this.imageDocument
= imageDocument
;
329 * The number of words in the related {@link Story}.
331 * @return the number of words
333 public long getWords() {
338 * The number of words in the related {@link Story}.
341 * the number of words to set
343 public void setWords(long words
) {
348 * The (Fanfix) {@link Story} creation date.
350 * @return the creationDate
352 public String
getCreationDate() {
357 * The (Fanfix) {@link Story} creation date.
359 * @param creationDate
360 * the creationDate to set
362 public void setCreationDate(String creationDate
) {
363 this.creationDate
= creationDate
;
367 * The cover in this {@link MetaData} object is "fake", in the sens that it
368 * comes from the actual content images.
370 * @return TRUE for a fake cover
372 public boolean isFakeCover() {
377 * The cover in this {@link MetaData} object is "fake", in the sens that it
378 * comes from the actual content images
381 * TRUE for a fake cover
383 public void setFakeCover(boolean fakeCover
) {
384 this.fakeCover
= fakeCover
;
388 public int compareTo(MetaData o
) {
393 String id
= (getTitle() == null ?
"" : getTitle())
394 + (getUuid() == null ?
"" : getUuid())
395 + (getLuid() == null ?
"" : getLuid());
396 String oId
= (getTitle() == null ?
"" : o
.getTitle())
397 + (getUuid() == null ?
"" : o
.getUuid())
398 + (o
.getLuid() == null ?
"" : o
.getLuid());
400 return id
.compareToIgnoreCase(oId
);
404 public boolean equals(Object obj
) {
405 if (!(obj
instanceof MetaData
)) {
409 return compareTo((MetaData
) obj
) == 0;
413 public int hashCode() {
414 String uuid
= getUuid();
416 uuid
= "" + title
+ author
+ source
;
419 return uuid
.hashCode();
423 public MetaData
clone() {
424 MetaData meta
= null;
426 meta
= (MetaData
) super.clone();
427 } catch (CloneNotSupportedException e
) {
428 // Did the clones rebel?
429 System
.err
.println(e
);
433 meta
.tags
= new ArrayList
<String
>(tags
);
436 if (resume
!= null) {
437 meta
.resume
= resume
.clone();
444 * Display a DEBUG {@link String} representation of this object.
446 * This is not efficient, nor intended to be.
449 public String
toString() {
451 if (getTitle() != null) {
455 StringBuilder tags
= new StringBuilder();
456 if (getTags() != null) {
457 for (String tag
: getTags()) {
458 if (tags
.length() > 0) {
466 if (getResume() != null) {
467 for (Paragraph para
: getResume()) {
469 resume
+= para
.toString().substring(0,
470 Math
.min(para
.toString().length(), 120));
475 String cover
= "none";
476 if (getCover() != null) {
477 cover
= StringUtils
.formatNumber(getCover().getSize())
481 return String
.format(
482 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]"
483 + "\n\tResume: [%s]\n\tCover: [%s]", luid
, title
,
484 getAuthor(), getDate(), tags
.toString(), resume
, cover
);