当前位置: 首页>>代码示例>>Java>>正文


Java UserAgent.parseUserAgentString方法代码示例

本文整理汇总了Java中eu.bitwalker.useragentutils.UserAgent.parseUserAgentString方法的典型用法代码示例。如果您正苦于以下问题:Java UserAgent.parseUserAgentString方法的具体用法?Java UserAgent.parseUserAgentString怎么用?Java UserAgent.parseUserAgentString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eu.bitwalker.useragentutils.UserAgent的用法示例。


在下文中一共展示了UserAgent.parseUserAgentString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleDevice

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
public void handleDevice(HttpServletRequest request,
        HttpServletResponse response) {
    String deviceId = getCookie(request, "SECURITY_DEVICE_ID");

    if (deviceId == null) {
        deviceId = UUID.randomUUID().toString();
        this.addCookie(response, "SECURITY_DEVICE_ID", deviceId,
                3600 * 24 * 365 * 100);
    }

    DeviceDTO deviceDto = deviceConnector.findDevice(deviceId);

    if (deviceDto == null) {
        deviceDto = new DeviceDTO();
        deviceDto.setCode(deviceId);

        UserAgent userAgent = UserAgent.parseUserAgentString(request
                .getHeader("User-Agent"));
        deviceDto.setType(userAgent.getOperatingSystem().getDeviceType()
                .toString());
        deviceDto.setOs(userAgent.getOperatingSystem().toString());
        deviceDto.setClient(userAgent.getBrowser().toString());
    }

    deviceConnector.saveDevice(deviceDto);
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:27,代码来源:RememberLastUsernameAuthenticationSuccessHandler.java

示例2: getUA

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * getUA
 * 
 * @param fdata
 * @param request
 */
private void getUA(StringBuilder fdata, HttpServletRequest request) {

    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));

    String bwrVersion = userAgent.getBrowserVersion().getMajorVersion();
    Browser bwr = userAgent.getBrowser();
    String bwrType = bwr.getBrowserType().getName();
    String bwrName = bwr.getName();
    String bwrEngine = bwr.getRenderingEngine().name();

    fdata.append(bwrName).append(";");
    fdata.append(bwrType).append(";");
    fdata.append(bwrEngine).append(";");
    fdata.append(bwrVersion).append(";");

    OperatingSystem os = userAgent.getOperatingSystem();

    String osName = os.getName();
    String deType = os.getDeviceType().getName();
    fdata.append(osName).append(";");
    fdata.append(deType).append(";");
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:29,代码来源:UEMServiceGFHandler.java

示例3: checkMobileOrPc

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/** 
 * 检测是PC端还是手机端访问,先判断PC端,若系统是 Windows或者Max OSX或者Ubuntu,则返回false,其他的都返回true
 * @param request {@link HttpServletRequest}
 * @return true:移动设备接入,false:pc端接入 
 */  
public static boolean checkMobileOrPc(HttpServletRequest request){    
	String userAgents = request.getHeader("User-Agent").toLowerCase();
	boolean isMobile = true;
	if(userAgents == null){
		return true;
	}
	
	UserAgent userAgent = UserAgent.parseUserAgentString(userAgents); 
	if(userAgent == null){
		return true;
	}
	String systemName = userAgent.getOperatingSystem().getName();
	if(systemName == null){
		return true;
	}
	for(int i=0;i<PC_SYSTEMS.length;i++){
		if(systemName.equals(PC_SYSTEMS[i])){
			return false;
		}
	}
	
    return isMobile;  
}
 
开发者ID:xnx3,项目名称:xnx3,代码行数:29,代码来源:TerminalDetection.java

示例4: apply

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
@Override
public String apply(String value) {
    final UserAgent userAgent = UserAgent.parseUserAgentString(value);
    switch (userAgentComponent) {
    case "browser":
        return String.valueOf(userAgent.getBrowser());
    case "browserVersion":
        return String.valueOf(userAgent.getBrowserVersion());
    case "id":
        return String.valueOf(userAgent.getId());
    case "operatingSystem":
        return String.valueOf(userAgent.getOperatingSystem());
    default:
        return null;
    }
}
 
开发者ID:ogidogi,项目名称:laughing-octo-sansa,代码行数:17,代码来源:SparkParseUAS.java

示例5: setUserAgentVersionAndPlatfom

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * Parses the user agent string using user-agent-utils and retrieve the browser version and the
 * platform details. If the operating system is 'mac' then further parses using Woothie to get the
 * operating system version.
 *
 * @param userAgentString navigator.userAgent
 */
public void setUserAgentVersionAndPlatfom(String userAgentString) {
  UserAgent userAgent = UserAgent.parseUserAgentString(userAgentString);
  Version version = userAgent.getBrowserVersion();
  if (version != null)
    this.userAgentVersion = version.getVersion();
  OperatingSystem operatingSystem = userAgent.getOperatingSystem();
  if (operatingSystem != null)
    this.userAgentPlatform = operatingSystem.getName();
  if (this.userAgentPlatform != null && this.userAgentPlatform.toLowerCase().startsWith("mac")) {
    Map<String, String> map = Classifier.parse(userAgentString);
    this.userAgentPlatform = this.userAgentPlatform + " " + map.get("os_version");
  }
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:21,代码来源:Browser.java

示例6: spiderList

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * 爬虫访问列表,列出最近7天内,最近的100条爬虫记录
 */
@RequestMapping("spiderList")
@ResponseBody
public RequestLogItemListVO spiderList(HttpServletRequest request) throws LogException{
	RequestLogItemListVO vo = new RequestLogItemListVO();
	
	//当前10位时间戳
	int currentTime = DateUtil.timeForUnix10();
	String query = "siteid="+getSiteId();
	String spider = null;
	for (int i = 0; i < spiderNameArray.length; i++) {
		if(spider == null){
			spider = spiderNameArray[i];
		}else{
			spider = spider + " or " + spiderNameArray[i];
		}
	}
	query = query + " and ("+spider+")";
	
	//当月访问量统计
	ArrayList<QueriedLog> jinriQlList = G.aliyunLogUtil.queryList(query, "", DateUtil.getDateZeroTime(currentTime - 604800), currentTime, 0, 100, true);
	
	JSONArray jsonArray = new JSONArray();	//某天访问量,pv
	for (int i = 0; i < jinriQlList.size(); i++) {
		LogItem li = jinriQlList.get(i).GetLogItem();
		JSONObject json = JSONObject.fromObject(li.ToJsonString());
		try {
			json.put("logtimeString", DateUtil.dateFormat(json.getInt("logtime"), "MM-dd HH:mm"));
		} catch (NotReturnValueException e) {
			e.printStackTrace();
		}
		
		UserAgent ua = UserAgent.parseUserAgentString(json.getString("userAgent"));
		json.put("os", ua.getOperatingSystem());
		json.put("browser", ua.getBrowser());
		if(ua.getOperatingSystem().getName().equals("Unknown")){
			String userAgent = json.getString("userAgent");
			//没有发现是哪个浏览器,那可能是爬虫
			for (int j = 0; j < spiderNameArray.length; j++) {
				if(userAgent.indexOf(spiderNameArray[j]) > -1){
					json.put("os", spiderExplainArray[j]);
				}
			}
			
			if(json.get("os") == null){
				if(userAgent.equals("Mozilla")){
					//忽略
				}else{
					System.out.println("未发现的useragent : "+json.toString());
				}
			}
		}
		
		jsonArray.add(json);
		
	}
	vo.setList(jsonArray);
	
	AliyunLog.addActionLog(getSiteId(), "获取最近7天内,最近的100条访问记录");
	
	return vo;
}
 
开发者ID:xnx3,项目名称:wangmarket,代码行数:65,代码来源:RequestLogController.java

示例7: getOSName

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * 获取系统名称
 * @param request 系统名称字符串
 * @return
 */
public static String getOSName(HttpServletRequest request) {
    String userAgentStr = request.getHeader("User-Agent");
    String result = "未知";
    UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr);
    result = userAgent.getOperatingSystem().getName();
    return result;
}
 
开发者ID:qjx378,项目名称:wenku,代码行数:13,代码来源:WebUtil.java

示例8: getBrowserInfo

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * 获取浏览器名称及版本号
 * @param request 浏览器名称及版本号字符串
 * @return
 */
public static String getBrowserInfo(HttpServletRequest request) {
    String userAgentStr = request.getHeader("User-Agent");
    String result = "未知";
    UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr);
    result = removeNumberRegx(userAgent.getBrowser().getName()) + " " + userAgent.getBrowserVersion().getVersion();
    return result;
}
 
开发者ID:qjx378,项目名称:wenku,代码行数:13,代码来源:WebUtil.java

示例9: main

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
public static void main(String[] args) {
    String userAgentString = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:41.0) Gecko/20100101 Firefox/41.0";
    ReadableUserAgent userAgent = getUADetectorExample(userAgentString);
    System.out.println(userAgent);

    UserAgent userAgent2 = UserAgent.parseUserAgentString(userAgentString);
    System.out.println(userAgent2);

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:10,代码来源:DetectDeviceTypeinJavaWebApplicationI.java

示例10: isBrowserSupported

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * Returns true if the browser is supported by dawg-show. Browser compatibility is mainly
 * determined by its ability to show the motion jpeg from the axis video server.
 * @param userAgentString The user agent string that will be parsed
 * @return
 */
public static boolean isBrowserSupported(String userAgentString) {
    UserAgent ua = UserAgent.parseUserAgentString(userAgentString);
    OperatingSystem osGroup = ua.getOperatingSystem().getGroup();
    Browser browser = ua.getBrowser();
    Set<Browser> supportedBrowsers = SUPPORTED.get(osGroup);
    return (supportedBrowsers != null) && supportedBrowsers.contains(browser.getGroup()) && !UNSUPPORTED.contains(browser);
}
 
开发者ID:Comcast,项目名称:dawg,代码行数:14,代码来源:BrowserSupport.java

示例11: getUserAgent

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
/**
 * @return {@link eu.bitwalker.useragentutils.UserAgent}
 */
public static UserAgent getUserAgent () {
	return UserAgent.parseUserAgentString( getUserAgentHeader() );
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:7,代码来源:RequestUtils.java

示例12: resolveUserAgent

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
public UserAgent resolveUserAgent(HttpServletRequest request) {
    String userAgentOrNull = request.getHeader(HttpHeaders.USER_AGENT);

    return UserAgent.parseUserAgentString(userAgentOrNull);
}
 
开发者ID:theborakompanioni,项目名称:tbk-spring-useragentutils,代码行数:6,代码来源:SimpleUserAgentResolver.java

示例13: getUserAgent

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
public static UserAgent getUserAgent(HttpServletRequest request){
	UserAgent userAgent = UserAgent.parseUserAgentString(RequestUtils.getUserAgent(request));
	return userAgent;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:5,代码来源:UserAgentUtils.java

示例14: apply

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
@Override
    public Object apply(String value) {
        final UserAgent userAgent = UserAgent.parseUserAgentString(value);
        switch (userAgentComponent) {
        case UA_BROWSER:
            return userAgent.getBrowser() != null ? String.valueOf(userAgent.getBrowser()) : DFLT_NULL;
        case UA_BROWSER_TYPE:
            return userAgent.getBrowser() != null ? String.valueOf(userAgent.getBrowser().getBrowserType()) : DFLT_NULL;
        case UA_BROWSER_MANUFACTURER:
            return userAgent.getBrowser() != null ? String.valueOf(userAgent.getBrowser().getManufacturer()) : DFLT_NULL;
        case UA_BROWSER_GROUP:
            return userAgent.getBrowser() != null ? String.valueOf(userAgent.getBrowser().getGroup()) : DFLT_NULL;
        case UA_BROWSER_RENDERING_ENGINE:
            return userAgent.getBrowser() != null ? String.valueOf(userAgent.getBrowser().getRenderingEngine()) : DFLT_NULL;
        case UA_BROWSERVERSION:
            //TODO changed in H2O model to String
            if (userAgent.getBrowserVersion() != null) {
                try {
                    return Double.parseDouble(userAgent.getBrowserVersion().toString());
                } catch (IllegalArgumentException e) {
                    return null;
                }
            } else {
                return null;
            }
//            return userAgent.getBrowserVersion() != null ? Double.parseDouble(userAgent.getBrowserVersion().toString()) : DFLT_NULL;
        case UA_BROWSERVERSION_MINOR:
            return userAgent.getBrowserVersion() != null ? Integer.parseInt(userAgent.getBrowserVersion().getMinorVersion()) : DFLT_NULL;
        case UA_BROWSERVERSION_MAJOR:
            return userAgent.getBrowserVersion() != null ? Integer.parseInt(userAgent.getBrowserVersion().getMajorVersion()) : DFLT_NULL;
        case UA_ID:
            return userAgent.getId();
        case UA_OS:
            return userAgent.getOperatingSystem() != null ? String.valueOf(userAgent.getOperatingSystem()) : DFLT_NULL;
        case UA_OS_NAME:
            return userAgent.getOperatingSystem() != null ? String.valueOf(userAgent.getOperatingSystem().getName()) : DFLT_NULL;
        case UA_OS_DEVICE:
            return userAgent.getOperatingSystem() != null ? String.valueOf(userAgent.getOperatingSystem().getDeviceType()) : DFLT_NULL;
        case UA_OS_GROUP:
            return userAgent.getOperatingSystem() != null ? String.valueOf(userAgent.getOperatingSystem().getGroup()) : DFLT_NULL;
        case UA_OS_MANUFACTURER:
            return userAgent.getOperatingSystem() != null ? String.valueOf(userAgent.getOperatingSystem().getManufacturer()) : DFLT_NULL;
        default:
            return null;
        }
    }
 
开发者ID:ogidogi,项目名称:laughing-octo-sansa,代码行数:47,代码来源:ParseUserAgentString.java

示例15: isSupported

import eu.bitwalker.useragentutils.UserAgent; //导入方法依赖的package包/类
protected boolean isSupported(String userAgentHeaderValue)
{
	UserAgent userAgent = UserAgent.parseUserAgentString(userAgentHeaderValue);
	return !UNSUPPORTED_BROWSERS.contains(userAgent.getBrowser());
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:6,代码来源:BrowserDetectionFilter.java


注:本文中的eu.bitwalker.useragentutils.UserAgent.parseUserAgentString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。