1 package org
.argeo
.slc
.web
.mvc
;
3 import java
.util
.Iterator
;
6 import javax
.servlet
.http
.HttpServletRequest
;
7 import javax
.servlet
.http
.HttpServletResponse
;
8 import javax
.xml
.transform
.stream
.StreamResult
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.slc
.SlcException
;
13 import org
.springframework
.oxm
.Marshaller
;
14 import org
.springframework
.web
.servlet
.view
.AbstractView
;
16 /** Marshal one of the object of the map to the output. */
17 public class MarshallerView
extends AbstractView
{
19 private final static Log log
= LogFactory
20 .getLog(MarshallerView
.class);
23 private String modelKey
= null;
24 private final Marshaller marshaller
;
26 public MarshallerView(Marshaller marshaller
) {
27 this.marshaller
= marshaller
;
30 public MarshallerView(Marshaller marshaller
, String modelKey
) {
32 this.modelKey
= modelKey
;
36 @SuppressWarnings(value
={"unchecked"})
37 protected void renderMergedOutputModel(Map model
,
38 HttpServletRequest request
, HttpServletResponse response
)
42 if (log
.isDebugEnabled()){
43 //log.debug("In MarshallerView :: renderMergedOutputModel");
44 if (modelKey
!= null )
45 log
.debug("Model key : ["+modelKey
+"]");
46 else log
.debug("ModelKey is null");
49 //TODO : remove this loop
50 if (log
.isDebugEnabled()){
51 Iterator it
= model
.keySet().iterator();
54 log
.debug(i
++ + " [" + it
.next().toString()+ "]");
57 if (modelKey
!= null) {
58 if (!model
.containsKey(modelKey
)){
59 /** //TODO : remove this loop
60 if (log.isDebugEnabled()){
61 log.debug("Key not found in Model. Available keys are : ");
62 for (Object key : model.keySet()){
63 log.debug(key.toString());
67 throw new SlcException("Key " + modelKey
68 + " not found in model.");
70 answer
= model
.get(modelKey
);
72 if (model
.size() != 1)
73 throw new SlcException(
74 "Model has a size different from 1. Specify a modelKey.");
75 answer
= model
.values().iterator().next();
78 StreamResult streamResult
= new StreamResult(response
.getOutputStream());
79 marshaller
.marshal(answer
, streamResult
);
82 public void setModelKey(String modelKey
) {
83 this.modelKey
= modelKey
;