1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import jakarta.inject.Inject;
16 import jakarta.servlet.http.HttpServletRequest;
17 import jakarta.servlet.http.HttpServletResponse;
18
19 import org.springframework.beans.factory.annotation.Value;
20 import org.springframework.web.bind.annotation.RequestMapping;
21 import org.springframework.web.servlet.ModelAndView;
22 import org.springframework.web.servlet.mvc.AbstractController;
23 import org.springframework.web.servlet.mvc.Controller;
24
25 import psiprobe.model.TransportableModel;
26
27
28
29
30 @org.springframework.stereotype.Controller
31 public class BeanToXmlController extends AbstractController {
32
33
34 private String xmlMarker;
35
36
37 @Inject
38 private XStream xstream;
39
40
41
42
43
44
45 public String getXmlMarker() {
46 return xmlMarker;
47 }
48
49
50
51
52
53
54 @Value(".oxml")
55 public void setXmlMarker(String xmlMarker) {
56 this.xmlMarker = xmlMarker;
57 }
58
59 @RequestMapping(path = "/*.oxml.htm")
60 @Override
61 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
62 throws Exception {
63 return super.handleRequest(request, response);
64 }
65
66 @Override
67 protected ModelAndView handleRequestInternal(HttpServletRequest request,
68 HttpServletResponse response) throws Exception {
69
70 String path = request.getServletPath();
71 String internalPath = path.replaceAll(xmlMarker, "");
72
73 Controller controller = (Controller) getApplicationContext().getBean(internalPath);
74 if (controller != null) {
75 ModelAndView modelAndView = controller.handleRequest(request, response);
76 if (modelAndView.getModel() != null) {
77 TransportableModel tm = new TransportableModel();
78 tm.putAll(modelAndView.getModel());
79 xstream.toXML(tm, response.getWriter());
80 }
81 }
82 return null;
83 }
84 }