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


Java UserAgent类代码示例

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


UserAgent类属于eu.bitwalker.useragentutils包,在下文中一共展示了UserAgent类的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: popuplateDevice

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
@Override
public boolean popuplateDevice( DeviceWebDriver webDriver, String deviceId, Device device, String xFID )
{
    String uAgent = (String) webDriver.executeScript("return navigator.userAgent;");
    UserAgent userAgent = new UserAgent( uAgent );
    device.setBrowserName( userAgent.getBrowser().getName() );
    device.setManufacturer( userAgent.getOperatingSystem().getManufacturer().getName() );
    String[] osSplit = userAgent.getOperatingSystem().getName().split( " " );
    device.setOs( osSplit[ 0 ].toUpperCase() );
    if ( osSplit.length > 1 )
        device.setOsVersion( userAgent.getOperatingSystem().getName().split( " " )[ 1 ].toUpperCase() );
    
    Dimension winDim = webDriver.manage().window().getSize();
    if ( winDim != null )
        device.setResolution( winDim.getWidth() + " x " + winDim.height );
    else
        device.setResolution( null );
    
    return true;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:21,代码来源:SELENIUMCloudActionProvider.java

示例4: 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

示例5: supportsWallet

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
public boolean supportsWallet(String userAgentHeaderValue) {
    if (StringUtils.isBlank(userAgentHeaderValue)) {
        return false;
    }
    UserAgent userAgent = new UserAgent(userAgentHeaderValue);
    if (userAgent.getOperatingSystem().getDeviceType() == DeviceType.MOBILE
            && userAgent.getOperatingSystem().getGroup() == OperatingSystem.IOS
            && userAgent.getOperatingSystem().getId() >= OperatingSystem.iOS6_IPHONE.getId()) {
        return true;
    }
    Version oldestSafariVersionWithGuaranteedSupport = new Version("6.2", "6", "2"); // Mac OS X 10.8.2 or later required to install this Safari version
    if (userAgent.getOperatingSystem() == OperatingSystem.MAC_OS_X
            && userAgent.getBrowser().getGroup() == Browser.SAFARI
            && userAgent.getBrowserVersion().compareTo(oldestSafariVersionWithGuaranteedSupport) >= 0) {
        return true;
    }
    return false;
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:19,代码来源:WalletSupportService.java

示例6: readPersistentLogins

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
@ExtDirectMethod(STORE_READ)
@Transactional(readOnly = true)
public List<PersistentLogin> readPersistentLogins(
		@AuthenticationPrincipal JpaUserDetails jpaUserDetails) {
	List<PersistentLogin> persistentLogins = this.jpaQueryFactory
			.selectFrom(QPersistentLogin.persistentLogin)
			.where(QPersistentLogin.persistentLogin.user.id
					.eq(jpaUserDetails.getUserDbId()))
			.fetch();

	persistentLogins.forEach(p -> {
		String ua = p.getUserAgent();
		if (StringUtils.hasText(ua)) {
			UserAgent userAgent = UserAgent.parseUserAgentString(ua);
			p.setUserAgentName(userAgent.getBrowser().getGroup().getName());
			p.setUserAgentVersion(userAgent.getBrowserVersion().getMajorVersion());
			p.setOperatingSystem(userAgent.getOperatingSystem().getName());
		}
	});

	return persistentLogins;
}
 
开发者ID:ralscha,项目名称:eds-starter6-jpa,代码行数:23,代码来源:UserConfigService.java

示例7: readPersistentLogins

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
@ExtDirectMethod(STORE_READ)
public List<PersistentLogin> readPersistentLogins(
		@AuthenticationPrincipal MongoUserDetails userDetails) {

	return StreamSupport
			.stream(this.mongoDb.getCollection(PersistentLogin.class)
					.find(Filters.eq(CPersistentLogin.userId,
							userDetails.getUserDbId()))
					.spliterator(), false)
			.peek(p -> {
				String ua = p.getUserAgent();
				if (StringUtils.hasText(ua)) {
					UserAgent userAgent = UserAgent.parseUserAgentString(ua);
					p.setUserAgentName(userAgent.getBrowser().getGroup().getName());
					p.setUserAgentVersion(
							userAgent.getBrowserVersion().getMajorVersion());
					p.setOperatingSystem(userAgent.getOperatingSystem().getName());
				}
			}).collect(Collectors.toList());

}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:22,代码来源:UserConfigService.java

示例8: getPredictionBean

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
public static PredictionBean getPredictionBean(Fingerprint fp) throws Exception{
	PredictionBean predictionBean = new PredictionBean();
	UserAgent ua = new UserAgent(fp.getUser_agent());
	
	BrowserOsGuessFingerprintNumericRepresentation fnr = new BrowserOsGuessFingerprintNumericRepresentation(
			fp.getAllHeaders(), fp.getFontsJS_CSS(), 
			fp.getSuperCookieLocalStorage(), fp.getSuperCookieSessionStorage(), fp.getSuperCookieUserData(),
			fp.getHstsEnabled(), fp.getIndexedDBEnabled(), fp.getMathTan(), fp.isUsingTor(), fp.getTbbVersion(),
			fp.getTouchPoints(), fp.getTouchEvent(), fp.getTouchStart());
	double fingerprintArray[];
	{
		double fingerprintArrayRaw[] = fnr.getFingerprintArray();
		fingerprintArray = new double[fingerprintArrayRaw.length + 1];
		fingerprintArray[0] = 0;
		for(int i = 0; i < fingerprintArrayRaw.length; ++i){
			fingerprintArray[i + 1] = fingerprintArrayRaw[i];
		}
	}
	
	predictionBean.setUseragentSpecifiedBrowser(ua.getBrowser().getGroup().toString());
	predictionBean.setBrowserPrediction(browserClassify(fingerprintArray));
	predictionBean.setUseragentSpecifiedOs(ua.getOperatingSystem().getGroup().toString());
	predictionBean.setOsPrediction(osClassify(fingerprintArray));
	
	return predictionBean;
}
 
开发者ID:qqTYXn7,项目名称:browserprint,代码行数:27,代码来源:Predictor.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: isMobileOrUnknownDevice

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
private boolean isMobileOrUnknownDevice(String userAgentHeaderValue) {
    if (StringUtils.isBlank(userAgentHeaderValue)) {
        return false;
    }
    UserAgent userAgent = new UserAgent(userAgentHeaderValue);
    return userAgent.getOperatingSystem().getDeviceType() == DeviceType.MOBILE;
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:8,代码来源:ConfirmationController.java

示例15: preHandle

import eu.bitwalker.useragentutils.UserAgent; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    UserAgent userAgent = this.userAgentResolver.resolveUserAgent(request);
    request.setAttribute(UserAgentUtils.CURRENT_USERAGENT_ATTRIBUTE, userAgent);

    return true;
}
 
开发者ID:theborakompanioni,项目名称:tbk-spring-useragentutils,代码行数:8,代码来源:UserAgentResolverHandlerInterceptor.java


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