Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try and respect the Accept-Language header when returning OAI-PMH #565

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.xml.stream.XMLStreamException;
import java.io.BufferedOutputStream;
import java.util.List;
import java.util.Locale;


/**
Expand All @@ -61,15 +62,14 @@ public class OaiPmhResource extends AbstractResource {
public static final String LIMIT_HEADER_NAME = "X-Limit";



public OaiPmhResource(@Context GraphDatabaseService database) {
super(database);
}

/**
* OAI-PMH 2.0 base URL. See specification for usage.
* <p>
* http://www.openarchives.org/OAI/openarchivesprotocol.html
* <a href="http://www.openarchives.org/OAI/openarchivesprotocol.html">...</a>
*
* @return an OAI-PMH XML payload as a chunked response.
*/
Expand All @@ -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<Locale> 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);
Expand All @@ -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<String> limit = requestHeaders.getRequestHeader(LIMIT_HEADER_NAME);
if (limit == null || limit.size() < 1) {
if (limit == null || limit.isEmpty()) {
return defaultLimit;
} else {
try {
Expand Down
Loading