Subversion Repositories SmartDukaan

Rev

Rev 2720 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.metamodel.core;

import in.shop2020.metamodel.util.MetaModelComponent;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;

/**
 * @author naveen
 * 
 */
public class Media extends MetaModelComponent {
    Media() {
        }

        /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public static enum Type {
        IMAGE("file"),
        VIDEO_WITH_SKIN("text"),
        VIDEO_WITHOUT_SKIN("text"),
        DOCUMENT("file");

        String inputType;
        Type(String inputType) {
            this.inputType = inputType;
        }
        public String getInputType() {
            return inputType;
        }
    }

    /**
     * 
     */
    private String label;
    private Type   type;
    private String title;
    private String location;
    private Date   creationTime;  

    // used only for images and documents
    private String fileName;
    /**
     * 
     * @param label
     * @param type
     * @param location
     */
    public Media(String label, Type type, String location) {
        this.label        = label;
        this.type         = type;
        this.location     = location;
        this.creationTime = new Date();
    }

    /**
     * @param label
     *            the label to set
     */
    public void setLabel(String label) {
        this.label = label;
    }

    /**
     * @return the label
     */
    public String getLabel() {
        return label;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    /**
     * @return the label
     */
    public String getEncodedLabel() {
        try {
            return URLEncoder.encode(label, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // CreationUtils.getStackTrace(e);
            e.printStackTrace();
            return "";
        }
    }

    /**
     * @param type
     *            the type to set
     */
    public void setType(Type type) {
        this.type = type;
    }

    /**
     * @return the type
     */
    public Type getType() {
        return type;
    }

    /**
     * @param location
     *            the location to set
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * @return the location
     */
    public String getLocation() {
        return location;
    }

    /**
     * parse the youtube url and return youtube id
     * 
     * @return the youtube id.
     */
    public String getYoutubeId() {
        String[] token = location.split("\\?v=");
        if (token.length == 2) {
            return token[1];
        }
        return "";
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "Media [label=" + label + ", location=" + location + ", type="
                + type + "]";
    }

    public Date getCreationTime() {
        return creationTime;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
}