All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.siegmann.epublib.domain.Metadata Maven / Gradle / Ivy

The newest version!
package nl.siegmann.epublib.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;

import nl.siegmann.epublib.service.MediatypeService;
import nl.siegmann.epublib.util.StringUtil;

/**
 * A Book's collection of Metadata. In the future it should contain all Dublin
 * Core attributes, for now it contains a set of often-used ones.
 *
 * @author paul
 *
 */
public class Metadata implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -2437262888962149444L;

    public static final String DEFAULT_LANGUAGE = "en";

    private boolean autoGeneratedId = true;
    private List contributors = new ArrayList();
    private List creators = new ArrayList();
    private List dates = new ArrayList();
    private String language = DEFAULT_LANGUAGE;
    private Map otherProperties = new HashMap();
    private List rights = new ArrayList();
    private List titles = new ArrayList();
    private List identifiers = new ArrayList();
    private List subjects = new ArrayList();
    private String format = MediatypeService.EPUB.getName();
    private List types = new ArrayList();
    private List descriptions = new ArrayList();
    private List publishers = new ArrayList();
    private Map metaAttributes = new HashMap();
    private List coverages = new ArrayList();
    private List relations = new ArrayList();
    private List sources = new ArrayList();

    public Metadata() {
        identifiers.add(new Identifier());
        autoGeneratedId = true;
    }

    public boolean isAutoGeneratedId() {
        return autoGeneratedId;
    }

    /**
     * Metadata properties not hard-coded like the author, title, etc.
     *
     * @return Metadata properties not hard-coded like the author, title, etc.
     */
    public Map getOtherProperties() {
        return otherProperties;
    }

    public void setOtherProperties(Map otherProperties) {
        this.otherProperties = otherProperties;
    }

    public Date addDate(Date date) {
        this.dates.add(date);
        return date;
    }

    public List getDates() {
        return dates;
    }

    public void setDates(List dates) {
        this.dates = dates;
    }

    public CreatorContributor addContributor(CreatorContributor contributor) {
        contributors.add(contributor);
        return contributor;
    }

    public List getContributors() {
        return contributors;
    }

    public void setContributors(List contributors) {
        this.contributors = contributors;
    }

    public CreatorContributor addCreator(CreatorContributor creator) {
        creators.add(creator);
        return creator;
    }

    public List getCreators() {
        return creators;
    }

    public void setCreators(List creators) {
        this.creators = creators;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public List getSubjects() {
        return subjects;
    }

    public void setSubjects(List subjects) {
        this.subjects = subjects;
    }

    public void setRights(List rights) {
        this.rights = rights;
    }

    public List getRights() {
        return rights;
    }

    /**
     * Gets the first non-blank title of the book. Will return "" if no title
     * found.
     *
     * @return the first non-blank title of the book.
     */
    public String getFirstTitle() {
        if (titles == null || titles.isEmpty()) {
            return "";
        }
        for (String title : titles) {
            if (StringUtil.isNotBlank(title)) {
                return title;
            }
        }
        return "";
    }

    public String addTitle(String title) {
        this.titles.add(title);
        return title;
    }

    public void setTitles(List titles) {
        this.titles = titles;
    }

    public List getTitles() {
        return titles;
    }

    public String addPublisher(String publisher) {
        this.publishers.add(publisher);
        return publisher;
    }

    public void setPublishers(List publishers) {
        this.publishers = publishers;
    }

    public List getPublishers() {
        return publishers;
    }

    public String addDescription(String description) {
        this.descriptions.add(description);
        return description;
    }

    public void setDescriptions(List descriptions) {
        this.descriptions = descriptions;
    }

    public List getDescriptions() {
        return descriptions;
    }

    public Identifier addIdentifier(Identifier identifier) {
        if (autoGeneratedId && (!(identifiers.isEmpty()))) {
            identifiers.set(0, identifier);
        } else {
            identifiers.add(identifier);
        }
        autoGeneratedId = false;
        return identifier;
    }

    public void setIdentifiers(List identifiers) {
        this.identifiers = identifiers;
        autoGeneratedId = false;
    }

    public List getIdentifiers() {
        return identifiers;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getFormat() {
        return format;
    }

    public String addType(String type) {
        this.types.add(type);
        return type;
    }

    public List getTypes() {
        return types;
    }

    public void setTypes(List types) {
        this.types = types;
    }

    public String getMetaAttribute(String name) {
        return metaAttributes.get(name);
    }

    public void setMetaAttributes(Map metaAttributes) {
        this.metaAttributes = metaAttributes;
    }

    public List getAuthors() {
        ArrayList authors = new ArrayList();

        for (CreatorContributor c : creators) {
            if (c.getRelators().contains(Relator.AUTHOR)) {
                authors.add(c);
            }
        }

        for (CreatorContributor c : contributors) {
            if (c.getRelators().contains(Relator.AUTHOR)) {
                authors.add(c);
            }
        }

        return authors;
    }

    public List getCoverages() {
        return coverages;
    }

    public void setCoverages(List coverages) {
        this.coverages = coverages;
    }

    public List getRelations() {
        return relations;
    }

    public void setRelations(List relations) {
        this.relations = relations;
    }

    public List getSources() {
        return sources;
    }

    public void setSources(List sources) {
        this.sources = sources;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy