From ceab87c973f8b0bb77ca911c7c3817c97cfb8e5f Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Thu, 29 Feb 2024 12:08:31 +0000 Subject: [PATCH] Try and respect the Accept-Language header when returning OAI-PMH --- .../main/java/eu/ehri/project/ws/OaiPmhResource.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ehri-ws-oaipmh/src/main/java/eu/ehri/project/ws/OaiPmhResource.java b/ehri-ws-oaipmh/src/main/java/eu/ehri/project/ws/OaiPmhResource.java index ea8184e45..f0eebdb47 100644 --- a/ehri-ws-oaipmh/src/main/java/eu/ehri/project/ws/OaiPmhResource.java +++ b/ehri-ws-oaipmh/src/main/java/eu/ehri/project/ws/OaiPmhResource.java @@ -45,6 +45,7 @@ import javax.xml.stream.XMLStreamException; import java.io.BufferedOutputStream; import java.util.List; +import java.util.Locale; /** @@ -61,7 +62,6 @@ public class OaiPmhResource extends AbstractResource { public static final String LIMIT_HEADER_NAME = "X-Limit"; - public OaiPmhResource(@Context GraphDatabaseService database) { super(database); } @@ -69,7 +69,7 @@ public OaiPmhResource(@Context GraphDatabaseService database) { /** * OAI-PMH 2.0 base URL. See specification for usage. *

- * http://www.openarchives.org/OAI/openarchivesprotocol.html + * ... * * @return an OAI-PMH XML payload as a chunked response. */ @@ -82,10 +82,14 @@ public Response oaiGet() { final BufferedOutputStream bufferedOut = new BufferedOutputStream(out); final IndentingXMLStreamWriter sw = new IndentingXMLStreamWriter( xmlOutputFactory.createXMLStreamWriter(bufferedOut))) { + // Fetch the language or use the default: + List locales = requestHeaders.getAcceptableLanguages(); + Locale locale = locales.isEmpty() ? Locale.ENGLISH : locales.get(0); + String lang = locale.getISO3Language(); Api api = anonymousApi(); OaiPmhExporter oaiPmh = new OaiPmhExporter( OaiPmhData.create(api), - OaiPmhRenderer.defaultRenderer(api, DEFAULT_LANG), + OaiPmhRenderer.defaultRenderer(api, lang), config); try { OaiPmhState state = OaiPmhState.parse(uriInfo.getRequestUri().getQuery(), limit); @@ -112,7 +116,7 @@ private int limit(int defaultLimit) { // Allow overriding the limit via a header. This is safe since // we stream requests. It's also very handy for testing. List limit = requestHeaders.getRequestHeader(LIMIT_HEADER_NAME); - if (limit == null || limit.size() < 1) { + if (limit == null || limit.isEmpty()) { return defaultLimit; } else { try {