io.github.mngsk.devicedetector.client.browser.BrowserParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of device-detector Show documentation
Show all versions of device-detector Show documentation
The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models.
package io.github.mngsk.devicedetector.client.browser;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.github.mngsk.devicedetector.client.AbstractClientParser;
import io.github.mngsk.devicedetector.client.Client;
public class BrowserParser extends AbstractClientParser {
private List engines;
private Map> families;
public BrowserParser() {
this(new ObjectMapper(new YAMLFactory()));
}
public BrowserParser(ObjectMapper objectMapper) {
super("browser", "regexes/client/browsers.yml", objectMapper);
String fixtureFile;
InputStream inputStream;
CollectionType listType;
fixtureFile = "regexes/client/browser_engine.yml";
inputStream = this.getClass().getClassLoader()
.getResourceAsStream(fixtureFile);
listType = objectMapper.getTypeFactory()
.constructCollectionType(List.class, EngineRegex.class);
try {
this.engines = objectMapper.readValue(inputStream, listType);
} catch (IOException e) {
throw new RuntimeException("Could not load " + fixtureFile, e);
}
fixtureFile = "regexes/client/browser_family.yml";
inputStream = this.getClass().getClassLoader()
.getResourceAsStream(fixtureFile);
TypeReference