java.util.MissingResourceException Java Examples

The following examples show how to use java.util.MissingResourceException. 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 Project: jdk8u60   Author: chenghanpeng   File: CatalogManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtain the static-catalog setting from the properties.
 *
 * <p>In the properties, a value of 'yes', 'true', or '1' is considered
 * true, anything else is false.</p>
 *
 * @return The static-catalog setting from the propertyFile or the
 * defaultUseStaticCatalog.
 */
private boolean queryUseStaticCatalog () {
  String staticCatalog = SecuritySupport.getSystemProperty(pStatic);

  if (staticCatalog == null) {
    if (resources==null) readProperties();
    if (resources==null) return defaultUseStaticCatalog;
    try {
      staticCatalog = resources.getString("static-catalog");
    } catch (MissingResourceException e) {
      return defaultUseStaticCatalog;
    }
  }

  if (staticCatalog == null) {
    return defaultUseStaticCatalog;
  }

  return (staticCatalog.equalsIgnoreCase("true")
          || staticCatalog.equalsIgnoreCase("yes")
          || staticCatalog.equalsIgnoreCase("1"));
}
 
Example #2
Source Project: jdk8u-dev-jdk   Author: frohoff   File: Resources.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initializes all non-final public static fields in the given class with
 * messages from a {@link ResourceBundle}.
 *
 * @param clazz the class containing the fields
 */
public static void initializeMessages(Class<?> clazz, String rbName) {
    ResourceBundle rb = null;
    try {
        rb = ResourceBundle.getBundle(rbName);
    } catch (MissingResourceException mre) {
        // fall through, handled later
    }
    for (Field field : clazz.getFields()) {
        if (isWritableField(field)) {
            String key = field.getName();
            String message = getMessage(rb, key);
            int mnemonicInt = findMnemonicInt(message);
            message = removeMnemonicAmpersand(message);
            message = replaceWithPlatformLineFeed(message);
            setFieldValue(field, message);
            MNEMONIC_LOOKUP.put(message, mnemonicInt);
        }
    }
}
 
Example #3
Source Project: archiva   Author: apache   File: ReleasePolicyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNamesAndDescriptions() throws Exception {

    PreDownloadPolicy policy = lookupPolicy();
    assertEquals("Release Artifact Update Policy", policy.getName());
    assertTrue(policy.getDescription(Locale.US).contains("when a release artifact will be updated"));
    assertEquals("Update always", policy.getOptionName(Locale.US, UpdateOption.ALWAYS));
    assertEquals("Do not download from remote", policy.getOptionName(Locale.US, UpdateOption.NEVER));
    assertEquals("Update, if older than a day", policy.getOptionName(Locale.US, UpdateOption.DAILY));
    assertEquals("Update, if older than a hour", policy.getOptionName(Locale.US, UpdateOption.HOURLY));
    assertEquals("Download only once", policy.getOptionName(Locale.US, UpdateOption.ONCE));
    assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.ALWAYS).contains("each download"));
    assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.NEVER).contains("never from the remote"));
    assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.DAILY).contains("older than one day"));
    assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.HOURLY).contains("older than one hour"));
    assertTrue(policy.getOptionDescription(Locale.US, UpdateOption.ONCE).contains("if it does not exist"));
    try {
        policy.getOptionName(Locale.US, StandardOption.NOOP);
        // Exception should be thrown
        assertTrue(false);
    } catch (MissingResourceException e) {
        //
    }

}
 
Example #4
Source Project: admin-template   Author: adminfaces   File: AdminSystemEventListener.java    License: MIT License 6 votes vote down vote up
public void processEvent(final SystemEvent event) {
    try {
        ResourceBundle adminBundle = ResourceBundle.getBundle("admin");
        ResourceBundle adminPersistenceBundle = null;
        try {
            adminPersistenceBundle = ResourceBundle.getBundle("admin-persistence");
        } catch (MissingResourceException mre) {
            //intentional
        }
        boolean isLegacyTemplate = has(adminBundle.getString("admin.legacy")) && adminBundle.getString("admin.legacy").equals("true");
        StringBuilder sb = new StringBuilder("Using Admin Template ")
                .append(adminBundle.getString("admin.version"))
                .append(isLegacyTemplate ? " (legacy)" : "");
        if (has(adminPersistenceBundle)) {
            sb.append(", Admin Persistence ").append(adminPersistenceBundle.getString("admin-persistence.version"));
        }
        sb.append(" and Admin Theme ").append(ResourceBundle.getBundle("admin-theme").getString("theme.version"));
        log.log(Level.INFO, sb.toString());
    } catch (Exception e) {
        log.log(Level.WARNING, "Could not get AdminFaces version.", e);
    }
}
 
Example #5
Source Project: lams   Author: lamsfoundation   File: Messages.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the localized message for the given message key
 * 
 * @param key
 *            the message key
 * @return The localized message for the key
 */
public static String getString(String key) {
    if (RESOURCE_BUNDLE == null) {
        throw new RuntimeException("Localized messages from resource bundle '" + BUNDLE_NAME + "' not loaded during initialization of driver.");
    }

    try {
        if (key == null) {
            throw new IllegalArgumentException("Message key can not be null");
        }

        String message = RESOURCE_BUNDLE.getString(key);

        if (message == null) {
            message = "Missing error message for key '" + key + "'";
        }

        return message;
    } catch (MissingResourceException e) {
        return '!' + key + '!';
    }
}
 
Example #6
Source Project: openjdk-8-source   Author: keerath   File: Main.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string value of a named resource in the rmic.properties
 * resource bundle.  If the resource is not found, null is returned.
 */
public static String getString(String key) {
    if (!resourcesInitialized) {
        initResources();
    }

    // To enable extensions, search the 'resourcesExt'
    // bundle first, followed by the 'resources' bundle...

    if (resourcesExt != null) {
        try {
            return resourcesExt.getString(key);
        } catch (MissingResourceException e) {}
    }

    try {
        return resources.getString(key);
    } catch (MissingResourceException ignore) {
    }
    return null;
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DatatypeException.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Overrides this method to get the formatted&localized error message.
 *
 * REVISIT: the system locale is used to load the property file.
 *          do we want to allow the appilcation to specify a
 *          different locale?
 */
public String getMessage() {
    ResourceBundle resourceBundle = null;
    resourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages");
    if (resourceBundle == null)
        throw new MissingResourceException("Property file not found!", "com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", key);

    String msg = resourceBundle.getString(key);
    if (msg == null) {
        msg = resourceBundle.getString("BadMessageKey");
        throw new MissingResourceException(msg, "com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", key);
    }

    if (args != null) {
        try {
            msg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            msg = resourceBundle.getString("FormatFailed");
            msg += " " + resourceBundle.getString(key);
        }
    }

    return msg;
}
 
Example #8
Source Project: r-course   Author: joanby   File: Messages.java    License: MIT License 6 votes vote down vote up
/**
 * Returns the localized message for the given message key
 * 
 * @param key
 *            the message key
 * @return The localized message for the key
 */
public static String getString(String key) {
    if (RESOURCE_BUNDLE == null) {
        throw new RuntimeException("Localized messages from resource bundle '" + BUNDLE_NAME + "' not loaded during initialization of driver.");
    }

    try {
        if (key == null) {
            throw new IllegalArgumentException("Message key can not be null");
        }

        String message = RESOURCE_BUNDLE.getString(key);

        if (message == null) {
            message = "Missing error message for key '" + key + "'";
        }

        return message;
    } catch (MissingResourceException e) {
        return '!' + key + '!';
    }
}
 
Example #9
Source Project: openjdk-8   Author: bpupadhyaya   File: CatalogManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtain the preferPublic setting from the properties.
 *
 * <p>In the properties, a value of 'public' is true,
 * anything else is false.</p>
 *
 * @return True if prefer is public or the
 * defaultPreferSetting.
 */
private boolean queryPreferPublic () {
  String prefer = SecuritySupport.getSystemProperty(pPrefer);

  if (prefer == null) {
    if (resources==null) readProperties();
    if (resources==null) return defaultPreferPublic;
    try {
      prefer = resources.getString("prefer");
    } catch (MissingResourceException e) {
      return defaultPreferPublic;
    }
  }

  if (prefer == null) {
    return defaultPreferPublic;
  }

  return (prefer.equalsIgnoreCase("public"));
}
 
Example #10
Source Project: rtg-tools   Author: RealTimeGenomics   File: DiagnosticEvent.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Return an internationalized text message for this diagnostic.  The generated
 * messages are backed by a <code>PropertyResourceBundle</code> with parameters
 * substituted into appropriate points in the message.  See the package level
 * documentation for further information.
 *
 * @return diagnostic message
 */
public String getMessage() {
  final String key = getType().toString();
  try {
    String value = RESOURCE.getString(key);
    //
    //
    //

    // Substitute parameters into value string
    final String[] params = getParams();
    for (int k = 0; k < params.length; ++k) {
      final int position = value.indexOf("%" + (k + 1));
      // In theory should always use all parameters, but just in case someone does
      // write an error message that does not use all the parameters, we make an
      // extra check here.
      if (position != -1) {
        value = value.substring(0, position) + params[k] + value.substring(position + 2);
      }
    }
    return mType.getMessagePrefix() + value;
  } catch (final MissingResourceException e) {
    Diagnostic.userLog("Missing resource information for diagnostic: " + key);
    return mType.getMessagePrefix() + key;
  }
}
 
Example #11
Source Project: j2objc   Author: google   File: ZoneMeta.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected OlsonTimeZone createInstance(String key, String data) {
    OlsonTimeZone tz = null;
    try {
        UResourceBundle top = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME,
                ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
        UResourceBundle res = openOlsonResource(top, data);
        if (res != null) {
            tz = new OlsonTimeZone(top, res, data);
            tz.freeze();
        }
    } catch (MissingResourceException e) {
        // do nothing
    }
    return tz;
}
 
Example #12
Source Project: jdk8u_jdk   Author: JetBrains   File: AccessibleBundle.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void loadResourceBundle(String resourceBundleName,
                                Locale locale) {
    if (! table.contains(locale)) {

        try {
            Hashtable resourceTable = new Hashtable();

            ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName, locale);

            Enumeration iter = bundle.getKeys();
            while(iter.hasMoreElements()) {
                String key = (String)iter.nextElement();
                resourceTable.put(key, bundle.getObject(key));
            }

            table.put(locale, resourceTable);
        }
        catch (MissingResourceException e) {
            System.err.println("loadResourceBundle: " + e);
            // Just return so toDisplayString() returns the
            // non-localized key.
            return;
        }
    }
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: TextToSpeech.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Queries the engine for the set of features it supports for a given locale.
 * Features can either be framework defined, e.g.
 * {@link TextToSpeech.Engine#KEY_FEATURE_NETWORK_SYNTHESIS} or engine specific.
 * Engine specific keys must be prefixed by the name of the engine they
 * are intended for. These keys can be used as parameters to
 * {@link TextToSpeech#speak(String, int, java.util.HashMap)} and
 * {@link TextToSpeech#synthesizeToFile(String, java.util.HashMap, String)}.
 *
 * Features values are strings and their values must meet restrictions described in their
 * documentation.
 *
 * @param locale The locale to query features for.
 * @return Set instance. May return {@code null} on error.
 * @deprecated As of API level 21, please use voices. In order to query features of the voice,
 * call {@link #getVoices()} to retrieve the list of available voices and
 * {@link Voice#getFeatures()} to retrieve the set of features.
 */
@Deprecated
public Set<String> getFeatures(final Locale locale) {
    return runAction(new Action<Set<String>>() {
        @Override
        public Set<String> run(ITextToSpeechService service) throws RemoteException {
            String[] features = null;
            try {
                features = service.getFeaturesForLanguage(
                    locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
            } catch(MissingResourceException e) {
                Log.w(TAG, "Couldn't retrieve 3 letter ISO 639-2/T language and/or ISO 3166 " +
                        "country code for locale: " + locale, e);
                return null;
            }

            if (features != null) {
                final Set<String> featureSet = new HashSet<String>();
                Collections.addAll(featureSet, features);
                return featureSet;
            }
            return null;
        }
    }, null, "getFeatures");
}
 
Example #14
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CatalogManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtain the list of catalog files from the properties.
 *
 * @return A semicolon delimited list of catlog file URIs
 */
private String queryCatalogFiles () {
  String catalogList = SecuritySupport.getSystemProperty(pFiles);
  fromPropertiesFile = false;

  if (catalogList == null) {
    if (resources == null) readProperties();
    if (resources != null) {
      try {
        catalogList = resources.getString("catalogs");
        fromPropertiesFile = true;
      } catch (MissingResourceException e) {
        System.err.println(propertyFile + ": catalogs not found.");
        catalogList = null;
      }
    }
  }

  if (catalogList == null) {
    catalogList = defaultCatalogFiles;
  }

  return catalogList;
}
 
Example #15
Source Project: keystore-explorer   Author: kaikramer   File: DTipOfTheDay.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void readTips(ResourceBundle tips, String tipPrefix) {
	ArrayList<String> tipList = new ArrayList<>();

	// Look for all properties "<tip prefix>x" where x is a sequential 0-index
	try {
		for (int i = 0; ; i++) {
			String tip = tips.getString(tipPrefix + i);
			tipList.add(tip);
		}
	} catch (MissingResourceException ex) {
		// no more tips
	}

	tipsText = tipList.toArray(new String[tipList.size()]);

	if (tipsText.length == 0) {
		throw new IllegalArgumentException(res.getString("NoTipsOfTheDaySupplied.exception.message"));
	}
}
 
Example #16
Source Project: jdk8u60   Author: chenghanpeng   File: LoadItUp2.java    License: GNU General Public License v2.0 6 votes vote down vote up
private boolean lookupBundle(String rbName) {
    // See if Logger.getLogger can find the resource in this directory
    try {
        Logger aLogger = Logger.getLogger("NestedLogger2", rbName);
    } catch (MissingResourceException re) {
        if (DEBUG) {
            System.out.println(
                "As expected, LoadItUp2.lookupBundle() did not find the bundle "
                + rbName);
        }
        return false;
    }
    System.out.println("FAILED: LoadItUp2.lookupBundle() found the bundle "
            + rbName + " using a stack search.");
    return true;
}
 
Example #17
Source Project: uima-uimaj   Author: apache   File: CasEditorPlugin.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the plugin's resource bundle.
 *
 * @return the ResourceBundle or null if missing
 */
public ResourceBundle getResourceBundle() {
  try {
    if (mResourceBundle == null) {
      mResourceBundle = ResourceBundle.getBundle("Annotator.AnnotatorPluginResources");
    }
  } catch (MissingResourceException x) {
    mResourceBundle = null;
  }

  return mResourceBundle;
}
 
Example #18
Source Project: openjdk-8-source   Author: keerath   File: Bug4168625Class.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** return the specified resource or null if not found */
public ResourceBundle getResourceBundle(String resource, Locale locale) {
    try {
        return ResourceBundle.getBundle(resource, locale);
    } catch (MissingResourceException e) {
        return null;
    }
}
 
Example #19
Source Project: jmkvpropedit   Author: BrunoReX   File: Messages.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static String getString(String key) {
	try {
		return RESOURCE_BUNDLE.getString(key);
	} catch (MissingResourceException e) {
		return '!' + key + '!';
	}
}
 
Example #20
Source Project: birt   Author: eclipse   File: Messages.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param key
 * @param lcl
 */
public static String getString( String key, ULocale lcl )
{
	try
	{
		return getResourceBundle( lcl ).getString( key );
	}
	catch ( MissingResourceException e )
	{
		return '!' + key + '!';
	}
}
 
Example #21
Source Project: openjdk-8   Author: bpupadhyaya   File: RegexParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setLocale(Locale locale) {
    try {
        if (locale != null) {
            this.resources = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.xpath.regex.message", locale);
        }
        else {
            this.resources = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.xpath.regex.message");
        }
    }
    catch (MissingResourceException mre) {
        throw new RuntimeException("Installation Problem???  Couldn't load messages: "
                                   + mre.getMessage());
    }
}
 
Example #22
Source Project: openjdk-8-source   Author: keerath   File: ResourceBundleSearchTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean testGetBundleFromSystemClassLoader(String bundleName) {
    // this should succeed if the bundle is on the system classpath.
    try {
        Logger aLogger = Logger.getLogger(ResourceBundleSearchTest.newLoggerName(),
                bundleName);
    } catch (MissingResourceException re) {
        msgs.add("INFO: testGetBundleFromSystemClassLoader() did not find bundle "
                 + bundleName);
        return false;
    }
    msgs.add("INFO: testGetBundleFromSystemClassLoader() found the bundle "
             + bundleName);
    return true;
}
 
Example #23
Source Project: APICloud-Studio   Author: apicloudcom   File: Messages.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String getString(String key)
{
	try
	{
		return RESOURCE_BUNDLE.getString(key);
	}
	catch (MissingResourceException e)
	{
		return '!' + key + '!';
	}
}
 
Example #24
Source Project: neoscada   Author: eclipse   File: ChartModelWizard.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the label for the specified type name.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
protected String getLabel ( final String typeName )
{
    try
    {
        return ChartEditPlugin.INSTANCE
                .getString ( "_UI_" + typeName + "_type" ); //$NON-NLS-1$ //$NON-NLS-2$
    }
    catch ( final MissingResourceException mre )
    {
        ChartEditorPlugin.INSTANCE.log ( mre );
    }
    return typeName;
}
 
Example #25
Source Project: openjdk-8-source   Author: keerath   File: TimeZoneNamesBundle.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a String array containing time zone names. The String array has
 * at most size elements.
 *
 * @param key  the time zone ID for which names are obtained
 * @param size the requested size of array for names
 * @return a String array containing names
 */
public String[] getStringArray(String key, int size) {
    String[] names = handleGetObject(key, size);
    if ((names == null || names.length != size) && parent != null) {
        names = ((TimeZoneNamesBundle)parent).getStringArray(key, size);
    }
    if (names == null) {
        throw new MissingResourceException("no time zone names", getClass().getName(), key);
    }
    return names;

}
 
Example #26
Source Project: tmxeditor8   Author: heartsome   File: Messages.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static String getString(String key) {
	try {
		return BUNDLE.getString(key);
	} catch (MissingResourceException e) {
		return key;
	}
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: ResourceBundleSearchTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean isOnClassPath(String baseName, ClassLoader cl) {
    ResourceBundle rb = null;
    try {
        rb = ResourceBundle.getBundle(baseName, Locale.getDefault(), cl);
        System.out.println("INFO: Found bundle " + baseName + " on " + cl);
    } catch (MissingResourceException e) {
        System.out.println("INFO: Could not find bundle " + baseName + " on " + cl);
        return false;
    }
    return (rb != null);
}
 
Example #28
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Bug4179766Class.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** return the specified resource or null if not found */
public ResourceBundle getResourceBundle(String resource) {
    try {
        return ResourceBundle.getBundle(resource);
    } catch (MissingResourceException e) {
        return null;
    }
}
 
Example #29
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Bug4168625Class.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** return the specified resource or null if not found */
public ResourceBundle getResourceBundle(String resource, Locale locale) {
    try {
        return ResourceBundle.getBundle(resource, locale);
    } catch (MissingResourceException e) {
        return null;
    }
}
 
Example #30
Source Project: jdk8u-jdk   Author: frohoff   File: Logger.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static ResourceBundle findSystemResourceBundle(final Locale locale) {
    // the resource bundle is in a restricted package
    return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
        @Override
        public ResourceBundle run() {
            try {
                return ResourceBundle.getBundle(SYSTEM_LOGGER_RB_NAME,
                                                locale,
                                                ClassLoader.getSystemClassLoader());
            } catch (MissingResourceException e) {
                throw new InternalError(e.toString());
            }
        }
    });
}