1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.util;
20
21 import javax.servlet.http.HttpServletRequest;
22
23 import org.springframework.web.context.request.RequestContextHolder;
24 import org.springframework.web.context.request.ServletRequestAttributes;
25
26 import com.vaadin.server.WebBrowser;
27
28
29
30
31 public final class WebBrowserUtil {
32
33
34 private static final String UNKNOWN = "unknown";
35
36
37 private static final String I_PHONE = "IPhone";
38
39
40 private static final String IPAD = "IPad";
41
42
43 private static final String IOS = "IOS";
44
45
46 private static final String ANDROID = "Android";
47
48
49 private static final String MAC_OSX = "MacOSX";
50
51
52 private static final String WINDOWS_PHONE = "WindowsPhone";
53
54
55 private static final String WINDOWS2 = "Windows";
56
57
58 private static final String LINUX = "Linux";
59
60
61 private static final String X_FORWARDED_FOR = "X-Forwarded-For";
62
63
64
65
66 private WebBrowserUtil() {
67 super();
68 }
69
70
71
72
73
74
75
76
77
78 public static String getIpInformation(final WebBrowser webBrowser) {
79 String ipInformation=webBrowser.getAddress();
80
81 final HttpServletRequest httpRequest=((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
82 final String xForwardedForHeader = httpRequest.getHeader(X_FORWARDED_FOR);
83 if (xForwardedForHeader != null) {
84 final String[] split = xForwardedForHeader.split(",");
85 if (split.length != 0) {
86 ipInformation = split[0];
87 }
88 }
89 return ipInformation;
90 }
91
92
93
94
95
96
97
98
99
100 public static String getOperatingSystem(final WebBrowser webBrowser) {
101 String osName = UNKNOWN;
102 if (webBrowser.isLinux()) {
103 osName = LINUX;
104 } else if (webBrowser.isWindows()) {
105 osName = WINDOWS2;
106 } else if (webBrowser.isWindowsPhone()) {
107 osName = WINDOWS_PHONE;
108 } else if (webBrowser.isMacOSX()) {
109 osName = MAC_OSX;
110 } else if (webBrowser.isAndroid()) {
111 osName = ANDROID;
112 } else if (webBrowser.isIOS()) {
113 osName = IOS;
114 } else if (webBrowser.isIPad()) {
115 osName = IPAD;
116 } else if (webBrowser.isIPhone()) {
117 osName = I_PHONE;
118 }
119 return osName;
120 }
121
122
123 }