1 package org
.argeo
.slc
.web
.mvc
;
5 import javax
.servlet
.http
.HttpServletRequest
;
6 import javax
.servlet
.http
.HttpServletResponse
;
7 import javax
.xml
.transform
.stream
.StreamResult
;
9 import org
.argeo
.slc
.SlcException
;
10 import org
.springframework
.oxm
.Marshaller
;
11 import org
.springframework
.web
.servlet
.view
.AbstractView
;
13 /** Marshal one of the object of the map to the output. */
14 public class MarshallerView
extends AbstractView
{
15 private String modelKey
= null;
16 private final Marshaller marshaller
;
18 public MarshallerView(Marshaller marshaller
) {
19 this.marshaller
= marshaller
;
22 public MarshallerView(Marshaller marshaller
, String modelKey
) {
24 this.modelKey
= modelKey
;
28 protected void renderMergedOutputModel(Map model
,
29 HttpServletRequest request
, HttpServletResponse response
)
32 if (modelKey
!= null) {
33 if (!model
.containsKey(modelKey
))
34 throw new SlcException("Key " + modelKey
35 + " not found in model.");
36 answer
= model
.get(modelKey
);
38 if (model
.size() != 1)
39 throw new SlcException(
40 "Model has a size different from 1. Specify a modelKey.");
41 answer
= model
.values().iterator().next();
44 StreamResult streamResult
= new StreamResult(response
.getOutputStream());
45 marshaller
.marshal(answer
, streamResult
);
48 public void setModelKey(String modelKey
) {
49 this.modelKey
= modelKey
;