// $Id$\r
/**\r
* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \r
+*\r
* The contents of this file are subject to the Mozilla Public License Version 1.1\r
* See LICENSE.TXT at the top of this package for the full license terms.\r
*/\r
\r
/**\r
* TODO write controller documentation\r
- * \r
+ *\r
* @author a.kohlbecker\r
* @date 24.03.2009\r
*/\r
\r
@Controller\r
@RequestMapping(value = {"/media/{uuid}"})\r
-public class MediaController extends AnnotatableController<Media, IMediaService>\r
+public class MediaController extends BaseController<Media, IMediaService>\r
{\r
- \r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)\r
- */\r
- @Autowired\r
- @Override\r
- public void setService(IMediaService service) {\r
- this.service = service;\r
- }\r
- private static final List<String> MEDIA_INIT_STRATEGY = Arrays.asList(new String []{\r
- "*",\r
- "representations",\r
- "representations.parts"\r
- });\r
- \r
- @RequestMapping(value = {"metadata"})\r
- public ModelAndView doGetMediaMetaData(@PathVariable("uuid") UUID uuid,\r
- HttpServletRequest request, HttpServletResponse response) throws IOException {\r
- Map<String, String> result;\r
- Media media = getCdmBaseInstance(uuid, response, MEDIA_INIT_STRATEGY);\r
- \r
- Set<MediaRepresentation> representations = media.getRepresentations();\r
- //get first representation and retrieve the according metadata\r
\r
- Object[] repArray = representations.toArray();\r
- Object mediaRep = repArray[0];\r
- ModelAndView mv = new ModelAndView();\r
- try {\r
- if (mediaRep instanceof MediaRepresentation){\r
- MediaRepresentation medRep = (MediaRepresentation) mediaRep;\r
- URI uri = medRep.getParts().get(0).getUri();\r
- ImageInfo imageInfo = ImageInfo.NewInstance(uri, 3000);\r
- imageInfo.readMetaData(3000);\r
- result = imageInfo.getMetaData();\r
- mv.addObject(result);\r
- }\r
- } catch (HttpException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
- return mv;\r
- \r
- }\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)\r
+ */\r
+ @Autowired\r
+ @Override\r
+ public void setService(IMediaService service) {\r
+ this.service = service;\r
+ }\r
+ private static final List<String> MEDIA_INIT_STRATEGY = Arrays.asList(new String []{\r
+ "*",\r
+ "representations",\r
+ "representations.parts"\r
+ });\r
+\r
+ @RequestMapping(value = {"metadata"})\r
+ public ModelAndView doGetMediaMetaData(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response) throws IOException {\r
+ Map<String, String> result;\r
+ Media media = getCdmBaseInstance(uuid, response, MEDIA_INIT_STRATEGY);\r
+\r
+ Set<MediaRepresentation> representations = media.getRepresentations();\r
+ //get first representation and retrieve the according metadata\r
+\r
+ Object[] repArray = representations.toArray();\r
+ Object mediaRep = repArray[0];\r
+ ModelAndView mv = new ModelAndView();\r
+ URI uri = null;\r
+ try {\r
+ if (mediaRep instanceof MediaRepresentation){\r
+ MediaRepresentation medRep = (MediaRepresentation) mediaRep;\r
+ uri = medRep.getParts().get(0).getUri();\r
+ ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 3000);\r
+ result = imageInfo.getMetaData();\r
+ if(result != null) {\r
+ mv.addObject(result);\r
+ }\r
+ }\r
+ } catch (HttpException e) {\r
+ HttpStatusMessage.fromString("Reading media file from " + uri.toString() + " failed").setStatusCode(400).send(response);\r
+ }\r
+ return mv;\r
+\r
+ }\r
\r
}\r