Java Code Examples for eu.bitwalker.useragentutils.Version

The following examples show how to use eu.bitwalker.useragentutils.Version. 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
Source Project: boubei-tss   Source File: URLUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String parseBrowser(String useragent) {
 	useragent = (useragent + "").toLowerCase();
 	if(useragent.indexOf(browsers[0]) >= 0 && useragent.indexOf(browsers[1]) < 0) { // 微信客户端,注意区分QQ浏览器
 		return QQ_WX;
 	} 
 	
 	String origin = useragent;
 	try {
UserAgent userAgent = UserAgent.parseUserAgentString( useragent );
     	Browser browser = userAgent.getBrowser();
     	OperatingSystem opsys = userAgent.getOperatingSystem(); // 访问设备系统
     	Version browserVersion = userAgent.getBrowserVersion(); // 详细版本
         String version = browserVersion.getMajorVersion();      // 浏览器主版本
         
         origin = browser.getGroup().getName() + version + "-" + opsys;
         
     } catch(Exception e) { }
     	
 	for(String _b : browsers) {
 		if(useragent.indexOf(_b) >= 0) {
 			origin += "," + _b;
 			break;
 		}
 	}
     return origin.toLowerCase();
 }
 
Example 2
Source Project: proctor   Source File: VersionedOS.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Version getVersion(@Nonnull final UserAgent userAgent) {
    String userAgentString = userAgent.getUserAgentString();

    if (userAgent.isIOS()) {
        return parseOsVersion(getIOSVersion(userAgentString));
    }
    else if (userAgent.isAndroid()) {
        return parseOsVersion(getAndroidVersion(userAgentString));
    }
    else if (userAgent.isWindowsPhone()) {
        return parseOsVersion(getWindowsPhoneVersion(userAgentString));
    }

    return UNKNOWN_VERSION;
}
 
Example 3
Source Project: momo-cloud-permission   Source File: UserAgentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取浏览器版本
 *
 * @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 4
Source Project: charging_pile_cloud   Source 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 5
Source Project: plumemo   Source 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 6
/**
 * 保存当前评论时的设备信息
 *
 * @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 7
Source Project: proctor   Source 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 8
Source Project: proctor   Source File: VersionedOS.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static VersionedOS fromUserAgent(@Nonnull final UserAgent agent) {
    final OperatingSystem os = agent.getOperatingSystem();
    final Version version = getVersion(agent);
    final int majorVersion = parseVersionNumberFrom(version.getMajorVersion());
    final int minorVersion = parseVersionNumberFrom(version.getMinorVersion());

    @Nonnull final String fullVersion = Strings.nullToEmpty(version.getVersion());
    return new VersionedOS(os, fullVersion, majorVersion, minorVersion);
}
 
Example 9
Source Project: proctor   Source File: VersionedOS.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Version parseOsVersion(@Nullable final String osVersionString) {
    if (Strings.isNullOrEmpty(osVersionString)) {
        return UNKNOWN_VERSION;
    }

    final Iterator<String> it = Splitter.on('.').split(osVersionString).iterator();
    final String majorVersion = it.next();
    final String minorVersion = it.hasNext() ? it.next() : "";

    return new Version(osVersionString, majorVersion, minorVersion);
}
 
Example 10
Source Project: Spring-Boot-Book   Source File: RequestListener.java    License: Apache License 2.0 4 votes vote down vote up
@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);
    }
 
Example 11
Source Project: bbs   Source File: UserAgentAnalysis.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 解析
 * String ua = request.getHeader("User-Agent");
 * @param ua 请求头字段包含有关发起请求的用户代理的信息
 */
public static AccessInfo analysis(String ua){
	if(ua != null && !"".equals(ua.trim())){
		//转成UserAgent对象
		UserAgent userAgent = UserAgent.parseUserAgentString(ua);
		if(userAgent != null){
			AccessInfo accessInfo = new AccessInfo();
			//获取浏览器信息
			Browser browser = userAgent.getBrowser();
			if(browser != null){
				String browserName = browser.getName();// 浏览器名称
				accessInfo.setBrowserName(browserName);//浏览器名称
				
				if(browser.getGroup() != null){
					String group = browser.getGroup().getName();// 浏览器大类
					accessInfo.setGroup(group);//浏览器大类
				}
			}
			
			
			Version browserVersion = userAgent.getBrowserVersion();// 详细版本
			if(browserVersion != null){
				String version = browserVersion.getMajorVersion();// 浏览器主版本
				accessInfo.setBrowserVersion(browserVersion.getVersion());//详细版本
				accessInfo.setVersion(version);//浏览器主版本
				
			}
			
		//	System.out.println("浏览器名称 "+browserName);
		//	System.out.println("浏览器大类 "+group);
		//	System.out.println("详细版本 "+browserVersion);
		//	System.out.println("浏览器主版本 "+version);
		//	System.out.println("访问设备系统 "+userAgent.getOperatingSystem());// 访问设备系统
			//系统名称
		//	String system = userAgent.getOperatingSystem().getName();
		//	System.out.println("访问设备类型 "+userAgent.getOperatingSystem().getDeviceType());// 访问设备类型
		//	System.out.println("访问设备制造厂商 "+userAgent.getOperatingSystem().getManufacturer());// 访问设备制造厂商
			
			
			if(userAgent.getOperatingSystem() != null){
				accessInfo.setOperatingSystem(userAgent.getOperatingSystem().toString());//访问设备系统
				if(userAgent.getOperatingSystem().getDeviceType() != null && userAgent.getOperatingSystem().getDeviceType().getName() != null){
					if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Computer")){
						accessInfo.setDeviceType("电脑");//访问设备类型
					}else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Mobile")){
						accessInfo.setDeviceType("手机");//访问设备类型
					}else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Tablet")){
						accessInfo.setDeviceType("平板");//访问设备类型
					}else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Game console")){
						accessInfo.setDeviceType("游戏机");//访问设备类型
					}else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Digital media receiver")){
						accessInfo.setDeviceType("数字媒体接收器");//访问设备类型
					}else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Wearable computer")){
						accessInfo.setDeviceType("可穿戴设备");//访问设备类型
					}else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Unknown")){
						accessInfo.setDeviceType("未知设备");//访问设备类型
					}
					
				}
				
				
			}
			
			

			return accessInfo;
		}
		
	}
	
	return null;
}
 
Example 12
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Delegate method
 * Detects the detailed version information of the browser. Depends on the userAgent to be available.
 * Use it only after using UserAgent(String) or UserAgent.parseUserAgent(String).
 * Returns UserAgent.UNKNOWN_VERSION if it can not detect the version information.
 * @return Version
 */
@Nonnull
public Version getBrowserVersion() {
    return MoreObjects.firstNonNull(userAgent.getBrowserVersion(), UserAgentVersion.UNKNOWN_VERSION);
}