1 // $Id: RdfView.java 7479 2009-11-02 12:31:13Z ben.clark $
2 package eu
.etaxonomy
.cdm
.remote
.view
;
6 import javax
.servlet
.http
.HttpServletRequest
;
7 import javax
.servlet
.http
.HttpServletResponse
;
8 import javax
.xml
.transform
.stream
.StreamResult
;
10 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
11 import org
.springframework
.oxm
.Marshaller
;
12 import org
.springframework
.web
.servlet
.view
.AbstractView
;
14 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
17 * View class which takes a serializes a cdm object as xml
19 * @see javax.xml.transform.Source
20 * @see com.ibm.lsid.MetadataResponse
22 public class XmlView
extends AbstractView
{
24 private Marshaller marshaller
;
26 private boolean locationHeader
= false;
28 private String locationPrefix
= "";
30 public void setLocationHeader(boolean locationHeader
) {
31 this.locationHeader
= locationHeader
;
34 public void setLocationPrefix(String locationPrefix
) {
35 this.locationPrefix
= locationPrefix
;
43 public void setMarshaller(Marshaller marshaller
) {
44 this.marshaller
= marshaller
;
50 protected void renderMergedOutputModel(Map model
, HttpServletRequest request
, HttpServletResponse response
)
53 for(Object object
: model
.values()) {
54 if(object
instanceof IdentifiableEntity
) {
55 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
)object
;
57 response
.addHeader("Location", locationPrefix
+ identifiableEntity
.getUuid().toString());
59 marshaller
.marshal(identifiableEntity
, new StreamResult(response
.getOutputStream()));
60 } else if(object
instanceof Throwable
) {
61 eu
.etaxonomy
.cdm
.io
.jaxb
.Error error
= new eu
.etaxonomy
.cdm
.io
.jaxb
.Error((Throwable
)object
);
62 marshaller
.marshal(error
, new StreamResult(response
.getOutputStream()));