Search in sources :

Example 1 with CaseInsensitiveDictionaryMap

use of org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap in project rt.equinox.framework by eclipse.

the class StateResolverTest method loadManifest.

private Dictionary loadManifest(String manifest) {
    URL url = getContext().getBundle().getEntry(MANIFEST_ROOT + manifest);
    try {
        CaseInsensitiveDictionaryMap<String, String> headers = new CaseInsensitiveDictionaryMap<String, String>();
        ManifestElement.parseBundleManifest(url.openStream(), headers);
        return headers.asUnmodifiableDictionary();
    } catch (IOException e) {
        fail("Unexpected error loading manifest: " + manifest, e);
    } catch (BundleException e) {
        fail("Unexpected error loading manifest: " + manifest, e);
    }
    return null;
}
Also used : IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) URL(java.net.URL) CaseInsensitiveDictionaryMap(org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)

Example 2 with CaseInsensitiveDictionaryMap

use of org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap in project rt.equinox.framework by eclipse.

the class ManifestLocalization method getHeaders.

Dictionary<String, String> getHeaders(String localeString) {
    if (localeString == null)
        localeString = Locale.getDefault().toString();
    if (localeString.length() == 0)
        return rawHeaders;
    boolean isDefaultLocale = localeString.equals(Locale.getDefault().toString());
    Dictionary<String, String> currentDefault = defaultLocaleHeaders;
    if (isDefaultLocale && currentDefault != null) {
        return currentDefault;
    }
    if (generation.getRevision().getRevisions().getModule().getState().equals(Module.State.UNINSTALLED)) {
        // defaultLocaleHeaders should have been initialized on uninstall
        if (currentDefault != null)
            return currentDefault;
        return rawHeaders;
    }
    ResourceBundle localeProperties = getResourceBundle(localeString, isDefaultLocale);
    CaseInsensitiveDictionaryMap<String, String> localeHeaders = new CaseInsensitiveDictionaryMap<>(this.rawHeaders);
    for (Entry<String, String> entry : localeHeaders.entrySet()) {
        String value = entry.getValue();
        if (value.startsWith("%") && (value.length() > 1)) {
            // $NON-NLS-1$
            String propertiesKey = value.substring(1);
            try {
                value = localeProperties == null ? propertiesKey : (String) localeProperties.getObject(propertiesKey);
            } catch (MissingResourceException ex) {
                value = propertiesKey;
            }
            entry.setValue(value);
        }
    }
    Dictionary<String, String> result = localeHeaders.asUnmodifiableDictionary();
    if (isDefaultLocale) {
        defaultLocaleHeaders = result;
    }
    return result;
}
Also used : MissingResourceException(java.util.MissingResourceException) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) CaseInsensitiveDictionaryMap(org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)

Example 3 with CaseInsensitiveDictionaryMap

use of org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap in project rt.equinox.framework by eclipse.

the class OSGiCapabilityTest method loadManifest.

private Dictionary loadManifest(String manifest) {
    URL url = getContext().getBundle().getEntry(MANIFEST_ROOT + manifest);
    try {
        CaseInsensitiveDictionaryMap<String, String> headers = new CaseInsensitiveDictionaryMap<String, String>();
        ManifestElement.parseBundleManifest(url.openStream(), headers);
        return headers.asUnmodifiableDictionary();
    } catch (IOException e) {
        fail("Unexpected error loading manifest: " + manifest, e);
    } catch (BundleException e) {
        fail("Unexpected error loading manifest: " + manifest, e);
    }
    return null;
}
Also used : IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) URL(java.net.URL) CaseInsensitiveDictionaryMap(org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)

Aggregations

CaseInsensitiveDictionaryMap (org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)3 IOException (java.io.IOException)2 URL (java.net.URL)2 BundleException (org.osgi.framework.BundleException)2 MissingResourceException (java.util.MissingResourceException)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1