All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.livk.context.useragent.yauaa.YauaaUserAgentConverter Maven / Gradle / Ivy

There is a newer version: 1.3.4
Show newest version
/*
 * Copyright 2021-2024 spring-boot-extension the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.livk.context.useragent.yauaa;

import com.livk.context.useragent.support.AbstractUserAgentConverter;
import lombok.RequiredArgsConstructor;
import nl.basjes.parse.useragent.UserAgent;
import nl.basjes.parse.useragent.UserAgentAnalyzer;
import org.springframework.http.HttpHeaders;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author livk
 */
@RequiredArgsConstructor
public class YauaaUserAgentConverter extends AbstractUserAgentConverter {

	private final UserAgentAnalyzer userAgentAnalyzer;

	@Override
	protected UserAgent create(HttpHeaders headers) {
		Map headersConcat = headers.entrySet()
			.stream()
			.collect(Collectors.toMap(Map.Entry::getKey, entry -> String.join(",", entry.getValue())));
		return userAgentAnalyzer.parse(headersConcat);
	}

	@Override
	protected String browser(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.AGENT_NAME);
	}

	@Override
	protected String browserType(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.AGENT_CLASS);
	}

	@Override
	protected String browserVersion(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.AGENT_VERSION);
	}

	@Override
	protected String os(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.OPERATING_SYSTEM_NAME);
	}

	@Override
	protected String osVersion(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.OPERATING_SYSTEM_NAME_VERSION);
	}

	@Override
	protected String deviceType(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.DEVICE_CLASS);
	}

	@Override
	protected String deviceName(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.DEVICE_NAME);
	}

	@Override
	protected String deviceBrand(UserAgent userAgent) {
		return userAgent.getValue(UserAgent.DEVICE_BRAND);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy