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.net.URISyntaxException;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.List;
|
18
|
import java.util.Map;
|
19
|
import java.util.Set;
|
20
|
|
21
|
import javax.servlet.http.HttpServletRequest;
|
22
|
import javax.servlet.http.HttpServletResponse;
|
23
|
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
import org.springframework.stereotype.Controller;
|
26
|
import org.springframework.web.bind.annotation.RequestMapping;
|
27
|
import org.springframework.web.servlet.ModelAndView;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
30
|
import eu.etaxonomy.cdm.common.mediaMetaData.MediaMetaData;
|
31
|
import eu.etaxonomy.cdm.model.common.Representation;
|
32
|
import eu.etaxonomy.cdm.model.media.Media;
|
33
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
34
|
|
35
|
/**
|
36
|
* TODO write controller documentation
|
37
|
*
|
38
|
* @author a.kohlbecker
|
39
|
* @date 24.03.2009
|
40
|
*/
|
41
|
|
42
|
@Controller
|
43
|
@RequestMapping(value = {"/media/*","/media/*/annotation", "/media/*/metadata"})
|
44
|
public class MediaController extends AnnotatableController<Media, IMediaService>
|
45
|
{
|
46
|
|
47
|
public MediaController(){
|
48
|
super();
|
49
|
setUuidParameterPattern("^/media/([^/?#&\\.]+).*");
|
50
|
}
|
51
|
|
52
|
/* (non-Javadoc)
|
53
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
54
|
*/
|
55
|
@Autowired
|
56
|
@Override
|
57
|
public void setService(IMediaService service) {
|
58
|
this.service = service;
|
59
|
}
|
60
|
private static final List<String> MEDIA_INIT_STRATEGY = Arrays.asList(new String []{
|
61
|
"*",
|
62
|
"representations",
|
63
|
"representations.parts"
|
64
|
});
|
65
|
|
66
|
@RequestMapping(value = {"/media/*/metadata"})
|
67
|
public ModelAndView doGetMediaMetaData(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
68
|
Map<String, String> result;
|
69
|
Media media = getCdmBase(request, response, MEDIA_INIT_STRATEGY, Media.class);
|
70
|
|
71
|
Set<MediaRepresentation> representations = media.getRepresentations();
|
72
|
//get first representation and retrieve the according metadata
|
73
|
|
74
|
Object[] repArray = representations.toArray();
|
75
|
Object mediaRep = repArray[0];
|
76
|
ModelAndView mv = new ModelAndView();
|
77
|
try {
|
78
|
if (mediaRep instanceof MediaRepresentation){
|
79
|
MediaRepresentation medRep = (MediaRepresentation) mediaRep;
|
80
|
String uriString = medRep.getParts().get(0).getUri();
|
81
|
result = service.getImageMetaData(new URI(uriString), 3000);
|
82
|
mv.addObject(result);
|
83
|
}
|
84
|
} catch (URISyntaxException e) {
|
85
|
// TODO Auto-generated catch block
|
86
|
e.printStackTrace();
|
87
|
}
|
88
|
return mv;
|
89
|
|
90
|
}
|
91
|
|
92
|
}
|