Example usage for com.google.common.net HttpHeaders ACCEPT_LANGUAGE

List of usage examples for com.google.common.net HttpHeaders ACCEPT_LANGUAGE

Introduction

In this page you can find the example usage for com.google.common.net HttpHeaders ACCEPT_LANGUAGE.

Prototype

String ACCEPT_LANGUAGE

To view the source code for com.google.common.net HttpHeaders ACCEPT_LANGUAGE.

Click Source Link

Document

The HTTP Accept-Language header field name.

Usage

From source file:com.arcbees.website.server.LocaleExtractor.java

/**
 * Returns the locale from Accept-Language with the higher priority. Disregards country information and not
 * supported locales. ie: <code>Accept-Language: da, en-gb;q=0.8, FR-CA;q=0.7</code> will return "en".
 *//* w  ww  . j av a 2  s  .com*/
private String getLocaleFromHeader() {
    String header = request.getHeader(HttpHeaders.ACCEPT_LANGUAGE);

    if (header != null) {
        String[] headerParts = header.split(",");
        List<LocalePreference> localePreferences = FluentIterable.of(headerParts)
                .transform(new Function<String, LocalePreference>() {
                    @Override
                    public LocalePreference apply(String locale) {
                        return new LocalePreference(locale);
                    }
                }).filter(new Predicate<LocalePreference>() {
                    @Override
                    public boolean apply(LocalePreference preference) {
                        return SUPPORTED_LOCALES.contains(preference.getLocale());
                    }
                }).toSortedList(LocalePreference.COMPARATOR);

        return localePreferences.isEmpty() ? null : localePreferences.get(0).getLocale();
    }

    return null;
}

From source file:com.arcbees.beestore.server.servlets.LocaleExtractor.java

/**
 * Returns the locale from Accept-Language with the higher priority. Disregards country information and not
 * supported locales. ie: <code>Accept-Language: da, en-gb;q=0.8, FR-CA;q=0.7</code> will return "en".
 *//*from w  w  w . j a  va  2  s.c  o  m*/
private String getLocaleFromHeader() {
    String header = request.getHeader(HttpHeaders.ACCEPT_LANGUAGE);

    if (header != null) {
        String[] headerParts = header.split(",");
        List<LocalePreference> localePreferences = FluentIterable.of(headerParts)
                .transform(new Function<String, LocalePreference>() {
                    @Override
                    public LocalePreference apply(String locale) {
                        return new LocalePreference(locale);
                    }
                }).filter(new Predicate<LocalePreference>() {
                    @Override
                    public boolean apply(LocalePreference preference) {
                        return SUPPORTED_LOCALES.contains(preference);
                    }
                }).toSortedList(LocalePreference.COMPARATOR);

        return localePreferences.isEmpty() ? null : localePreferences.get(0).getLocale();
    }

    return null;
}

From source file:com.b2international.snowowl.snomed.api.rest.SnomedConceptRestService.java

@ApiOperation(value = "Retrieve Concepts from a branch", notes = "Returns a list with all/filtered Concepts from a branch."
        + "<p>The following properties can be expanded:" + "<p>"
        + "&bull; pt() &ndash; the description representing the concept's preferred term in the given locale<br>"
        + "&bull; fsn() &ndash; the description representing the concept's fully specified name in the given locale<br>"
        + "&bull; descriptions() &ndash; the list of descriptions for the concept<br>")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = PageableCollectionResource.class),
        @ApiResponse(code = 400, message = "Invalid filter config", response = RestApiError.class),
        @ApiResponse(code = 404, message = "Branch not found", response = RestApiError.class) })
@RequestMapping(value = "/{path:**}/concepts", method = RequestMethod.GET, produces = {
        AbstractRestService.SO_MEDIA_TYPE, AbstractRestService.TEXT_CSV_MEDIA_TYPE })
public @ResponseBody DeferredResult<SnomedConcepts> search(
        @ApiParam(value = "The branch path") @PathVariable(value = "path") final String branch,

        @ApiParam(value = "The concept status to match") @RequestParam(value = "active", required = false) final Boolean activeFilter,

        @ApiParam(value = "The concept module identifier to match") @RequestParam(value = "module", required = false) final String moduleFilter,

        @ApiParam(value = "The namespace to match") @RequestParam(value = "namespace", required = false) final String namespaceFilter,

        @ApiParam(value = "The effective time to match (yyyyMMdd, exact matches only)") @RequestParam(value = "effectiveTime", required = false) final String effectiveTimeFilter,

        @ApiParam(value = "The definition status to match") @RequestParam(value = "definitionStatus", required = false) final String definitionStatusFilter,

        @ApiParam(value = "The description term to match") @RequestParam(value = "term", required = false) final String termFilter,

        @ApiParam(value = "The description active state to match") @RequestParam(value = "termActive", required = false) final Boolean descriptionActiveFilter,

        @ApiParam(value = "The ECL expression to match in the inferred tree") @RequestParam(value = "ecl", required = false) final String eclFilter,

        @ApiParam(value = "The ECL expression to match in the stated tree") @RequestParam(value = "statedEcl", required = false) final String statedEclFilter,

        @ApiParam(value = "A set of concept identifiers") @RequestParam(value = "conceptIds", required = false) final Set<String> conceptIds,

        @ApiParam(value = "The scrollKeepAlive to start a scroll using this query") @RequestParam(value = "scrollKeepAlive", required = false) final String scrollKeepAlive,

        @ApiParam(value = "A scrollId to continue scrolling a previous query") @RequestParam(value = "scrollId", required = false) final String scrollId,

        @ApiParam(value = "The search key to use for retrieving the next page of results") @RequestParam(value = "searchAfter", required = false) final String searchAfter,

        @ApiParam(value = "The maximum number of items to return") @RequestParam(value = "limit", defaultValue = "50", required = false) final int limit,

        @ApiParam(value = "Expansion parameters") @RequestParam(value = "expand", required = false) final String expand,

        @ApiParam(value = "Accepted language tags, in order of preference") @RequestHeader(value = HttpHeaders.ACCEPT_LANGUAGE, defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage,

        @ApiIgnore @RequestHeader(value = HttpHeaders.ACCEPT, required = false) final String contentType) {

    return doSearch(branch, activeFilter, moduleFilter, namespaceFilter, effectiveTimeFilter,
            definitionStatusFilter, termFilter, descriptionActiveFilter, eclFilter, statedEclFilter, conceptIds,
            scrollKeepAlive, scrollId, searchAfter, limit, expand, acceptLanguage, contentType);
}

From source file:com.b2international.snowowl.snomed.api.rest.SnomedConceptRestService.java

@ApiOperation(value = "Alternate search endpoint. Retrieve Concepts from a branch", notes = "This is an alternative to the standard {path}/concepts search endpoint.<br/>"
        + "Returns a list with all/filtered Concepts from a branch."
        + "<p>The following properties can be expanded:" + "<p>"
        + "&bull; pt() &ndash; the description representing the concept's preferred term in the given locale<br>"
        + "&bull; fsn() &ndash; the description representing the concept's fully specified name in the given locale<br>"
        + "&bull; descriptions() &ndash; the list of descriptions for the concept<br>")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = PageableCollectionResource.class),
        @ApiResponse(code = 400, message = "Invalid filter config", response = RestApiError.class),
        @ApiResponse(code = 404, message = "Branch not found", response = RestApiError.class) })
@RequestMapping(value = "/{path:**}/concepts/search", method = RequestMethod.POST, produces = {
        AbstractRestService.SO_MEDIA_TYPE, AbstractRestService.TEXT_CSV_MEDIA_TYPE })
public @ResponseBody DeferredResult<SnomedConcepts> searchViaPost(

        @ApiParam(value = "The branch path") @PathVariable(value = "path") final String branch,

        @RequestBody final SnomedConceptRestSearch body,

        @ApiParam(value = "Accepted language tags, in order of preference") @RequestHeader(value = HttpHeaders.ACCEPT_LANGUAGE, defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage,

        @ApiIgnore @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = AbstractRestService.SO_MEDIA_TYPE, required = false) final String contentType) {

    return doSearch(branch, body.getActiveFilter(), body.getModuleFilter(), body.getNamespaceFilter(),
            body.getEffectiveTimeFilter(), body.getDefinitionStatusFilter(), body.getTermFilter(),
            body.getDescriptionActiveFilter(), body.getEclFilter(), body.getStatedEclFilter(),
            body.getConceptIds(), body.getScrollKeepAlive(), body.getScrollId(), body.getSearchAfter(),
            body.getLimit(), body.getExpand(), acceptLanguage, contentType);
}

From source file:com.b2international.snowowl.snomed.api.rest.SnomedConceptRestService.java

@ApiOperation(value = "Retrieve Concept properties", notes = "Returns all properties of the specified Concept, including a summary of inactivation indicator and association members."
        + "<p>The following properties can be expanded:" + "<p>"
        + "&bull; pt() &ndash; the description representing the concept's preferred term in the given locale<br>"
        + "&bull; fsn() &ndash; the description representing the concept's fully specified name in the given locale<br>"
        + "&bull; descriptions() &ndash; the list of descriptions for the concept<br>"
        + "&bull; ancestors(limit:50,direct:true,expand(pt(),...)) &ndash; the list of concept ancestors (parameter 'direct' is required)<br>"
        + "&bull; descendants(limit:50,direct:true,expand(pt(),...)) &ndash; the list of concept descendants (parameter 'direct' is required)<br>")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = Void.class),
        @ApiResponse(code = 404, message = "Branch or Concept not found", response = RestApiError.class) })
@RequestMapping(value = "/{path:**}/concepts/{conceptId}", method = RequestMethod.GET)
public @ResponseBody DeferredResult<SnomedConcept> read(
        @ApiParam(value = "The branch path") @PathVariable(value = "path") final String branchPath,

        @ApiParam(value = "The Concept identifier") @PathVariable(value = "conceptId") final String conceptId,

        @ApiParam(value = "Expansion parameters") @RequestParam(value = "expand", required = false) final String expand,

        @ApiParam(value = "Accepted language tags, in order of preference") @RequestHeader(value = HttpHeaders.ACCEPT_LANGUAGE, defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage) {

    final List<ExtendedLocale> extendedLocales;

    try {//from w ww  .  ja  va 2s. c om
        extendedLocales = AcceptHeader.parseExtendedLocales(new StringReader(acceptLanguage));
    } catch (IOException e) {
        throw new BadRequestException(e.getMessage());
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e.getMessage());
    }

    return DeferredResults.wrap(SnomedRequests.prepareGetConcept(conceptId).setExpand(expand)
            .setLocales(extendedLocales).build(repositoryId, branchPath).execute(bus));
}

From source file:com.b2international.snowowl.snomed.api.rest.SnomedConceptRestService.java

@ApiOperation(value = "Retrieve authoring form of a concept", notes = "Retrieve authoring form of a concept which includes proximal primitive super-types and all inferred relationships "
        + "which are not of type 'Is a'.")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = Void.class),
        @ApiResponse(code = 404, message = "Branch or Concept not found", response = RestApiError.class) })
@RequestMapping(value = "/{path:**}/concepts/{conceptId}/authoring-form", method = RequestMethod.GET)
public @ResponseBody ISnomedExpression readShortNormalForm(
        @ApiParam(value = "The branch path") @PathVariable(value = "path") final String branchPath,

        @ApiParam(value = "The Concept identifier") @PathVariable(value = "conceptId") final String conceptId,

        @ApiParam(value = "Accepted language tags, in order of preference") @RequestHeader(value = HttpHeaders.ACCEPT_LANGUAGE, defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage) {

    final List<ExtendedLocale> extendedLocales;

    try {/*from   ww  w  .jav a  2  s. c o m*/
        extendedLocales = AcceptHeader.parseExtendedLocales(new StringReader(acceptLanguage));
    } catch (IOException e) {
        throw new BadRequestException(e.getMessage());
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e.getMessage());
    }

    return expressionService.getConceptAuthoringForm(conceptId, branchPath, extendedLocales);
}