Java Code Examples for eu.bitwalker.useragentutils.Version#getVersion()

The following examples show how to use eu.bitwalker.useragentutils.Version#getVersion() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 获取浏览器版本
 *
 * @param request
 * @return
 */
public static String getBrowserVersion(String userAgent) {
    Browser browser = getBrowser(userAgent);
    Version Version = browser.getVersion(userAgent);
    if (null == Version) {
        return "";
    }
    return Version.getVersion();
}
 
Example 2
/**
 * 获取浏览器版本
 *
 * @param request
 * @return
 */
public static String getBrowserVersion(String userAgent) {
    Browser browser = getBrowser(userAgent);
    Version Version = browser.getVersion(userAgent);
    if (null == Version) {
        return "";
    }
    return Version.getVersion();
}
 
Example 3
Source Project: charging_pile_cloud   File: HttpRequestUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 获取系统设备类型信息
 * @param request
 * @return
 */
public  static  String  getSystemDevice(HttpServletRequest request){
    String info = "";
    try{
        Browser browser = UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getBrowser();
        //获取浏览器版本号
        Version version = browser.getVersion(request.getHeader("User-Agent"));
        info = browser.getName() + "/" + version.getVersion();
    }catch (Exception e){
        log.info("获取系统设备信息失败:"+ ExceptionUtils.getStackTrace(e));
    }
    return info;
}
 
Example 4
Source Project: plumemo   File: HttpContextUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取发起请求的浏览器版本号
 */
public static String getBrowserVersion(HttpServletRequest request) {
	try{
		String header = request.getHeader("User-Agent");
		UserAgent userAgent = UserAgent.parseUserAgentString(header);
		Browser browser = userAgent.getBrowser();// 获取浏览器信息
		Version version = browser.getVersion(header);// 获取浏览器版本号
		return version.getVersion();
	}catch (Exception e){
		return "not found version";
	}

}
 
Example 5
/**
 * 保存当前评论时的设备信息
 *
 * @param comment
 */
private void setCurrentDeviceInfo(Comment comment) {
    String ua = RequestUtil.getUa();
    UserAgent agent = UserAgent.parseUserAgentString(ua);
    Browser browser = agent.getBrowser();
    String browserInfo = browser.getName();
    Version version = agent.getBrowserVersion();
    if (version != null) {
        browserInfo += " " + version.getVersion();
    }
    comment.setBrowser(browserInfo);
    OperatingSystem os = agent.getOperatingSystem();
    comment.setOs(os.getName());
    comment.setIp(RequestUtil.getIp());
}
 
Example 6
Source Project: proctor   File: UserAgentVersion.java    License: Apache License 2.0 5 votes vote down vote up
public static UserAgentVersion from(@Nullable final Version version) {
    if (null == version) {
        return UNKNOWN;
    }

    final String majorVersion = version.getMajorVersion();
    final int majorVersionNumber = null == majorVersion ? -1 : UserAgent.getIntegerParameter(majorVersion, -1);

    final String minorVersion = version.getMinorVersion();
    final int minorVersionNumber= null == minorVersion ? -1 : UserAgent.getIntegerParameter(minorVersion, -1);

    return new UserAgentVersion(version.getVersion(), majorVersionNumber, minorVersionNumber);
}
 
Example 7
@Override
    public void requestDestroyed(ServletRequestEvent arg0) {
        System.out.println("监听器初始化...");
        Integer count = null;//请求数量
        Object requestCount = arg0.getServletContext().getAttribute("requestCount");
        if (requestCount == null) {
            count = 0;
        } else {
            count = Integer.valueOf(requestCount.toString());
        }
        count++;
        System.out.println("当前请求数:" + count.toString());
        arg0.getServletContext().setAttribute("requestCount", count);
        /*用户信息*/





        /*用户信息*/
        HttpServletRequest servletRequest = (HttpServletRequest) arg0.getServletRequest();
        //requestURL
        String requestURL = servletRequest.getRequestURL().toString();
        //queryString
        String queryString = servletRequest.getQueryString();

        RequestLog requestLog = new RequestLog();
        requestLog.setIpaddr(IpUtils.getIpAddr(servletRequest));
        requestLog.setSessionId(servletRequest.getRequestedSessionId());
        requestLog.setReferer(servletRequest.getHeader("Referer"));
        requestLog.setAccept(servletRequest.getHeader("accept"));
        requestLog.setMethod(servletRequest.getMethod());
        requestLog.setUrl(requestURL);
        requestLog.setQuerystring(queryString);
        /*UserAgent 工具类*/
        UserAgent userAgent = UserAgent.parseUserAgentString(servletRequest.getHeader("User-Agent"));
        Browser browser = userAgent.getBrowser();
        Version version = browser.getVersion(servletRequest.getHeader("User-Agent"));

        String browserInfo = null;
        try {
            browserInfo = browser.getName() + "/" + version.getVersion();
        } catch (Exception e) {
            e.printStackTrace();
        }

        OperatingSystem os = userAgent.getOperatingSystem();

        /*UserAgent 工具类*/
        requestLog.setOs(os.getName());
        requestLog.setBrowser(browserInfo);
        requestLog.setCreationTimes(System.currentTimeMillis());


/*        SecurityContextImpl securityContextImpl = (SecurityContextImpl) servletRequest.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
        requestLog.setLoginName( securityContextImpl.getAuthentication().getName());*/
        requestLogRepository.save(requestLog);
    }