Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 shop2020 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.core;
5
 
199 naveen 6
import java.util.ArrayList;
211 naveen 7
import java.util.HashMap;
199 naveen 8
import java.util.List;
211 naveen 9
import java.util.Map;
451 rajveer 10
import java.util.StringTokenizer;
199 naveen 11
 
10 shop2020 12
import in.shop2020.metamodel.util.MetaModelComponent;
13
 
14
/**
45 naveen 15
 * Represents un-structured data about Slide, Feature and Bullet. It is used
16
 * judiciously by content developers to store multi-media content in support
17
 * component they are attached to.
10 shop2020 18
 * 
19
 * @author naveen
20
 *
21
 */
22
public class FreeformContent extends MetaModelComponent {
23
 
24
	/**
25
	 * 
26
	 */
27
	private static final long serialVersionUID = 1L;
28
 
199 naveen 29
	// Un-structured text only
30
	private List<String> freeformTexts;
10 shop2020 31
 
211 naveen 32
	private Map<String, List<String>> mediaRefs;
33
 
10 shop2020 34
    /**
35
     * 
36
     */
199 naveen 37
    public FreeformContent() {
10 shop2020 38
    }
39
 
40
    /**
41
     * 
199 naveen 42
     * @param freeformText
10 shop2020 43
     */
199 naveen 44
    public FreeformContent(String freeformText) {
45
    	this.addFreeformText(freeformText);
10 shop2020 46
    }
47
 
199 naveen 48
	/**
49
	 * @param freeformTexts the freeformTexts to set
50
	 */
51
	public void setFreeformTexts(List<String> freeformTexts) {
52
		this.freeformTexts = freeformTexts;
53
	}
54
 
55
	/**
56
	 * 
57
	 * @param fft
58
	 */
59
	public void addFreeformText(String fft) {
60
		if(this.freeformTexts == null) {
61
			this.freeformTexts = new ArrayList<String>();
62
		}
63
 
64
		this.freeformTexts.add(fft);
65
	}
66
 
67
	/**
68
	 * @return the freeformTexts
69
	 */
70
	public List<String> getFreeformTexts() {
71
		return freeformTexts;
72
	}
73
 
74
 
75
	/**
76
	 * Return first free-form text
77
	 * 
78
	 * @return the freeformTexts
79
	 */
80
	public String getFreeformText() {
81
		if(this.freeformTexts != null && this.freeformTexts.size() > 0) {
82
			return this.freeformTexts.get(0);
83
		}
84
 
85
		return null;
86
	}
211 naveen 87
 
199 naveen 88
	/**
211 naveen 89
	 * Convenience method to add new image Refs
90
	 * 
91
	 * @param imgURL
199 naveen 92
	 */
211 naveen 93
	public void addMedia(String type, String mediaRef) {
94
		if(this.mediaRefs == null) {
95
			this.mediaRefs = new HashMap<String, List<String>>();
96
		}
97
 
98
		List<String> typeRefs = this.mediaRefs.get(type);
99
		if(typeRefs == null) {
100
			typeRefs = new ArrayList<String>();
101
			this.mediaRefs.put(type, typeRefs);
102
		}
103
 
104
		typeRefs.add(mediaRef);
199 naveen 105
	}
106
 
451 rajveer 107
 
108
	/**
109
	 * Convenience method to add new image Refs
110
	 * 
111
	 * @param imgURL
112
	 */
113
	public void removeMedia(String type, String label) {
114
		if(this.mediaRefs == null) {
115
			return;
116
		}
117
 
118
		List<String> typeRefs = this.mediaRefs.get(type);
119
		if(typeRefs == null) {
120
			return;
121
		}
122
		typeRefs.remove(label);
123
	}
211 naveen 124
 
451 rajveer 125
 
199 naveen 126
	/**
211 naveen 127
	 * Convenience method to add new image Refs
199 naveen 128
	 * 
129
	 * @param imgURL
130
	 */
211 naveen 131
	public void setMedia(String type, List<String> mediaRefs) {
132
		if(this.mediaRefs == null) {
133
			this.mediaRefs = new HashMap<String, List<String>>();
199 naveen 134
		}
135
 
211 naveen 136
		this.mediaRefs.put(type, mediaRefs);
199 naveen 137
	}
138
 
139
	/**
211 naveen 140
	 * @return the imageRefs
199 naveen 141
	 */
211 naveen 142
	public List<String> getImageRefs() {
143
		if(this.mediaRefs != null) {
144
			return this.mediaRefs.get("image");
199 naveen 145
		}
146
 
211 naveen 147
		return null;
199 naveen 148
	}
149
 
150
	/**
151
	 * @return the youtubeURLs
152
	 */
211 naveen 153
	public List<String> getYoutubeRefs() {
154
		if(this.mediaRefs != null) {
155
			return this.mediaRefs.get("youtube");
156
		}
157
 
158
		return null;
199 naveen 159
	}
160
 
451 rajveer 161
	/**
162
	 * @return the imageRefs
163
	 */
164
	public List<Map<String, String>> getImageDetails() {
165
		if(this.mediaRefs != null) {
166
			List<String> imageDetails = this.mediaRefs.get("image");
167
			List<Map<String, String>> imageDetailsList = new ArrayList<Map<String,String>>();
168
			if(imageDetails == null)
169
				return null;
170
 
171
			for(String imageDetail: imageDetails){
172
				StringTokenizer tokenizer = new StringTokenizer(imageDetail,"~!~");
173
				String label = tokenizer.nextToken();
174
				String name = tokenizer.nextToken();
175
				HashMap<String, String> imageInfoMap = new HashMap<String, String>();
176
				imageInfoMap.put("label", label);
177
				imageInfoMap.put("name", name);
178
				imageDetailsList.add(imageInfoMap);
179
			}
180
			return imageDetailsList;
181
		}
182
 
183
		return null;
184
	}
185
 
186
	/**
187
	 * @return the youtubeURLs
188
	 */
189
	public List<Map<String,String>> getVideoDetails() {
190
		if(this.mediaRefs != null) {
191
			List<String> videoDetails = this.mediaRefs.get("youtube");
192
			if(videoDetails == null)
193
				return null;
194
			List<Map<String, String>> videoDetailsList = new ArrayList<Map<String,String>>();
195
 
196
			for(String videoDetail: videoDetails){
197
				StringTokenizer tokenizer = new StringTokenizer(videoDetail,"~!~");
198
				String label = tokenizer.nextToken();
199
				String url = tokenizer.nextToken();
200
				StringTokenizer urlTokenizer = new StringTokenizer(url,"=");
201
				urlTokenizer.nextToken();
202
				String videoId = urlTokenizer.nextToken();
203
				HashMap<String, String> videoInfoMap = new HashMap<String, String>();
204
				videoInfoMap.put("label", label);
205
				videoInfoMap.put("videoid", videoId);
206
				videoDetailsList.add(videoInfoMap);
207
			}
208
			return videoDetailsList;
209
 
210
		}
211
 
212
		return null;
213
	}
214
 
34 naveen 215
	/* (non-Javadoc)
216
	 * @see java.lang.Object#toString()
217
	 */
218
	@Override
219
	public String toString() {
199 naveen 220
		return "FreeformContent [freeformTexts=" + freeformTexts
211 naveen 221
				+ ", mediaRefs=" + mediaRefs + "]";
34 naveen 222
	}
223
 
10 shop2020 224
}