Java Code Examples for org.osgi.framework.Constants#BUNDLE_LOCALIZATION_DEFAULT_BASENAME

The following examples show how to use org.osgi.framework.Constants#BUNDLE_LOCALIZATION_DEFAULT_BASENAME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Reads all localization entries that affects this bundle (including its
 * host/fragments)
 *
 * @param locale locale == "" the bundle.properties will be read o/w it will
 *          read the files as described in the spec.
 * @param localization_entries will append the new entries to this dictionary
 * @param baseName the basename for localization properties, <code>null</code>
 *          will choose OSGi default
 */
void readLocalization(String locale,
                      Hashtable<String, String> localization_entries,
                      String baseName)
{
  @SuppressWarnings("unchecked")
  final Vector<BundleGeneration> fragments = (Vector<BundleGeneration>)current().fragments.clone();
  if (fragments == null) {
    // NYI! read localization from framework.
    // There is no need for this now since it isn't used.
    return;
  }
  if (baseName == null) {
    baseName = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
  }
  if (!locale.equals("")) {
    locale = "_" + locale;
  }
  while (true) {
    final String l = baseName + locale + ".properties";
    for (int i = fragments.size() - 1; i >= 0; i--) {
      final BundleGeneration bg = fragments.get(i);
      final Hashtable<String, String> tmp = bg.archive.getLocalizationEntries(l);
      if (tmp != null) {
        localization_entries.putAll(tmp);
        return;
      }
    }
    final int pos = locale.lastIndexOf('_');
    if (pos == -1) {
      break;
    }
    locale = locale.substring(0, pos);
  }
}
 
Example 2
Source File: BundleInformationParser.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private void attachLocalization ( final BundleInformation result, final Attributes ma ) throws IOException
{
    String loc = ma.getValue ( Constants.BUNDLE_LOCALIZATION );
    if ( loc == null )
    {
        loc = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
    }
    else
    {
        result.setBundleLocalization ( loc );
    }

    result.setLocalization ( ParserHelper.loadLocalization ( this.file, loc ) );
}
 
Example 3
Source File: BundleGeneration.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Get locale dictionary for this bundle.
 */
private Dictionary<String, String> getLocaleDictionary(String locale, String baseName) {
  final String defaultLocale = Locale.getDefault().toString();

  if (locale == null) {
    locale = defaultLocale;
  } else if (locale.equals("")) {
    return null;
  }
  final Hashtable<String, String> localization_entries = new Hashtable<String, String>();
  // TODO, should we do like this and allow mixed locales?
  if (baseName == null) {
    baseName = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
  }
  final Vector<BundleGeneration> h = getHosts();
  if (h != null) {
    BundleGeneration best;
    while (true) {
      try {
        best = null;
        for (final BundleGeneration bundleGeneration : h) {
          final BundleGeneration bg = bundleGeneration;
          if (best == null || bg.version.compareTo(best.version) > 0) {
            best = bg;
          }
        }
        break;
      } catch (final ConcurrentModificationException ignore) {
      }
    }
    if (best == bundle.fwCtx.systemBundle.current()) {
      bundle.fwCtx.systemBundle.readLocalization("", localization_entries, baseName);
      bundle.fwCtx.systemBundle.readLocalization(defaultLocale, localization_entries,
          baseName);
      if (!locale.equals(defaultLocale)) {
        bundle.fwCtx.systemBundle.readLocalization(locale, localization_entries, baseName);
      }
      return localization_entries;
    } else if (best != null) {
      return best.getLocaleDictionary(locale, baseName);
    }
    // Didn't find a host, fall through.
  }

  readLocalization("", localization_entries, baseName);
  readLocalization(defaultLocale, localization_entries, baseName);
  if (!locale.equals(defaultLocale)) {
    readLocalization(locale, localization_entries, baseName);
  }
  return localization_entries;
}