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

org.dspace.matomo.factory.MatomoRequestCustomCookiesEnricher Maven / Gradle / Ivy

The newest version!
/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.matomo.factory;

import java.util.Set;

import jakarta.servlet.http.Cookie;
import org.dspace.matomo.model.MatomoRequestDetails;
import org.dspace.usage.UsageEvent;

/**
 * This class extends the {@code MatomoRequestDetailsEnricher} interface and provides a concrete implementation
 * to enrich the {@code MatomoRequestDetails} with custom cookies from the {@code UsageEvent}.
 * 
customCookies; public MatomoRequestCustomCookiesEnricher(String customCookies) { this.customCookies = Set.of(customCookies.split(",")); } /** * Enriches the {@code MatomoRequestDetails} with custom cookies from the {@code UsageEvent}. * * @param usageEvent The {@code UsageEvent} containing the request. * @param matomoRequestDetails The {@code MatomoRequestDetails} to be enriched. * @return The enriched {@code MatomoRequestDetails}. */ @Override public MatomoRequestDetails enrich(UsageEvent usageEvent, MatomoRequestDetails matomoRequestDetails) { Cookie[] cookies = usageEvent.getRequest().getCookies(); if (cookies == null) { return matomoRequestDetails; } for (Cookie cookie : cookies) { String cookieName = cookie.getName(); String baseName = null; if (cookieName != null && cookieName.contains(".")) { baseName = cookieName.substring(0, cookieName.indexOf(".")); } if (baseName != null && customCookies.contains(baseName)) { matomoRequestDetails.addCookie(cookieName, cookie.getValue()); } } return matomoRequestDetails; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy