3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.remote
.controller
;
13 import java
.io
.IOException
;
15 import java
.net
.URISyntaxException
;
16 import java
.util
.Arrays
;
17 import java
.util
.List
;
21 import javax
.servlet
.http
.HttpServletRequest
;
22 import javax
.servlet
.http
.HttpServletResponse
;
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
;
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
;
36 * TODO write controller documentation
38 * @author a.kohlbecker
43 @RequestMapping(value
= {"/media/*","/media/*/annotation", "/media/*/metadata"})
44 public class MediaController
extends AnnotatableController
<Media
, IMediaService
>
47 public MediaController(){
49 setUuidParameterPattern("^/media/([^/?#&\\.]+).*");
53 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
57 public void setService(IMediaService service
) {
58 this.service
= service
;
60 private static final List
<String
> MEDIA_INIT_STRATEGY
= Arrays
.asList(new String
[]{
63 "representations.parts"
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);
71 Set
<MediaRepresentation
> representations
= media
.getRepresentations();
72 //get first representation and retrieve the according metadata
74 Object
[] repArray
= representations
.toArray();
75 Object mediaRep
= repArray
[0];
76 ModelAndView mv
= new ModelAndView();
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);
84 } catch (URISyntaxException e
) {
85 // TODO Auto-generated catch block