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.
10 package eu
.etaxonomy
.cdm
.remote
.service
;
12 import java
.util
.StringTokenizer
;
13 import java
.util
.Vector
;
15 import eu
.etaxonomy
.cdm
.api
.service
.lsid
.LSIDMetadataService
;
16 import eu
.etaxonomy
.cdm
.model
.common
.IIdentifiableEntity
;
17 import eu
.etaxonomy
.cdm
.model
.common
.LSID
;
18 import eu
.etaxonomy
.cdm
.remote
.editor
.LSIDPropertyEditor
;
20 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
21 import org
.springframework
.stereotype
.Controller
;
22 import org
.springframework
.web
.bind
.WebDataBinder
;
23 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
24 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
25 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
26 import org
.springframework
.web
.servlet
.ModelAndView
;
28 import com
.ibm
.lsid
.LSIDException
;
29 import com
.ibm
.lsid
.MetadataResponse
;
30 import com
.ibm
.lsid
.server
.LSIDServerException
;
33 * Controller which accepts requests for the metadata representation of an object
37 * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
38 * @see com.ibm.lsid.server.servlet.MetadataServlet
41 public class MetadataController
{
43 private LSIDMetadataService lsidMetadataService
;
46 public void setLsidMetadataService(LSIDMetadataService lsidMetadataService
) {
47 this.lsidMetadataService
= lsidMetadataService
;
51 public void initBinder(WebDataBinder binder
) {
52 binder
.registerCustomEditor(LSID
.class, new LSIDPropertyEditor());
56 * Handle requests for the metadata representation of an object with a given lsid. Will return metadata in any format supported
57 * from a list of formats if specified.
59 * @param lsid the lsid to get metadata for
60 * @param formats a comma separated list of acceptable formats to the client
61 * @return ModelAndView containing the metadata response as an object with key 'metadataResponse', view name 'Metadata.rdf'
62 * @throws LSIDServerException
64 @RequestMapping(value
= "/authority/metadata.do", params
= "lsid")
65 public ModelAndView
getMetadata(@RequestParam("lsid") LSID lsid
,
66 @RequestParam(value
= "acceptedFormats", required
= false) String formats
) throws LSIDServerException
{
67 String
[] acceptedFormats
= null;
68 if (formats
!= null) {
69 StringTokenizer st
= new StringTokenizer(formats
,",",false);
70 Vector
<String
> v
= new Vector
<String
>();
71 while (st
.hasMoreTokens()) {
72 v
.add(st
.nextToken());
74 acceptedFormats
= new String
[v
.size()];
75 v
.toArray(acceptedFormats
);
78 if (acceptedFormats
!= null) {
79 boolean found
= false;
80 for (int i
=0;i
<acceptedFormats
.length
;i
++) {
81 if (acceptedFormats
[i
].equals(MetadataResponse
.RDF_FORMAT
))
86 throw new LSIDServerException(LSIDServerException
.NO_METADATA_AVAILABLE_FOR_FORMATS
,"No metadata found for given format");
90 IIdentifiableEntity identifiableEntity
= lsidMetadataService
.getMetadata(lsid
);
91 ModelAndView modelAndView
= new ModelAndView("Metadata.rdf");
92 modelAndView
.addObject(identifiableEntity
);
96 @RequestMapping(value
= "/authority/metadata.do", params
= "!lsid")
97 public ModelAndView
getMetadata() throws LSIDException
{
98 throw new LSIDException(LSIDException
.INVALID_METHOD_CALL
, "Must specify HTTP Parameter 'lsid'");