1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.net.InetAddress;
17 import java.net.UnknownHostException;
18 import java.util.List;
19 import java.util.Locale;
20 import java.util.Properties;
21
22 import org.springframework.beans.factory.annotation.Value;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.RequestMapping;
25 import org.springframework.web.servlet.ModelAndView;
26
27 import psiprobe.PostParameterizableViewController;
28 import psiprobe.Utils;
29
30
31
32
33 @Controller
34 public class DecoratorController extends PostParameterizableViewController {
35
36
37 private String messagesBasename;
38
39
40
41
42
43
44 public String getMessagesBasename() {
45 return messagesBasename;
46 }
47
48
49
50
51
52
53 @Value("/WEB-INF/messages")
54 public void setMessagesBasename(String messagesBasename) {
55 this.messagesBasename = messagesBasename;
56 }
57
58 @RequestMapping(path = "/decorator.htm")
59 @Override
60 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
61 throws Exception {
62 return super.handleRequest(request, response);
63 }
64
65 @Override
66 protected ModelAndView handleRequestInternal(HttpServletRequest request,
67 HttpServletResponse response) throws Exception {
68
69 try {
70 request.setAttribute("hostname", InetAddress.getLocalHost().getHostName());
71 } catch (UnknownHostException e) {
72 request.setAttribute("hostname", "unknown");
73 logger.trace("", e);
74 }
75
76 Properties version = (Properties) getApplicationContext().getBean("version");
77 request.setAttribute("version", version.getProperty("probe.version"));
78
79
80
81
82
83 String lang = "en";
84 for (String fileName : getMessageFileNamesForLocale(request.getLocale())) {
85 if (getServletContext().getResource(fileName + ".properties") != null) {
86 lang = fileName.substring(messagesBasename.length() + 1);
87 break;
88 }
89 }
90
91 request.setAttribute("lang", lang);
92
93 return super.handleRequestInternal(request, response);
94 }
95
96
97
98
99
100
101
102
103 private List<String> getMessageFileNamesForLocale(Locale locale) {
104 return Utils.getNamesForLocale(messagesBasename, locale);
105 }
106
107 @Value("decorators/probe")
108 @Override
109 public void setViewName(String viewName) {
110 super.setViewName(viewName);
111 }
112
113 }