mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 12:18:01 +08:00
fix code
This commit is contained in:
parent
29c2db6246
commit
31398c727f
@ -1,8 +1,10 @@
|
||||
package cn.hutool.http.useragent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 引擎对象
|
||||
@ -40,4 +42,16 @@ public class Engine extends UserAgentInfo {
|
||||
super(name, regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取引擎版本
|
||||
*
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 版本
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public String getVersion(String userAgentString) {
|
||||
final String regexp = getName() + "[/\\- ]([\\d\\w.\\-]+)";
|
||||
final Pattern pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
|
||||
return ReUtil.getGroup1(pattern, userAgentString);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
package cn.hutool.http.useragent;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* User-Agent解析器
|
||||
*
|
||||
@ -25,16 +22,22 @@ public class UserAgentParser {
|
||||
}
|
||||
final UserAgent userAgent = new UserAgent();
|
||||
|
||||
// 浏览器
|
||||
final Browser browser = parseBrowser(userAgentString);
|
||||
userAgent.setBrowser(parseBrowser(userAgentString));
|
||||
userAgent.setVersion(browser.getVersion(userAgentString));
|
||||
|
||||
// 浏览器引擎
|
||||
final Engine engine = parseEngine(userAgentString);
|
||||
userAgent.setEngine(engine);
|
||||
if (false == engine.isUnknown()) {
|
||||
userAgent.setEngineVersion(parseEngineVersion(engine, userAgentString));
|
||||
userAgent.setEngineVersion(engine.getVersion(userAgentString));
|
||||
}
|
||||
|
||||
// 操作系统
|
||||
userAgent.setOs(parseOS(userAgentString));
|
||||
|
||||
// 平台
|
||||
final Platform platform = parsePlatform(userAgentString);
|
||||
userAgent.setPlatform(platform);
|
||||
userAgent.setMobile(platform.isMobile() || browser.isMobile());
|
||||
@ -73,19 +76,6 @@ public class UserAgentParser {
|
||||
return Engine.Unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析引擎版本
|
||||
*
|
||||
* @param engine 引擎
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 引擎版本
|
||||
*/
|
||||
private static String parseEngineVersion(Engine engine, String userAgentString) {
|
||||
final String regexp = engine.getName() + "[/\\- ]([\\d\\w.\\-]+)";
|
||||
final Pattern pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
|
||||
return ReUtil.getGroup1(pattern, userAgentString);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析系统类型
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user