Package org.restlet.data

Examples of org.restlet.data.Language


            case TYPE_ENCODING:
                result.setMetadata((T) new Encoding(metadata.toString()));
                break;

            case TYPE_LANGUAGE:
                result.setMetadata((T) new Language(metadata.toString()));
                break;

            case TYPE_MEDIA_TYPE:
                result.setMetadata((T) new MediaType(metadata.toString(),
                        mediaParams));
View Full Code Here


            } else {
                // Get the primary language preferences that are not currently
                // accepted by the client
                List<String> list = new ArrayList<String>();
                for (Preference<Language> preference : languagePrefs) {
                    Language language = preference.getMetadata();
                    if (!language.getSubTags().isEmpty()) {
                        if (!list.contains(language.getPrimaryTag())) {
                            list.add(language.getPrimaryTag());
                            primaryLanguagePrefs
                                    .add(new Preference<Language>(new Language(
                                            language.getPrimaryTag()),
                                            0.005f + (0.001f * preference
                                                    .getQuality())));
                        }
                    }
                }
                // If the default language is a "primary" language but is not
                // present in the list of all primary languages, add it.
                if (defaultLanguage != null
                        && !defaultLanguage.getSubTags().isEmpty()) {
                    if (!list.contains(defaultLanguage.getPrimaryTag())) {
                        primaryLanguagePrefs.add(new Preference<Language>(
                                new Language(defaultLanguage.getPrimaryTag()),
                                0.002f));
                    }
                }

            }

            // Client preferences are altered
            languagePrefs.addAll(primaryLanguagePrefs);
            if (defaultLanguagePref != null) {
                languagePrefs.add(defaultLanguagePref);
                // In this case, if the client adds the "all languages"
                // preference, the latter is removed, in order to support the
                // default preference defined by the server
                List<Preference<Language>> list = new ArrayList<Preference<Language>>();
                for (Preference<Language> preference : languagePrefs) {
                    Language language = preference.getMetadata();
                    if (!language.equals(Language.ALL)) {
                        list.add(preference);
                    }
                }
                languagePrefs = list;
            }
View Full Code Here

    public void testSelectVariant() {
        final ClientInfo clientInfo = new ClientInfo();
        final List<Preference<Language>> accLangs = clientInfo
                .getAcceptedLanguages();
        accLangs.add(new Preference<Language>(Language.SPANISH, 1f));
        accLangs.add(new Preference<Language>(new Language("de"), 0.8f));
        clientInfo.getAcceptedMediaTypes().add(
                new Preference<MediaType>(MediaType.TEXT_HTML, 0.5f));

        Response response = get("selectVariants", clientInfo);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEqualMediaType(MediaType.TEXT_HTML, response.getEntity()
                .getMediaType());
        assertEquals(new Language("de"), TestUtils.getOnlyElement(response
                .getEntity().getLanguages()));
        assertTrue("dimensions must contain " + Dimension.MEDIA_TYPE, response
                .getDimensions().contains(Dimension.MEDIA_TYPE));
        assertTrue("dimensions must contain " + Dimension.LANGUAGE, response
                .getDimensions().contains(Dimension.LANGUAGE));

        clientInfo.getAcceptedMediaTypes().add(
                new Preference<MediaType>(MediaType.TEXT_PLAIN, 1f));
        response = get("selectVariants", clientInfo);
        assertEqualMediaType(MediaType.TEXT_PLAIN, response.getEntity()
                .getMediaType());
        assertEquals(new Language("de"), TestUtils.getOnlyElement(response
                .getEntity().getLanguages()));

        accLangs.add(new Preference<Language>(Language.ENGLISH, 0.9f));
        response = get("selectVariants", clientInfo);
        assertEqualMediaType(MediaType.TEXT_PLAIN, response.getEntity()
View Full Code Here

            case TYPE_ENCODING:
                result.setMetadata((T) new Encoding(metadata.toString()));
                break;

            case TYPE_LANGUAGE:
                result.setMetadata((T) new Language(metadata.toString()));
                break;

            case TYPE_MEDIA_TYPE:
                result.setMetadata((T) new MediaType(metadata.toString(),
                        mediaParams));
View Full Code Here

    private void updateFileExtension(StringBuilder fileName, Metadata metadata) {
        boolean defaultMetadata = true;

        if (getMetadataService() != null) {
            if (metadata instanceof Language) {
                Language language = (Language) metadata;
                defaultMetadata = language.equals(getMetadataService()
                        .getDefaultLanguage());
            } else if (metadata instanceof MediaType) {
                MediaType mediaType = (MediaType) metadata;
                defaultMetadata = mediaType.equals(getMetadataService()
                        .getDefaultMediaType());
View Full Code Here

            }

            if (applyDefault) {
                // If no language is defined, take the default one
                if (variant.getLanguages().isEmpty()) {
                    final Language defaultLanguage = metadataService
                            .getDefaultLanguage();

                    if ((defaultLanguage != null)
                            && !defaultLanguage.equals(Language.ALL)) {
                        variant.getLanguages().add(defaultLanguage);
                    }
                }

                // If no media type is defined, take the default one
View Full Code Here

     *
     * @param locale
     * @return the Restlet Language
     */
    public static Language toLanguage(Locale locale) {
        return new Language(locale.toString());
    }
View Full Code Here

     *
     * @param locale
     * @return the Restlet Language
     */
    public static Language toLanguage(String locale) {
        return new Language(locale);
    }
View Full Code Here

                        "rel")));
                String type = attrs.getValue("", "type");
                if (type != null && type.length() > 0) {
                    this.currentLink.setType(new MediaType(type));
                }
                this.currentLink.setHrefLang(new Language(attrs.getValue("",
                        "hreflang")));
                this.currentLink.setTitle(attrs.getValue("", "title"));
                final String attr = attrs.getValue("", "length");
                this.currentLink.setLength((attr == null) ? -1L : Long
                        .parseLong(attr));
View Full Code Here

                String type = attrs.getValue("", "type");
                if (type != null && type.length() > 0) {
                    this.currentLink.setType(new MediaType(type));
                }

                this.currentLink.setHrefLang(new Language(attrs.getValue("",
                        "hreflang")));
                this.currentLink.setTitle(attrs.getValue("", "title"));
                final String attr = attrs.getValue("", "length");
                this.currentLink.setLength((attr == null) ? -1L : Long
                        .parseLong(attr));
View Full Code Here

TOP

Related Classes of org.restlet.data.Language

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.