Esempio n. 1
0
 private String getJsLocale(Locale locale) {
   String jsLocale = locale.getLanguage();
   if (StringUtils.isNotEmpty(locale.getCountry())) {
     jsLocale += "-" + locale.getCountry();
   }
   return jsLocale;
 }
Esempio n. 2
0
  /**
   * @param locale the predominant language of the targeted {@link
   *     de.catma.document.source.SourceDocument}
   */
  private void setLanguage(Locale locale) {
    String identValue = locale.getLanguage();
    if (!locale.getCountry().isEmpty()) {
      identValue += "-" + locale.getCountry();
    }

    if (language == null) {
      language = new TeiElement(TeiElementName.language);
      nu.xom.Attribute identAttr =
          new nu.xom.Attribute(Attribute.language_ident.getLocalName(), identValue);

      language.addAttribute(identAttr);
      language.appendChild(locale.getDisplayLanguage());

      TeiElement langUsage = new TeiElement(TeiElementName.langUsage);
      langUsage.appendChild(language);

      TeiElement profileDesc = new TeiElement(TeiElementName.profileDesc);
      profileDesc.appendChild(langUsage);
      teiHeaderElement.appendChild(profileDesc);
    } else {
      nu.xom.Attribute identAttr = language.getAttribute(Attribute.language_ident.getLocalName());
      identAttr.setValue(identValue);
      language.removeChildren();
      language.appendChild(locale.getDisplayLanguage());
    }
  }
Esempio n. 3
0
 /**
  * a utility method to answer the name of a resource bundle according to the given base name and
  * locale
  *
  * @param baseName the given base name
  * @param locale the locale to use
  * @return the name of a resource bundle according to the given base name and locale
  */
 public String toBundleName(String baseName, Locale locale) {
   final String emptyString = EMPTY_STRING;
   final String preString = UNDER_SCORE;
   final String underline = UNDER_SCORE;
   if (null == baseName) {
     throw new NullPointerException();
   }
   StringBuilder ret = new StringBuilder();
   StringBuilder prefix = new StringBuilder();
   ret.append(baseName);
   if (!locale.getLanguage().equals(emptyString)) {
     ret.append(underline);
     ret.append(locale.getLanguage());
   } else {
     prefix.append(preString);
   }
   if (!locale.getCountry().equals(emptyString)) {
     ret.append((CharSequence) prefix);
     ret.append(underline);
     ret.append(locale.getCountry());
     prefix = new StringBuilder();
   } else {
     prefix.append(preString);
   }
   if (!locale.getVariant().equals(emptyString)) {
     ret.append((CharSequence) prefix);
     ret.append(underline);
     ret.append(locale.getVariant());
   }
   return ret.toString();
 }
Esempio n. 4
0
 private String compatibleLanguageCode(Locale language) {
   final ArrayList<Locale> compatibleLanguages = new ArrayList<Locale>();
   for (Locale supportedLanguage : supportedLanguages) {
     try {
       if (supportedLanguage.getISO3Language().equals(language.getISO3Language())) {
         compatibleLanguages.add(supportedLanguage);
       }
     } catch (MissingResourceException e) {
     } // No 3-letter language code for locale (as in cmn-Hans-CN), which can be ignored in our
       // case
   }
   if (!compatibleLanguages.isEmpty() && language.getCountry().equals(""))
     return compatibleLanguages.get(0).getLanguage(); // Not a country specific locale
   for (Locale compatibleLanguage : compatibleLanguages) {
     try {
       if (compatibleLanguage.getISO3Country().equals(language.getISO3Country())) {
         return compatibleLanguage.getLanguage()
             + "-"
             + compatibleLanguage.getCountry().toUpperCase();
       }
     } catch (MissingResourceException e) {
     } // No 3-letter country code for locale (as in cmn-Hans-CN), which can be ignored in our case
   }
   return compatibleLanguages.isEmpty() ? null : compatibleLanguages.get(0).getLanguage();
 }
Esempio n. 5
0
  // Compares the specified locale against the supported variants
  private int _compareLocale(Locale locale) {
    // If we don't have any locales specified, anything matches
    if (_locales.isEmpty()) return _LOCALE_UNKNOWN_MATCH;

    // On the other hand, if the client-locale is not specified,
    // but we do have a locale specified, there is no match.
    if (locale == null) return 0;

    int match = 0;

    for (Locale tmpLocale : _locales) {
      if (tmpLocale.getLanguage().equals(locale.getLanguage())) {
        if (tmpLocale.getCountry().equals(locale.getCountry())) {
          match = _LOCALE_EXACT_MATCH;
          break;
        }

        // If we've got a partial match, keep looking - we may could find
        // an exact match
        match = _LOCALE_PARTIAL_MATCH;
      }
    }

    return match;
  }
Esempio n. 6
0
  /**
   * Returns any occurrence of the specified Locale or any its fallback in the value collection, or
   * null if not found. By fallback, we mean will try without variant and country. Example, if
   * locale is zh_TW, it will try zh_TW and then zh.
   */
  public static Locale getByFallback(Collection<Locale> values, Locale locale) {
    if (values.contains(locale)) return locale;

    final String lang = locale.getLanguage();
    final String cnty = locale.getCountry();
    final String var = locale.getVariant();
    if (var != null && var.length() > 0) {
      locale = new Locale(lang, cnty);
      if (values.contains(locale)) return locale;
    }
    if (cnty != null && cnty.length() > 0) {
      locale = new Locale(lang, "");
      if (values.contains(locale)) return locale;
    }

    // search the first one that matches partially
    Locale rtn = null;
    for (Locale l : values) {
      if (l.getLanguage().equals(lang)) {
        // case 1: it matches all but the last element -> done
        if (var == null
            || var.length() == 0
            || Objects.equals(l.getCountry(), cnty)) // country might null
        return l;

        // case 2: it matches only language, we seeek for any case 1
        if (rtn == null) rtn = l;
      }
    }
    return rtn;
  }
Esempio n. 7
0
 public List<String> getExternalsWithResolutionOrder(Permutation permutation) {
   if (permutation == null) {
     return null;
   }
   List<String> result = new ArrayList<String>(4);
   result.add(permutation.toExternal());
   Locale locale = permutation.getLocale();
   if (locale != null) {
     String localeStr = locale.toString();
     if (!result.contains(localeStr)) {
       result.add(localeStr);
     }
     if (locale.getVariant() != null && locale.getVariant().length() != 0) {
       Locale localeWithVar = new Locale(locale.getLanguage(), locale.getCountry());
       localeStr = localeWithVar.toString();
       if (!result.contains(localeStr)) {
         result.add(localeStr);
       }
     }
     if (locale.getCountry() != null && locale.getCountry().length() != 0) {
       Locale localeWithCountry = new Locale(locale.getLanguage());
       localeStr = localeWithCountry.toString();
       if (!result.contains(localeStr)) {
         result.add(localeStr);
       }
     }
   }
   result.add("");
   return result;
 }
  private static Locale _getSuperLocale(Locale locale) {
    String variant = locale.getVariant();

    if (variant.length() > 0) {
      return new Locale(locale.getLanguage(), locale.getCountry());
    }

    String country = locale.getCountry();

    if (country.length() > 0) {
      Locale priorityLocale = LanguageUtil.getLocale(locale.getLanguage());

      if ((priorityLocale != null) && !locale.equals(priorityLocale)) {
        return new Locale(priorityLocale.getLanguage(), priorityLocale.getCountry());
      }

      return LocaleUtil.fromLanguageId(locale.getLanguage(), false, true);
    }

    String language = locale.getLanguage();

    if (language.length() > 0) {
      return _blankLocale;
    }

    return null;
  }
  /** This method must be called in a context synchronized on {@link #translationsStatistics}. */
  private static LanguageEntry getSortedLanguageByLocale(Locale locale) {
    for (LanguageEntry entry : sortedLanguages) {
      if (entry.locale.equals(locale)) {
        return entry;
      }
    }

    // No exact match found, try to match only by language and country
    for (LanguageEntry entry : sortedLanguages) {
      if (entry.locale.getCountry().equals(locale.getCountry())
          && entry.locale.getLanguage().equals(locale.getLanguage())) {
        return entry;
      }
    }

    // No match found on language and country, try to match only by language
    for (LanguageEntry entry : sortedLanguages) {
      if (entry.locale.getLanguage().equals(locale.getLanguage())) {
        return entry;
      }
    }

    // No match found on language, try a last desperate match only by country
    if (!locale.getCountry().isEmpty()) {
      for (LanguageEntry entry : sortedLanguages) {
        if (entry.locale.getCountry().equals(locale.getCountry())) {
          return entry;
        }
      }
    }

    // No match found, return null
    return null;
  }
Esempio n. 10
0
  private InputStream getHelpStream(Class c, String suffix) {
    Locale locale = Stapler.getCurrentRequest().getLocale();
    String base = c.getName().replace('.', '/').replace('$', '/') + "/help" + suffix;

    ClassLoader cl = c.getClassLoader();
    if (cl == null) return null;

    InputStream in;
    in =
        cl.getResourceAsStream(
            base
                + '_'
                + locale.getLanguage()
                + '_'
                + locale.getCountry()
                + '_'
                + locale.getVariant()
                + ".html");
    if (in != null) return in;
    in =
        cl.getResourceAsStream(
            base + '_' + locale.getLanguage() + '_' + locale.getCountry() + ".html");
    if (in != null) return in;
    in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + ".html");
    if (in != null) return in;

    // default
    return cl.getResourceAsStream(base + ".html");
  }
Esempio n. 11
0
  /**
   * Get the appropriate localized version of a file according to language settings e. g. help files
   * in jsp/help/
   *
   * @param locale Locale to get the file for
   * @param fileName String fileName, to get the localized file for
   * @param fileType String file extension
   * @return localizedFileName String - localized filename
   */
  private static String getFilename(Locale locale, String fileName, String fileType) {
    String localizedFileName = null;
    boolean fileFound = false;
    // with Language, Country, Variant
    String fileNameLCV = null;
    // with Language, Country
    String fileNameLC = null;
    // with Language
    String fileNameL = null;
    fileNameL = fileName + "_" + locale.getLanguage();

    if (fileType == null) {
      fileType = "";
    }

    if (!("".equals(locale.getCountry()))) {
      fileNameLC = fileName + "_" + locale.getLanguage() + "_" + locale.getCountry();

      if (!("".equals(locale.getVariant()))) {
        fileNameLCV =
            fileName
                + "_"
                + locale.getLanguage()
                + "_"
                + locale.getCountry()
                + "_"
                + locale.getVariant();
      }
    }

    if (fileNameLCV != null && !fileFound) {
      File fileTmp = new File(fileNameLCV + fileType);
      if (fileTmp.exists()) {
        fileFound = true;
        localizedFileName = fileNameLCV + fileType;
      }
    }

    if (fileNameLC != null && !fileFound) {
      File fileTmp = new File(fileNameLC + fileType);
      if (fileTmp.exists()) {
        fileFound = true;
        localizedFileName = fileNameLC + fileType;
      }
    }

    if (fileNameL != null && !fileFound) {
      File fileTmp = new File(fileNameL + fileType);
      if (fileTmp.exists()) {
        fileFound = true;
        localizedFileName = fileNameL + fileType;
      }
    }
    if (!fileFound) {
      localizedFileName = fileName + fileType;
    }
    return localizedFileName;
  }
  /** Used by Stripes to tell the converter what locale the incoming text is in. */
  public void setLocale(Locale locale) {
    this.locale = locale;
    this.formats = getNumberFormats();

    // Use the appropriate currency symbol if our locale has a country, otherwise try the dollar
    // sign!
    if (locale.getCountry() != null && !"".equals(locale.getCountry()))
      this.currencySymbol = Currency.getInstance(locale).getSymbol(locale);
    else this.currencySymbol = "$";
  }
Esempio n. 13
0
 /**
  * Compatible is a looser matching than that provided by Locale.equals(). Two locales are
  * considered equal if they are equal, or if either does not have a country specified and the
  * languages match.
  *
  * @param lhs left hand side Locale
  * @param rhs right hand side Locale
  * @return true if the two locales are compatible, false otherwise
  * @should confirm different language missing country as compatible
  * @should confirm same language missing country as compatible
  * @should not confirm different country as compatible
  * @should confirm matching country as compatible
  * @should not confirm different language as compatible
  * @should confirm matching language as compatible
  */
 public static boolean areCompatible(Locale lhs, Locale rhs) {
   if (lhs.equals(rhs)) {
     return true;
   } else if ((lhs.getCountry() == "") || (rhs.getCountry() == "")) {
     // no country specified, so language match is good enough
     if (lhs.getLanguage().equals(rhs.getLanguage())) {
       return true;
     }
   }
   return false;
 }
Esempio n. 14
0
 public String toString(final Locale locale) {
   if (locale == null) {
     return null;
   }
   final String variant = locale.getVariant();
   if (StringUtils.isEmpty(variant)) {
     return locale.getLanguage() + "_" + locale.getCountry();
   } else {
     return locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant();
   }
 }
Esempio n. 15
0
  @Test
  public void should_serialize_valid_locale() {
    Locale[] locales = Locale.getAvailableLocales();

    for (Locale locale : locales) {
      String languageTag = LocaleUtil.toLanguageTag(locale);
      assertEquals(
          locale.getLanguage()
              + (StringUtils.isNotBlank(locale.getCountry()) ? ("-" + locale.getCountry()) : ""),
          languageTag);
    }
  }
Esempio n. 16
0
 /**
  * Test for lax Locale equality. More precisely, returns true if (a) both are equal; (b) general
  * only specifies language, and specific has the same language; (c) general specifies language and
  * country, and specific has the same language and country. Else returns false.
  */
 public static boolean subsumes(Locale general, Locale specific) {
   if (general == null || specific == null) return false;
   if (general.equals(specific)) return true;
   else if (general.getVariant().equals("")) {
     if (general.getCountry().equals("")) {
       if (general.getLanguage().equals(specific.getLanguage())) return true;
     } else {
       if (general.getLanguage().equals(specific.getLanguage())
           && general.getCountry().equals(specific.getCountry())) return true;
     }
   }
   return false;
 }
Esempio n. 17
0
 private void fillCombo(final Combobox combo, final Locale curLocale) {
   if (combo.getItemCount() == 0) {
     final Locale currentLocale = UISessionUtils.getCurrentSession().getLocale();
     for (final Locale locale : getPlayerFacade().getAllCountries()) {
       final Comboitem item = new Comboitem(locale.getDisplayCountry(currentLocale));
       item.setValue(locale);
       combo.appendChild(item);
       if (curLocale.getCountry().equals(locale.getCountry())) {
         combo.setSelectedItem(item);
       }
     }
   }
 }
Esempio n. 18
0
  /**
   * this method imitates the orginal <code>ResourceBundle.getBundle(String className,Locale
   * locale)</code> which causes problems when the locale is changed to the base locale (english).
   * For a full description see ResourceBundle.getBundle(String className) in the java-api.
   */
  public ResourceBundle loadResourceBundle(String className, Locale locale)
      throws MissingResourceException {
    String tries[] = new String[7];
    StringBuffer buf = new StringBuffer();
    tries[6] = className;
    buf.append(className);
    if (locale.getLanguage().length() > 0) {
      buf.append('_');
      buf.append(locale.getLanguage());
      tries[2] = buf.toString();
    }
    if (locale.getCountry().length() > 0) {
      buf.append('_');
      buf.append(locale.getCountry());
      tries[1] = buf.toString();
    }
    if (locale.getVariant().length() > 0) {
      buf.append('_');
      buf.append(locale.getVariant());
      tries[0] = buf.toString();
    }
    buf.delete(className.length(), buf.length() - 1);
    Locale defaultLocale = Locale.getDefault();
    if (defaultLocale.getLanguage().length() > 0) {
      buf.append(defaultLocale.getLanguage());
      tries[5] = buf.toString();
    }
    if (defaultLocale.getCountry().length() > 0) {
      buf.append('_');
      buf.append(defaultLocale.getCountry());
      tries[4] = buf.toString();
    }
    if (defaultLocale.getVariant().length() > 0) {
      buf.append('_');
      buf.append(defaultLocale.getVariant());
      tries[3] = buf.toString();
    }

    ResourceBundle bundle = null;
    for (int i = 0; i < tries.length; i++) {
      if (tries[i] == null) continue;
      bundle = loadBundle(tries[i]);
      if (bundle != null) {
        loadParent(tries, i, bundle);
        return bundle;
      }
    }
    throw new MissingResourceException(
        "'" + className + "' not found. The resource-file is missing.", className, "");
  }
  /*
   * Gets the resource bundle with the given base name and preferred locale.
   *
   * This method calls java.util.ResourceBundle.getBundle(), but ignores
   * its return value unless its locale represents an exact or language match
   * with the given preferred locale.
   *
   * @param basename the resource bundle base name
   * @param pref the preferred locale
   *
   * @return the requested resource bundle, or <tt>null</tt> if no resource
   * bundle with the given base name exists or if there is no exact- or
   * language-match between the preferred locale and the locale of
   * the bundle returned by java.util.ResourceBundle.getBundle().
   */
  private static ResourceBundle findMatch(String basename, Locale pref) {
    ResourceBundle match = null;

    try {
      ResourceBundle bundle =
          ResourceBundle.getBundle(basename, pref, Thread.currentThread().getContextClassLoader());
      Locale avail = bundle.getLocale();
      if (pref.equals(avail)) {
        // Exact match
        match = bundle;
      } else {
        /*
         * We have to make sure that the match we got is for
         * the specified locale. The way ResourceBundle.getBundle()
         * works, if a match is not found with (1) the specified locale,
         * it tries to match with (2) the current default locale as
         * returned by Locale.getDefault() or (3) the root resource
         * bundle (basename).
         * We must ignore any match that could have worked with (2) or (3).
         * So if an exact match is not found, we make the following extra
         * tests:
         *     - avail locale must be equal to preferred locale
         *     - avail country must be empty or equal to preferred country
         *       (the equality match might have failed on the variant)
         */
        if (pref.getLanguage().equals(avail.getLanguage())
            && ("".equals(avail.getCountry()) || pref.getCountry().equals(avail.getCountry()))) {
          /*
           * Language match.
           * By making sure the available locale does not have a
           * country and matches the preferred locale's language, we
           * rule out "matches" based on the container's default
           * locale. For example, if the preferred locale is
           * "en-US", the container's default locale is "en-UK", and
           * there is a resource bundle (with the requested base
           * name) available for "en-UK", ResourceBundle.getBundle()
           * will return it, but even though its language matches
           * that of the preferred locale, we must ignore it,
           * because matches based on the container's default locale
           * are not portable across different containers with
           * different default locales.
           */
          match = bundle;
        }
      }
    } catch (MissingResourceException mre) {
    }

    return match;
  }
 @Test
 public void testListAllCountries() {
   for (final Locale aLocale :
       CollectionHelper.getSorted(
           Locale.getAvailableLocales(), new CollatingComparatorLocaleCountry(Locale.US)))
     if (aLocale.getCountry().length() > 0)
       s_aLogger.info(
           aLocale.getCountry()
               + " "
               + aLocale.getDisplayCountry()
               + " ("
               + aLocale.toString()
               + ")");
 }
  private static String localeToLanguageTag(Locale locale) {
    /*
     * This might seem redundant, but a language can also contain a
     * country/region and a variant. Stating that e.g language
     * "ar" should return "ar" means that "messages_ar.properties"
     * will be used for any country/region and variant of Arabic.
     * This should be true until UMS contains multiple dialects of Arabic,
     * in which case different codes would have to be returned for the
     * different dialects.
     */

    if (locale == null) {
      return null;
    }
    String languageTag = locale.getLanguage();
    if (languageTag != null && !languageTag.isEmpty()) {
      switch (languageTag) {
        case "en":
          if (locale.getCountry().equalsIgnoreCase("GB")) {
            return "en-GB";
          } else {
            return "en-US";
          }
        case "pt":
          if (locale.getCountry().equalsIgnoreCase("BR")) {
            return "pt-BR";
          } else {
            return "pt";
          }
        case "nb":
        case "nn":
          return "no";
        case "cmn":
        case "zh":
          if (locale.getScript().equalsIgnoreCase("Hans")) {
            return "zh-Hans";
          } else if (locale.getCountry().equalsIgnoreCase("CN")
              || locale.getCountry().equalsIgnoreCase("SG")) {
            return "zh-Hans";
          } else {
            return "zh-Hant";
          }
        default:
          return languageTag;
      }
    } else {
      return null;
    }
  }
Esempio n. 22
0
 public static String zza(Locale locale) {
   if (locale == null) {
     return null;
   }
   Object language = locale.getLanguage();
   if (TextUtils.isEmpty(language)) {
     return null;
   }
   StringBuilder stringBuilder = new StringBuilder();
   stringBuilder.append(language.toLowerCase());
   if (!TextUtils.isEmpty(locale.getCountry())) {
     stringBuilder.append("-").append(locale.getCountry().toLowerCase());
   }
   return stringBuilder.toString();
 }
Esempio n. 23
0
 @Override
 public List<String> defaultLanguageCodes() {
   final TreeSet<String> set = new TreeSet<String>();
   set.add(Locale.getDefault().getLanguage());
   final TelephonyManager manager =
       (TelephonyManager) myApplication.getSystemService(Context.TELEPHONY_SERVICE);
   if (manager != null) {
     final String country0 = manager.getSimCountryIso().toLowerCase();
     final String country1 = manager.getNetworkCountryIso().toLowerCase();
     for (Locale locale : Locale.getAvailableLocales()) {
       final String country = locale.getCountry().toLowerCase();
       if (country != null
           && country.length() > 0
           && (country.equals(country0) || country.equals(country1))) {
         set.add(locale.getLanguage());
       }
     }
     if ("ru".equals(country0) || "ru".equals(country1)) {
       set.add("ru");
     } else if ("by".equals(country0) || "by".equals(country1)) {
       set.add("ru");
     } else if ("ua".equals(country0) || "ua".equals(country1)) {
       set.add("ru");
     }
   }
   set.add("multi");
   return new ArrayList<String>(set);
 }
Esempio n. 24
0
  public static void LoadApplication(Context context, String runtimeDataDir, String[] apks) {
    synchronized (lock) {
      if (!initialized) {
        System.loadLibrary("monodroid");
        Locale locale = Locale.getDefault();
        String language = locale.getLanguage() + "-" + locale.getCountry();
        String filesDir = context.getFilesDir().getAbsolutePath();
        String cacheDir = context.getCacheDir().getAbsolutePath();
        String dataDir = context.getApplicationInfo().dataDir + "/lib";
        ClassLoader loader = context.getClassLoader();

        Runtime.init(
            language,
            apks,
            runtimeDataDir,
            new String[] {
              filesDir, cacheDir, dataDir,
            },
            loader,
            new java.io.File(
                    android.os.Environment.getExternalStorageDirectory(),
                    "Android/data/" + context.getPackageName() + "/files/.__override__")
                .getAbsolutePath(),
            MonoPackageManager_Resources.Assemblies);
        initialized = true;
      }
    }
  }
Esempio n. 25
0
  public static List<KeyValue> getCountries() {
    String[] isoCountryCodes = Locale.getISOCountries();
    List<KeyValue> countries = new ArrayList<>();
    for (String countryCode : isoCountryCodes) {
      Locale locale = new Locale("", countryCode);
      String countryName = locale.getDisplayCountry();
      String regionCode = locale.getCountry();
      countries.add(new KeyValue(regionCode, countryName));
    }

    //        Locale[] locales = Locale.getAvailableLocales();
    //        for (Locale locale : locales)
    //        {
    //            String code = locale.getCountry();
    //            String country = locale.getDisplayCountry();
    //            if (code.trim().length() > 0 && !code.contains(code) && country.trim().length() >
    // 0 && !countries.contains(country))
    //            {
    //                countries.add(new KeyValue(code, country));
    //            }
    //        }

    Collections.sort(countries, new KeyValueComparator());
    countries.add(0, new KeyValue("", "Any"));
    return countries;
  }
Esempio n. 26
0
  /**
   * Sets -javaagent and JRE arguments as SUN environment variable.
   *
   * @param parameters The parameters for starting the AUT
   * @return the _JAVA_OPTIONS environment variable including -javaagent and jre arguments
   */
  protected String setJavaOptions(Map parameters) {
    StringBuffer sb = new StringBuffer();
    if (isRunningFromExecutable(parameters)) {
      Locale locale = (Locale) parameters.get(IStartAut.LOCALE);
      // set agent and locals

      sb.append(JAVA_OPTIONS_INTRO);
      if (org.eclipse.jubula.tools.utils.MonitoringUtil.shouldAndCanRunWithMonitoring(parameters)) {
        String monAgent = getMonitoringAgent(parameters);
        if (monAgent != null) {
          sb.append(monAgent).append(StringConstants.SPACE);
        }
      }
      sb.append(StringConstants.QUOTE)
          .append("-javaagent:") // $NON-NLS-1$
          .append(getAbsoluteAgentJarPath())
          .append(StringConstants.QUOTE);

      if (locale != null) {
        sb.append(StringConstants.SPACE).append(JAVA_COUNTRY_PROPERTY).append(locale.getCountry());
        sb.append(StringConstants.SPACE)
            .append(JAVA_LANGUAGE_PROPERTY)
            .append(locale.getLanguage());
      }
    } else {
      if (org.eclipse.jubula.tools.utils.MonitoringUtil.shouldAndCanRunWithMonitoring(parameters)) {
        String monAgent = getMonitoringAgent(parameters);
        if (monAgent != null) {
          sb.append(JAVA_OPTIONS_INTRO).append(monAgent);
        }
      }
    }

    return sb.toString();
  }
Esempio n. 27
0
 protected PlayDfeApiContext(
     Context context,
     AndroidAuthenticator authenticator,
     Cache cache,
     String appPackageName,
     String appVersionString,
     int apiVersion,
     Locale locale,
     String mccmnc,
     String clientId,
     String loggingId) {
   this.mHeaders = new HashMap();
   this.mContext = context;
   this.mAuthenticator = authenticator;
   this.mCache = cache;
   this.mHeaders.put(
       "X-DFE-Device-Id", Long.toHexString(((Long) PlayG.androidId.get()).longValue()));
   this.mHeaders.put("Accept-Language", locale.getLanguage() + "-" + locale.getCountry());
   if (!TextUtils.isEmpty(mccmnc)) {
     this.mHeaders.put("X-DFE-MCCMNC", mccmnc);
   }
   if (!TextUtils.isEmpty(clientId)) {
     this.mHeaders.put("X-DFE-Client-Id", clientId);
   }
   if (!TextUtils.isEmpty(clientId)) {
     this.mHeaders.put("X-DFE-Logging-Id", loggingId);
   }
   this.mHeaders.put(
       "User-Agent", makeUserAgentString(appPackageName, appVersionString, apiVersion));
   checkUrlRules();
 }
  @Override
  public void prepareModule() throws Exception {
    Context ctx =
        (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    ReferenceService rservice =
        (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    Locale locale = getLocale();

    String country = locale.getCountry();
    if (locale.getVariant().equals("EUR")) {
      country = "X1";
    }

    Map packages = ShippingUtil.buildPackageMap(moduleid, locale);
    if (packages != null) {
      setPackageMap(packages);
    }

    // get merchant configs
    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);

    ConfigurationResponse config = mservice.getConfigurationByModule(moduleid, merchantid);
    this.setConfigurations(config);
  }
Esempio n. 29
0
 private void assertLocale(String code, String language, String country, String variant) {
   Locale locale = Language.getLocale(code);
   assertEquals(code.replaceAll("-", "_"), locale.toString());
   assertEquals(language, locale.getLanguage());
   assertEquals(country, locale.getCountry());
   assertEquals(variant, locale.getVariant());
 }
Esempio n. 30
0
 /**
  * Obtains the list of locales to search through when performing a locale search.
  *
  * <pre>
  * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en"))
  *   = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"]
  * </pre>
  *
  * <p>The result list begins with the most specific locale, then the next more general and so on,
  * finishing with the default locale. The list will never contain the same locale twice.
  *
  * @param locale the locale to start from, null returns empty list
  * @param defaultLocale the default locale to use if no other is found
  * @return the unmodifiable list of Locale objects, 0 being locale, not null
  */
 public static List<Locale> localeLookupList(final Locale locale, final Locale defaultLocale) {
   final List<Locale> list = new ArrayList<Locale>(4);
   if (locale != null) {
     list.add(locale);
     if (locale.getVariant().length() > 0) {
       list.add(new Locale(locale.getLanguage(), locale.getCountry()));
     }
     if (locale.getCountry().length() > 0) {
       list.add(new Locale(locale.getLanguage(), ""));
     }
     if (list.contains(defaultLocale) == false) {
       list.add(defaultLocale);
     }
   }
   return Collections.unmodifiableList(list);
 }