Subversion Repositories SmartDukaan

Rev

Rev 211 | Rev 451 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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

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

import in.shop2020.metamodel.util.MetaModelComponent;

/**
 * Represents un-structured data about Slide, Feature and Bullet. It is used
 * judiciously by content developers to store multi-media content in support
 * component they are attached to.
 * 
 * @author naveen
 *
 */
public class FreeformContent extends MetaModelComponent {
        
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        
        // Un-structured text only
        private List<String> freeformTexts;

        private Map<String, List<String>> mediaRefs;
        
    /**
     * 
     */
    public FreeformContent() {
    }

    /**
     * 
     * @param freeformText
     */
    public FreeformContent(String freeformText) {
        this.addFreeformText(freeformText);
    }

        /**
         * @param freeformTexts the freeformTexts to set
         */
        public void setFreeformTexts(List<String> freeformTexts) {
                this.freeformTexts = freeformTexts;
        }
        
        /**
         * 
         * @param fft
         */
        public void addFreeformText(String fft) {
                if(this.freeformTexts == null) {
                        this.freeformTexts = new ArrayList<String>();
                }
                
                this.freeformTexts.add(fft);
        }
        
        /**
         * @return the freeformTexts
         */
        public List<String> getFreeformTexts() {
                return freeformTexts;
        }

        
        /**
         * Return first free-form text
         * 
         * @return the freeformTexts
         */
        public String getFreeformText() {
                if(this.freeformTexts != null && this.freeformTexts.size() > 0) {
                        return this.freeformTexts.get(0);
                }
                
                return null;
        }

        /**
         * Convenience method to add new image Refs
         * 
         * @param imgURL
         */
        public void addMedia(String type, String mediaRef) {
                if(this.mediaRefs == null) {
                        this.mediaRefs = new HashMap<String, List<String>>();
                }
                
                List<String> typeRefs = this.mediaRefs.get(type);
                if(typeRefs == null) {
                        typeRefs = new ArrayList<String>();
                        this.mediaRefs.put(type, typeRefs);
                }
                
                typeRefs.add(mediaRef);
        }


        /**
         * Convenience method to add new image Refs
         * 
         * @param imgURL
         */
        public void setMedia(String type, List<String> mediaRefs) {
                if(this.mediaRefs == null) {
                        this.mediaRefs = new HashMap<String, List<String>>();
                }
                
                this.mediaRefs.put(type, mediaRefs);
        }
        
        /**
         * @return the imageRefs
         */
        public List<String> getImageRefs() {
                if(this.mediaRefs != null) {
                        return this.mediaRefs.get("image");
                }
                
                return null;
        }
        
        /**
         * @return the youtubeURLs
         */
        public List<String> getYoutubeRefs() {
                if(this.mediaRefs != null) {
                        return this.mediaRefs.get("youtube");
                }
                
                return null;
        }

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

}