Subversion Repositories SmartDukaan

Rev

Rev 450 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 450 Rev 455
Line 19... Line 19...
19
import java.io.FileInputStream;
19
import java.io.FileInputStream;
20
import java.io.FileOutputStream;
20
import java.io.FileOutputStream;
21
import java.io.InputStream;
21
import java.io.InputStream;
22
import java.io.OutputStream;
22
import java.io.OutputStream;
23
import java.net.URLDecoder;
23
import java.net.URLDecoder;
-
 
24
import java.util.ArrayList;
24
import java.util.Collection;
25
import java.util.Collection;
25
import java.util.HashMap;
26
import java.util.HashMap;
26
import java.util.List;
27
import java.util.List;
27
import java.util.Map;
28
import java.util.Map;
28
import java.util.StringTokenizer;
29
import java.util.StringTokenizer;
Line 32... Line 33...
32
import org.apache.juli.logging.LogFactory;
33
import org.apache.juli.logging.LogFactory;
33
import org.apache.struts2.convention.annotation.Result;
34
import org.apache.struts2.convention.annotation.Result;
34
import org.apache.struts2.convention.annotation.Results;
35
import org.apache.struts2.convention.annotation.Results;
35
import org.apache.struts2.rest.DefaultHttpHeaders;
36
import org.apache.struts2.rest.DefaultHttpHeaders;
36
import org.apache.struts2.rest.HttpHeaders;
37
import org.apache.struts2.rest.HttpHeaders;
-
 
38
import org.apache.struts2.views.xslt.ArrayAdapter;
37
 
39
 
38
/**
40
/**
39
 * @author naveen
41
 * @author naveen
40
 *
42
 *
41
 */
43
 */
Line 128... Line 130...
128
        			contentLabel = media.getLabel() + "~!~" + media.getLocation();
130
        			contentLabel = media.getLabel() + "~!~" + media.getLocation();
129
        			log.info("Type is youtube :" + contentLabel);
131
        			log.info("Type is youtube :" + contentLabel);
130
        		}
132
        		}
131
    			
133
    			
132
    			
134
    			
-
 
135
        		
133
    			EntityContainer enContainer = Catalog.getInstance().getEntityContainer();
136
    			Entity entity = CreationUtils.getEntity(Long.parseLong(this.entityID));
-
 
137
    			
134
    			Entity entity = enContainer.getEntity(Long.parseLong(this.entityID));
138
	    		Slide slide = entity.getSlide(Long.parseLong(this.slideID));
-
 
139
    			if(slide == null){
-
 
140
    				slide = new Slide(Long.parseLong(this.getSlideID()));
-
 
141
    				entity.addSlide(slide);
-
 
142
    			}
135
    			FreeformContent freeformContent = entity.getSlide(Long.parseLong(this.slideID)).getFreeformContent();
143
    			FreeformContent freeformContent = slide.getFreeformContent();
-
 
144
    			if(freeformContent == null){
-
 
145
    				freeformContent = new FreeformContent();
-
 
146
    				slide.setFreeformContent(freeformContent);
-
 
147
    			}
136
    			freeformContent.addMedia(media.getType(), contentLabel);
148
    			freeformContent.addMedia(media.getType(), contentLabel);
137
    			entity.getSlide(Long.parseLong(slideID)).setFreeformContent(freeformContent);
149
    			entity.getSlide(Long.parseLong(slideID)).setFreeformContent(freeformContent);
138
    			updateEntity(entity);
150
    			updateEntity(entity);
139
    			//CreationUtils.storeEntity(entity);
151
    			//CreationUtils.storeEntity(entity);
140
    		}
152
    		}
Line 177... Line 189...
177
    			contentLabel = media.getLabel() + "~!~" + media.getLocation();
189
    			contentLabel = media.getLabel() + "~!~" + media.getLocation();
178
    			log.info("Type is youtube :" + contentLabel);
190
    			log.info("Type is youtube :" + contentLabel);
179
    		}
191
    		}
180
			
192
			
181
			
193
			
182
    		Entity entity = Catalog.getInstance().getEntityContainer().getEntity(entityID);
194
    		Entity entity = CreationUtils.getEntity(Long.parseLong(this.entityID));
183
			FreeformContent freeformContent = entity.getSlide(slideID).getFreeformContent(); 
195
			FreeformContent freeformContent = entity.getSlide(slideID).getFreeformContent(); 
184
			freeformContent.removeMedia(media.getType(), contentLabel);
196
			freeformContent.removeMedia(media.getType(), contentLabel);
185
			entity.getSlide(slideID).setFreeformContent(freeformContent);
197
			entity.getSlide(slideID).setFreeformContent(freeformContent);
186
			updateEntity(entity);
198
			updateEntity(entity);
187
			//CreationUtils.storeEntity(entity);
199
			//CreationUtils.storeEntity(entity);
Line 201... Line 213...
201
     * @return
213
     * @return
202
     * @throws Exception 
214
     * @throws Exception 
203
     */
215
     */
204
    public Collection<Media> getMedia() throws Exception {
216
    public Collection<Media> getMedia() throws Exception {
205
    	Collection<Media> allMedia = null;
217
    	Collection<Media> allMedia = null;
-
 
218
    	Entity entity = CreationUtils.getEntity(Long.parseLong(getEntityID()));
-
 
219
    	if(entity != null){
-
 
220
	    	Slide slide = entity.getSlide(Long.parseLong(getSlideID()));
-
 
221
	    	if(slide != null && slide.getFreeformContent() != null){
-
 
222
	    		List<String> labels = slide.getFreeformContent().getAllLabels();
-
 
223
		    	
-
 
224
		    	if(labels != null){
-
 
225
		    		
206
    	if(this.rawMedia == null) {
226
		    		if(this.rawMedia == null) {
207
    		this.rawMedia = this.getRawMedia();
227
		        		this.rawMedia = this.getRawMedia();
-
 
228
		        	}
208
    		
229
		    	
209
    		if(this.rawMedia != null) {
230
		    		if(this.rawMedia != null) {
210
    			allMedia = rawMedia.values();
231
		    			allMedia = new ArrayList<Media>();
-
 
232
		    			for(String label: labels){
-
 
233
		    				allMedia.add(this.rawMedia.get(label));
-
 
234
		    			}
211
    		}
235
		    		}
-
 
236
		    	}
-
 
237
	    	}
212
    	}
238
    	}
213
    	
-
 
214
		return allMedia;
239
	    return allMedia;
215
    }
240
    }
216
	/**
241
	/**
217
	 * @param id the id to set
242
	 * @param id the id to set
218
	 */
243
	 */
219
	public void setSlideID(String id) {
244
	public void setSlideID(String id) {
Line 360... Line 385...
360
		if(rawMedia == null) {
385
		if(rawMedia == null) {
361
			rawMedia = new HashMap<String, Media>();
386
			rawMedia = new HashMap<String, Media>();
362
		}
387
		}
363
		rawMedia.put(media.getLabel(), media);
388
		rawMedia.put(media.getLabel(), media);
364
		
389
		
365
		DBUtils.store(rawMedia, Utils.MEDIA_DB_PATH + this.getEntityID() + 
390
		DBUtils.store(rawMedia, Utils.CONTENT_DB_PATH + "media" + File.separator + this.getEntityID() + 
366
				".ser");
391
				".ser");
367
	}
392
	}
368
 
393
 
369
    
394
    
370
    /**
395
    /**
Line 383... Line 408...
383
	/**
408
	/**
384
	 * 
409
	 * 
385
	 * @throws Exception
410
	 * @throws Exception
386
	 */
411
	 */
387
	private String storeFile() throws Exception {
412
	private String storeFile() throws Exception {
388
		String mediaDirPath = Utils.MEDIA_DB_PATH + this.getEntityID();
413
		String mediaDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator + this.getEntityID();
389
		File mediaDir = new File(mediaDirPath);
414
		File mediaDir = new File(mediaDirPath);
390
		if(!mediaDir.exists()) {
415
		if(!mediaDir.exists()) {
391
			mediaDir.mkdir();
416
			mediaDir.mkdir();
392
		}
417
		}
393
		
418
		
Line 398... Line 423...
398
		File uploadedPicFile = this.getPic();
423
		File uploadedPicFile = this.getPic();
399
 
424
 
400
		InputStream in = new FileInputStream(uploadedPicFile);
425
		InputStream in = new FileInputStream(uploadedPicFile);
401
		
426
		
402
		// appending output stream
427
		// appending output stream
-
 
428
		// @rajveer : replacing the existing file 
403
		OutputStream out = new FileOutputStream(mediaFile, true); 
429
		OutputStream out = new FileOutputStream(mediaFile); 
404
		
430
		
405
		try {
431
		try {
406
			IOUtils.copy(in, out);
432
			IOUtils.copy(in, out);
407
		}
433
		}
408
		finally {
434
		finally {