Java Code Examples for eu.bitwalker.useragentutils.DeviceType

The following examples show how to use eu.bitwalker.useragentutils.DeviceType. 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: kk-anti-reptile   Source File: UaRule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean doExecute(HttpServletRequest request, HttpServletResponse response) {
    AntiReptileProperties.UaRule uaRule = properties.getUaRule();
    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
    OperatingSystem os = userAgent.getOperatingSystem();
    OperatingSystem osGroup = userAgent.getOperatingSystem().getGroup();
    DeviceType deviceType = userAgent.getOperatingSystem().getDeviceType();
    if (DeviceType.UNKNOWN.equals(deviceType)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Unknown device, User-Agent: " + userAgent.toString());
        return true;
    } else if (OperatingSystem.UNKNOWN.equals(os)
            || OperatingSystem.UNKNOWN_MOBILE.equals(os)
            || OperatingSystem.UNKNOWN_TABLET.equals(os)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Unknown OperatingSystem, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedLinux() && (OperatingSystem.LINUX.equals(osGroup) || OperatingSystem.LINUX.equals(os))) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Linux request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedMobile() && (DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType))) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Mobile Device request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedPc() && DeviceType.COMPUTER.equals(deviceType)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed PC request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedIot() && (DeviceType.DMR.equals(deviceType) || DeviceType.GAME_CONSOLE.equals(deviceType) || DeviceType.WEARABLE.equals(deviceType))) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Iot Device request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedProxy() && OperatingSystem.PROXY.equals(os)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Proxy request, User-Agent: " + userAgent.toString());
        return true;
    }
    return false;
}
 
Example 2
Source Project: onetwo   Source File: UserAgentUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isMobileRequest(){
	return DeviceType.MOBILE.equals(getRequestDeviceType());
}
 
Example 3
Source Project: onetwo   Source File: UserAgentUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isMobileRequest(HttpServletRequest request){
	return DeviceType.MOBILE.equals(getRequestDeviceType(request));
}
 
Example 4
Source Project: onetwo   Source File: UserAgentUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static DeviceType getRequestDeviceType(){
	UserAgent userAgent = getUserAgent();
	return userAgent.getOperatingSystem().getDeviceType();
}
 
Example 5
Source Project: onetwo   Source File: UserAgentUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static DeviceType getRequestDeviceType(HttpServletRequest request){
	UserAgent userAgent = getUserAgent(request);
	return userAgent.getOperatingSystem().getDeviceType();
}
 
Example 6
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public DeviceType getDeviceType() {
    return MoreObjects.firstNonNull(getOperatingSystem().getDeviceType(), DeviceType.UNKNOWN);
}
 
Example 7
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether user agent is a tablet
 * @return true if tablet
 */
public boolean isTablet() {
    return DeviceType.TABLET.equals(getDeviceType()) ||
            userAgentString.contains(NEXUS_7_SIGNATURE) ||
            userAgentString.contains(KINDLE_FIRE_SIGNATURE);
}
 
Example 8
Source Project: frpMgr   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 获取设备类型
 * @param request
 * @return
 */
public static DeviceType getDeviceType(HttpServletRequest request){
	return getUserAgent(request).getOperatingSystem().getDeviceType();
}
 
Example 9
Source Project: frpMgr   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是PC
 * @param request
 * @return
 */
public static boolean isComputer(HttpServletRequest request){
	return DeviceType.COMPUTER.equals(getDeviceType(request));
}
 
Example 10
Source Project: frpMgr   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是手机
 * @param request
 * @return
 */
public static boolean isMobile(HttpServletRequest request){
	return DeviceType.MOBILE.equals(getDeviceType(request));
}
 
Example 11
Source Project: frpMgr   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是平板
 * @param request
 * @return
 */
public static boolean isTablet(HttpServletRequest request){
	return DeviceType.TABLET.equals(getDeviceType(request));
}
 
Example 12
Source Project: frpMgr   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是手机和平板
 * @param request
 * @return
 */
public static boolean isMobileOrTablet(HttpServletRequest request){
	DeviceType deviceType = getDeviceType(request);
	return DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType);
}
 
Example 13
Source Project: Shop-for-JavaWeb   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 获取设备类型
 * @param request
 * @return
 */
public static DeviceType getDeviceType(HttpServletRequest request){
	return getUserAgent(request).getOperatingSystem().getDeviceType();
}
 
Example 14
Source Project: Shop-for-JavaWeb   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是PC
 * @param request
 * @return
 */
public static boolean isComputer(HttpServletRequest request){
	return DeviceType.COMPUTER.equals(getDeviceType(request));
}
 
Example 15
Source Project: Shop-for-JavaWeb   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是手机
 * @param request
 * @return
 */
public static boolean isMobile(HttpServletRequest request){
	return DeviceType.MOBILE.equals(getDeviceType(request));
}
 
Example 16
Source Project: Shop-for-JavaWeb   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是平板
 * @param request
 * @return
 */
public static boolean isTablet(HttpServletRequest request){
	return DeviceType.TABLET.equals(getDeviceType(request));
}
 
Example 17
Source Project: Shop-for-JavaWeb   Source File: UserAgentUtils.java    License: MIT License 2 votes vote down vote up
/**
 * 是否是手机和平板
 * @param request
 * @return
 */
public static boolean isMobileOrTablet(HttpServletRequest request){
	DeviceType deviceType = getDeviceType(request);
	return DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType);
}