Exemplo n.º 1
0
  /**
   * Constructor.
   *
   * @param clientInfo
   * @param metadataService
   */
  public Conneg(ClientInfo clientInfo, MetadataService metadataService) {
    this.clientInfo = clientInfo;
    this.metadataService = metadataService;

    if (clientInfo != null) {
      // Get the enriched user preferences
      this.languagePrefs =
          getEnrichedPreferences(
              clientInfo.getAcceptedLanguages(),
              (metadataService == null) ? null : metadataService.getDefaultLanguage(),
              Language.ALL);
      this.mediaTypePrefs =
          getEnrichedPreferences(
              clientInfo.getAcceptedMediaTypes(),
              (metadataService == null) ? null : metadataService.getDefaultMediaType(),
              MediaType.ALL);
      this.characterSetPrefs =
          getEnrichedPreferences(
              clientInfo.getAcceptedCharacterSets(),
              (metadataService == null) ? null : metadataService.getDefaultCharacterSet(),
              CharacterSet.ALL);
      this.encodingPrefs =
          getEnrichedPreferences(
              clientInfo.getAcceptedEncodings(),
              (metadataService == null) ? null : metadataService.getDefaultEncoding(),
              Encoding.ALL);
    }
  }
Exemplo n.º 2
0
  /**
   * Creates a {@link ClientInfo} instance with preferences matching exactly the current variant.
   *
   * @return The new {@link ClientInfo} instance.
   */
  public ClientInfo createClientInfo() {
    ClientInfo result = new ClientInfo();

    if (getCharacterSet() != null) {
      result.getAcceptedCharacterSets().add(new Preference<CharacterSet>(getCharacterSet()));
    }

    if (getEncodings() != null) {
      for (Encoding encoding : getEncodings()) {
        result.getAcceptedEncodings().add(new Preference<Encoding>(encoding));
      }
    }

    if (getLanguages() != null) {
      for (Language language : getLanguages()) {
        result.getAcceptedLanguages().add(new Preference<Language>(language));
      }
    }

    if (getMediaType() != null) {
      result.getAcceptedMediaTypes().add(new Preference<MediaType>(getMediaType()));
    }

    return result;
  }