Project

General

Profile

Download (2.77 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.remote.controller;
12

    
13
import java.io.IOException;
14
import java.net.URI;
15
import java.util.Arrays;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.Set;
19
import java.util.UUID;
20

    
21
import javax.servlet.http.HttpServletRequest;
22
import javax.servlet.http.HttpServletResponse;
23

    
24
import org.apache.http.HttpException;
25
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.stereotype.Controller;
27
import org.springframework.web.bind.annotation.PathVariable;
28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.servlet.ModelAndView;
30

    
31
import eu.etaxonomy.cdm.api.service.IMediaService;
32
import eu.etaxonomy.cdm.common.media.ImageInfo;
33
import eu.etaxonomy.cdm.model.media.Media;
34
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
35

    
36
/**
37
 * TODO write controller documentation
38
 * 
39
 * @author a.kohlbecker
40
 * @date 24.03.2009
41
 */
42

    
43
@Controller
44
@RequestMapping(value = {"/media/{uuid}"})
45
public class MediaController extends AnnotatableController<Media, IMediaService>
46
{
47
	
48
	/* (non-Javadoc)
49
	 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
50
	 */
51
	@Autowired
52
	@Override
53
	public void setService(IMediaService service) {
54
		this.service = service;
55
	}
56
	private static final List<String> MEDIA_INIT_STRATEGY = Arrays.asList(new String []{
57
			"*",
58
			"representations",
59
			"representations.parts"
60
	});
61
	
62
	@RequestMapping(value = {"metadata"})
63
	public ModelAndView doGetMediaMetaData(@PathVariable("uuid") UUID uuid,
64
			HttpServletRequest request, HttpServletResponse response) throws IOException {
65
		Map<String, String> result;
66
		Media media = getCdmBaseInstance(uuid, response, MEDIA_INIT_STRATEGY);
67
		
68
		Set<MediaRepresentation> representations = media.getRepresentations();
69
		//get first representation and retrieve the according metadata
70

    
71
		Object[] repArray = representations.toArray();
72
		Object mediaRep = repArray[0];
73
		ModelAndView mv = new ModelAndView();
74
		try {
75
			if (mediaRep instanceof MediaRepresentation){
76
				MediaRepresentation medRep = (MediaRepresentation) mediaRep;
77
				URI uri = medRep.getParts().get(0).getUri();
78
				ImageInfo imageInfo = ImageInfo.NewInstance(uri, 3000);
79
				imageInfo.readMetaData(3000);
80
				result = imageInfo.getMetaData();
81
				mv.addObject(result);
82
			}
83
		} catch (HttpException e) {
84
			// TODO Auto-generated catch block
85
			e.printStackTrace();
86
		}
87
		return mv;
88
		
89
	}
90

    
91
}
(25-25/48)