1 package be
.nikiroo
.fanfix
.data
;
3 import java
.io
.Serializable
;
4 import java
.util
.ArrayList
;
7 import be
.nikiroo
.utils
.Image
;
10 * The meta data associated to a {@link Story} object.
14 public class MetaData
implements Cloneable
, Comparable
<MetaData
>, Serializable
{
15 private static final long serialVersionUID
= 1L;
18 private String author
;
20 private Chapter resume
;
21 private List
<String
> tags
;
23 private String subject
;
24 private String source
;
29 private String publisher
;
31 private boolean imageDocument
;
33 private String creationDate
;
34 private boolean fakeCover
;
37 * The title of the story.
41 public String
getTitle() {
46 * The title of the story.
51 public void setTitle(String title
) {
56 * The author of the story.
60 public String
getAuthor() {
65 * The author of the story.
70 public void setAuthor(String author
) {
75 * The story publication date.
79 public String
getDate() {
84 * The story publication date.
89 public void setDate(String date
) {
94 * The tags associated with this story.
98 public List
<String
> getTags() {
103 * The tags associated with this story.
108 public void setTags(List
<String
> tags
) {
113 * The story resume (a.k.a. description).
117 public Chapter
getResume() {
122 * The story resume (a.k.a. description).
127 public void setResume(Chapter resume
) {
128 this.resume
= resume
;
132 * The cover image of the story if any (can be NULL).
136 public Image
getCover() {
141 * The cover image of the story if any (can be NULL).
146 public void setCover(Image cover
) {
151 * The subject of the story (or instance, if it is a fanfiction, what is the
152 * original work; if it is a technical text, what is the technical
155 * @return the subject
157 public String
getSubject() {
162 * The subject of the story (for instance, if it is a fanfiction, what is
163 * the original work; if it is a technical text, what is the technical
169 public void setSubject(String subject
) {
170 this.subject
= subject
;
174 * The source of this story (which online library it was downloaded from).
178 public String
getSource() {
183 * The source of this story (which online library it was downloaded from).
188 public void setSource(String source
) {
189 this.source
= source
;
193 * The original URL from which this {@link Story} was imported.
197 public String
getUrl() {
202 * The original URL from which this {@link Story} was imported.
207 public void setUrl(String url
) {
212 * A unique value representing the story (it is often a URL).
216 public String
getUuid() {
221 * A unique value representing the story (it is often a URL).
226 public void setUuid(String uuid
) {
231 * A unique value representing the story in the local library.
235 public String
getLuid() {
240 * A unique value representing the story in the local library.
245 public void setLuid(String luid
) {
250 * The 2-letter code language of this story.
254 public String
getLang() {
259 * The 2-letter code language of this story.
264 public void setLang(String lang
) {
269 * The story publisher (other the same as the source).
271 * @return the publisher
273 public String
getPublisher() {
278 * The story publisher (other the same as the source).
281 * the publisher to set
283 public void setPublisher(String publisher
) {
284 this.publisher
= publisher
;
288 * The output type this {@link Story} is in.
290 * @return the type the type
292 public String
getType() {
297 * The output type this {@link Story} is in.
300 * the new type to set
302 public void setType(String type
) {
307 * Document catering mostly to image files.
309 * @return the imageDocument state
311 public boolean isImageDocument() {
312 return imageDocument
;
316 * Document catering mostly to image files.
318 * @param imageDocument
319 * the imageDocument state to set
321 public void setImageDocument(boolean imageDocument
) {
322 this.imageDocument
= imageDocument
;
326 * The number of words in the related {@link Story}.
328 * @return the number of words
330 public long getWords() {
335 * The number of words in the related {@link Story}.
338 * the number of words to set
340 public void setWords(long words
) {
345 * The (Fanfix) {@link Story} creation date.
347 * @return the creationDate
349 public String
getCreationDate() {
354 * The (Fanfix) {@link Story} creation date.
356 * @param creationDate
357 * the creationDate to set
359 public void setCreationDate(String creationDate
) {
360 this.creationDate
= creationDate
;
364 * The cover in this {@link MetaData} object is "fake", in the sens that it
365 * comes from the actual content images.
367 * @return TRUE for a fake cover
369 public boolean isFakeCover() {
374 * The cover in this {@link MetaData} object is "fake", in the sens that it
375 * comes from the actual content images
378 * TRUE for a fake cover
380 public void setFakeCover(boolean fakeCover
) {
381 this.fakeCover
= fakeCover
;
385 public int compareTo(MetaData o
) {
390 String id
= (getUuid() == null ?
"" : getUuid())
391 + (getLuid() == null ?
"" : getLuid());
392 String oId
= (getUuid() == null ?
"" : o
.getUuid())
393 + (o
.getLuid() == null ?
"" : o
.getLuid());
395 return id
.compareTo(oId
);
399 public boolean equals(Object obj
) {
400 if (!(obj
instanceof MetaData
)) {
404 return compareTo((MetaData
) obj
) == 0;
408 public int hashCode() {
409 String uuid
= getUuid();
411 uuid
= "" + title
+ author
+ source
;
414 return uuid
.hashCode();
418 public MetaData
clone() {
419 MetaData meta
= null;
421 meta
= (MetaData
) super.clone();
422 } catch (CloneNotSupportedException e
) {
423 // Did the clones rebel?
424 System
.err
.println(e
);
428 meta
.tags
= new ArrayList
<String
>(tags
);
431 if (resume
!= null) {
432 meta
.resume
= resume
.clone();
439 * Display a DEBUG {@link String} representation of this object.
441 * This is not efficient, nor intended to be.
444 public String
toString() {
446 if (getTitle() != null) {
450 StringBuilder tags
= new StringBuilder();
451 if (getTags() != null) {
452 for (String tag
: getTags()) {
453 if (tags
.length() > 0) {
461 if (getResume() != null) {
462 for (Paragraph para
: getResume()) {
464 resume
+= para
.toString().substring(0,
465 Math
.min(para
.toString().length(), 120));
470 String cover
= "none";
471 if (getCover() != null) {
474 int size
= getCover().getData().length
;
484 cover
= size
+ cover
;
487 return String
.format(
488 "Meta %s:\n\tTitle: [%s]\n\tAuthor: [%s]\n\tDate: [%s]\n\tTags: [%s]"
489 + "\n\tResume: [%s]\n\tCover: [%s]", luid
, title
,
490 getAuthor(), getDate(), tags
.toString(), resume
, cover
);