Package org.restlet.data

Examples of org.restlet.data.Language


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

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


    protected Variant getVariant( Request request,
                                  List<Language> possibleLanguages,
                                  List<MediaType> possibleMediaTypes
    )
    {
        Language language = request.getClientInfo().getPreferredLanguage( possibleLanguages );

        if( language == null )
        {
            language = possibleLanguages.get( 0 );
        }
View Full Code Here

        if( preferenceList.isEmpty() )
        {
            return Locale.getDefault();
        }

        Language language = preferenceList
            .get( 0 ).getMetadata();
        String[] localeStr = language.getName().split( "-" );

        Locale locale;
        switch( localeStr.length )
        {
        case 1:
View Full Code Here

                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_CONTENT_LANGUAGE)) {
                    HeaderReader hr = new HeaderReader(header.getValue());
                    String value = hr.readValue();
                    while (value != null) {
                        result.getLanguages().add(new Language(value));
                        value = hr.readValue();
                    }
                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_LAST_MODIFIED)) {
                    result.setModificationDate(parseDate(header.getValue(),
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

      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 if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_CONTENT_LANGUAGE)) {
                    HeaderReader hr = new HeaderReader(header.getValue());
                    String value = hr.readValue();
                    while (value != null) {
                        result.getLanguages().add(new Language(value));
                        value = hr.readValue();
                    }
                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_LAST_MODIFIED)) {
                    result.setModificationDate(parseDate(header.getValue(),
View Full Code Here

            } else if (header.getName().equalsIgnoreCase(
                    HttpConstants.HEADER_CONTENT_LANGUAGE)) {
                final HeaderReader hr = new HeaderReader(header.getValue());
                String value = hr.readValue();
                while (value != null) {
                    result.getLanguages().add(new Language(value));
                    value = hr.readValue();
                }
                entityHeaderFound = true;
            } else if (header.getName().equalsIgnoreCase(
                    HttpConstants.HEADER_LAST_MODIFIED)) {
View Full Code Here

        } else {
            // Get the primary language preferences that are not currently
            // accepted by the client
            final List<String> list = new ArrayList<String>();
            for (final Preference<Language> preference : languagePrefs) {
                final 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
            final List<Preference<Language>> list = new ArrayList<Preference<Language>>();
            for (final Preference<Language> preference : languagePrefs) {
                final Language language = preference.getMetadata();
                if (!language.equals(Language.ALL)) {
                    list.add(preference);
                }
            }
            languagePrefs = list;
        }
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

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.