Search in sources :

Example 6 with WebBrowser

use of com.vaadin.server.WebBrowser in project cuba by cuba-platform.

the class WebDeviceInfoProvider method getDeviceInfo.

@Nullable
@Override
public DeviceInfo getDeviceInfo() {
    // per request cache
    HttpServletRequest currentServletRequest = VaadinServletService.getCurrentServletRequest();
    if (currentServletRequest == null) {
        return null;
    }
    DeviceInfo deviceInfo = (DeviceInfo) currentServletRequest.getAttribute(DeviceInfoProvider.NAME);
    if (deviceInfo != null) {
        return deviceInfo;
    }
    Page page = Page.getCurrent();
    if (page == null) {
        return null;
    }
    WebBrowser webBrowser = page.getWebBrowser();
    DeviceInfo di = new DeviceInfo();
    di.setAddress(webBrowser.getAddress());
    di.setBrowserApplication(webBrowser.getBrowserApplication());
    di.setBrowserMajorVersion(webBrowser.getBrowserMajorVersion());
    di.setBrowserMinorVersion(webBrowser.getBrowserMinorVersion());
    di.setChrome(webBrowser.isChrome());
    di.setChromeFrame(webBrowser.isChromeFrame());
    di.setChromeFrameCapable(webBrowser.isChromeFrameCapable());
    di.setEdge(webBrowser.isEdge());
    di.setFirefox(webBrowser.isFirefox());
    di.setOpera(webBrowser.isOpera());
    di.setIE(webBrowser.isIE());
    if (webBrowser.isWindows()) {
        di.setOperatingSystem(OperatingSystem.WINDOWS);
    } else if (webBrowser.isAndroid()) {
        di.setOperatingSystem(OperatingSystem.ANDROID);
    } else if (webBrowser.isIOS()) {
        di.setOperatingSystem(OperatingSystem.IOS);
    } else if (webBrowser.isMacOSX()) {
        di.setOperatingSystem(OperatingSystem.MACOSX);
    } else if (webBrowser.isLinux()) {
        di.setOperatingSystem(OperatingSystem.LINUX);
    }
    di.setIPad(webBrowser.isIPad());
    di.setIPhone(webBrowser.isIPhone());
    di.setWindowsPhone(webBrowser.isWindowsPhone());
    di.setSecureConnection(webBrowser.isSecureConnection());
    di.setLocale(webBrowser.getLocale());
    di.setScreenHeight(webBrowser.getScreenHeight());
    di.setScreenWidth(webBrowser.getScreenWidth());
    currentServletRequest.setAttribute(DeviceInfoProvider.NAME, di);
    return di;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebBrowser(com.vaadin.server.WebBrowser) DeviceInfo(com.haulmont.cuba.gui.config.DeviceInfo) Page(com.vaadin.server.Page) Nullable(javax.annotation.Nullable)

Example 7 with WebBrowser

use of com.vaadin.server.WebBrowser in project cia by Hack23.

the class CitizenIntelligenceAgencyUI method init.

@Override
protected void init(final VaadinRequest request) {
    VaadinSession.getCurrent().setErrorHandler(new UiInstanceErrorHandler(this));
    setSizeFull();
    springNavigator.addView(CRLF_REPLACEMENT, mainView);
    setNavigator(springNavigator);
    final Page currentPage = Page.getCurrent();
    final String requestUrl = currentPage.getLocation().toString();
    final String language = request.getLocale().getLanguage();
    final UserConfiguration userConfiguration = configurationManager.getUserConfiguration(requestUrl, language);
    currentPage.setTitle(userConfiguration.getAgency().getAgencyName() + ":" + userConfiguration.getPortal().getPortalName() + ":" + userConfiguration.getLanguage().getLanguageName());
    if (getSession().getUIs().isEmpty()) {
        final WebBrowser webBrowser = currentPage.getWebBrowser();
        final CreateApplicationSessionRequest serviceRequest = new CreateApplicationSessionRequest();
        serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
        final String ipInformation = WebBrowserUtil.getIpInformation(webBrowser);
        serviceRequest.setIpInformation(ipInformation);
        serviceRequest.setTimeZone(webBrowser.getTimeZoneId());
        serviceRequest.setScreenSize(webBrowser.getScreenWidth() + "x" + webBrowser.getScreenHeight());
        serviceRequest.setUserAgentInformation(webBrowser.getBrowserApplication());
        serviceRequest.setLocale(webBrowser.getLocale().toString());
        serviceRequest.setOperatingSystem(WebBrowserUtil.getOperatingSystem(webBrowser));
        serviceRequest.setSessionType(ApplicationSessionType.ANONYMOUS);
        final ServiceResponse serviceResponse = applicationManager.service(serviceRequest);
        LOGGER.info(LOG_INFO_BROWSER_ADDRESS_APPLICATION_SESSION_ID_RESULT, requestUrl.replaceAll(CRLF, CRLF_REPLACEMENT), language.replaceAll(CRLF, CRLF_REPLACEMENT), ipInformation.replaceAll(CRLF, CRLF_REPLACEMENT), webBrowser.getBrowserApplication().replaceAll(CRLF, CRLF_REPLACEMENT), serviceRequest.getSessionId().replaceAll(CRLF, CRLF_REPLACEMENT), serviceResponse.getResult().toString().replaceAll(CRLF, CRLF_REPLACEMENT));
    }
}
Also used : ServiceResponse(com.hack23.cia.service.api.action.common.ServiceResponse) WebBrowser(com.vaadin.server.WebBrowser) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) Page(com.vaadin.server.Page) UserConfiguration(com.hack23.cia.service.api.UserConfiguration)

Aggregations

WebBrowser (com.vaadin.server.WebBrowser)7 Page (com.vaadin.server.Page)2 UserConfiguration (com.hack23.cia.service.api.UserConfiguration)1 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 ServiceResponse (com.hack23.cia.service.api.action.common.ServiceResponse)1 DeviceInfo (com.haulmont.cuba.gui.config.DeviceInfo)1 VaadinRequest (com.vaadin.server.VaadinRequest)1 Notification (com.vaadin.ui.Notification)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Nullable (javax.annotation.Nullable)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1