Package org.apache.clerezza.triaxrs.headerDelegate

Examples of org.apache.clerezza.triaxrs.headerDelegate.LocaleProvider


    assertEquals(mylocale2, null);
  }

  @Test
  public void testLocaleProviderFromString() {
    LocaleProvider lp = new LocaleProvider();
    boolean illegaleArugmentOccured = false;

    assertEquals("en_UK", lp.fromString("en-uk;q = .7").toString());
    assertEquals("us__slang", lp.fromString("us-slang").toString());
    assertEquals("en_UK_cockney", lp.fromString("en-uk-cockney").toString());

    // only 2 letter language tags are allowed
    try {
      lp.fromString("abc-oaeu");
    } catch (IllegalArgumentException e) {
      illegaleArugmentOccured = true;
    }
    assertTrue(illegaleArugmentOccured);

    illegaleArugmentOccured = false;
    // the first sub-tag must not be longer than 8 chars
    try {
      lp.fromString("ab-abcdefghij");
    } catch (IllegalArgumentException e) {
      illegaleArugmentOccured = true;
    }
    assertTrue(illegaleArugmentOccured);

    illegaleArugmentOccured = false;
    // the first sub-tag must not be shorter than 2 chars
    try {
      lp.fromString("ab-a");
    } catch (IllegalArgumentException e) {
      illegaleArugmentOccured = true;
    }
    assertTrue(illegaleArugmentOccured);
  }
View Full Code Here


    assertTrue(illegaleArugmentOccured);
  }

  @Test
  public void testLocaleProviderToString() {
    LocaleProvider lp = new LocaleProvider();
    Locale locale1 = new Locale("en", "uk", "cockney");
    Locale locale2 = new Locale("en", "", "cockney");

    // toLowerCase() because RFC 1766 says:
    // All tags are to be treated as case insensitive
    assertEquals("en-uk-cockney", lp.toString(locale1).toLowerCase());
    assertEquals("en-cockney", lp.toString(locale2).toLowerCase());
  }
View Full Code Here

  @Override
  public List<Locale> getAcceptableLanguages() {
    List<Locale> locales = new ArrayList<Locale>();
    List<String> languages = request.getHeaders().get(HttpHeaders.ACCEPT_LANGUAGE);
    LocaleProvider lp = new LocaleProvider();
   
    if(languages == null) {
      return null;
    }
   
    for (String language : languages) {
      try{
        locales.add(lp.fromString(language));
      } catch (IllegalArgumentException ex) {
        //log and continue
        logger.error("Exception {}", ex);
      }
    }
View Full Code Here

    if (clang == null) {
      return null;
    }
   
    try{
      locale = new LocaleProvider().fromString(clang.get(0));
    } catch (IllegalArgumentException ex) {
      logger.error("Exception {}", ex);
      return null;
    }
   
View Full Code Here

        new ConversionUtil.Convertor<Locale>() {

      @Override
      public Locale convert(String string) {
        try{
          return new LocaleProvider().fromString(string);
        } catch (IllegalArgumentException ex) {
          logger.error("Exception {}", ex);
          return null;
        }
      }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.triaxrs.headerDelegate.LocaleProvider

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.