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).
118 public Chapter
getResume() {
123 * The story resume (a.k.a. description).
128 public void setResume(Chapter resume
) {
129 this.resume
= resume
;
133 * The cover image of the story if any (can be NULL).
137 public Image
getCover() {
142 * The cover image of the story if any (can be NULL).
147 public void setCover(Image cover
) {
152 * The subject of the story (or instance, if it is a fanfiction, what is the
153 * original work; if it is a technical text, what is the technical
156 * @return the subject
158 public String
getSubject() {
163 * The subject of the story (for instance, if it is a fanfiction, what is
164 * the original work; if it is a technical text, what is the technical
170 public void setSubject(String subject
) {
171 this.subject
= subject
;
175 * The source of this story (which online library it was downloaded from).
179 public String
getSource() {
184 * The source of this story (which online library it was downloaded from).
189 public void setSource(String source
) {
190 this.source
= source
;
194 * The original URL from which this {@link Story} was imported.
198 public String
getUrl() {
203 * The original URL from which this {@link Story} was imported.
208 public void setUrl(String url
) {
213 * A unique value representing the story (it is often a URL).
217 public String
getUuid() {
222 * A unique value representing the story (it is often a URL).
227 public void setUuid(String uuid
) {
232 * A unique value representing the story in the local library.
236 public String
getLuid() {
241 * A unique value representing the story in the local library.
246 public void setLuid(String luid
) {
251 * The 2-letter code language of this story.
255 public String
getLang() {
260 * The 2-letter code language of this story.
265 public void setLang(String lang
) {
270 * The story publisher (other the same as the source).
272 * @return the publisher
274 public String
getPublisher() {
279 * The story publisher (other the same as the source).
282 * the publisher to set
284 public void setPublisher(String publisher
) {
285 this.publisher
= publisher
;
289 * The output type this {@link Story} is in.
291 * @return the type the type
293 public String
getType() {
298 * The output type this {@link Story} is in.
301 * the new type to set
303 public void setType(String type
) {
308 * Document catering mostly to image files.
310 * @return the imageDocument state
312 public boolean isImageDocument() {
313 return imageDocument
;
317 * Document catering mostly to image files.
319 * @param imageDocument
320 * the imageDocument state to set
322 public void setImageDocument(boolean imageDocument
) {
323 this.imageDocument
= imageDocument
;
327 * The number of words in the related {@link Story}.
329 * @return the number of words
331 public long getWords() {
336 * The number of words in the related {@link Story}.
339 * the number of words to set
341 public void setWords(long words
) {
346 * The (Fanfix) {@link Story} creation date.
348 * @return the creationDate
350 public String
getCreationDate() {
355 * The (Fanfix) {@link Story} creation date.
357 * @param creationDate
358 * the creationDate to set
360 public void setCreationDate(String creationDate
) {
361 this.creationDate
= creationDate
;
365 * The cover in this {@link MetaData} object is "fake", in the sens that it
366 * comes from the actual content images.
368 * @return TRUE for a fake cover
370 public boolean isFakeCover() {
375 * The cover in this {@link MetaData} object is "fake", in the sens that it
376 * comes from the actual content images
379 * TRUE for a fake cover
381 public void setFakeCover(boolean fakeCover
) {
382 this.fakeCover
= fakeCover
;
386 public int compareTo(MetaData o
) {
391 String id
= (getUuid() == null ?
"" : getUuid())
392 + (getLuid() == null ?
"" : getLuid());
393 String oId
= (getUuid() == null ?
"" : o
.getUuid())
394 + (o
.getLuid() == null ?
"" : o
.getLuid());
396 return id
.compareTo(oId
);
400 public boolean equals(Object obj
) {
401 if (!(obj
instanceof MetaData
)) {
405 return compareTo((MetaData
) obj
) == 0;
409 public int hashCode() {
410 String uuid
= getUuid();
412 uuid
= "" + title
+ author
+ source
;
415 return uuid
.hashCode();
419 public MetaData
clone() {
420 MetaData meta
= null;
422 meta
= (MetaData
) super.clone();
423 } catch (CloneNotSupportedException e
) {
424 // Did the clones rebel?
425 System
.err
.println(e
);
429 meta
.tags
= new ArrayList
<String
>(tags
);
432 if (resume
!= null) {
433 meta
.resume
= resume
.clone();
440 * Display a DEBUG {@link String} representation of this object.
442 * This is not efficient, nor intended to be.
445 public String
toString() {
447 if (getTitle() != null) {
451 StringBuilder tags
= new StringBuilder();
452 if (getTags() != null) {
453 for (String tag
: getTags()) {
454 if (tags
.length() > 0) {
462 if (getResume() != null) {
463 for (Paragraph para
: getResume()) {
465 resume
+= para
.toString().substring(0,
466 Math
.min(para
.toString().length(), 120));
471 String cover
= "none";
472 if (getCover() != null) {
473 cover
= StringUtils
.formatNumber(getCover().getData().length
)
477 return String
.format(
478 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]"
479 + "\n\tResume: [%s]\n\tCover: [%s]", luid
, title
,
480 getAuthor(), getDate(), tags
.toString(), resume
, cover
);