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 File: CatalogManager.java    From openjdk-jdk8u with 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 #2
Source File: LoadItUp2.java    From jdk8u60 with 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 #3
Source File: ReleasePolicyTest.java    From archiva with 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 File: Resources.java    From jdk8u-dev-jdk with 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 #5
Source File: DTipOfTheDay.java    From keystore-explorer with 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 #6
Source File: CatalogManager.java    From jdk8u60 with 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 #7
Source File: AdminSystemEventListener.java    From admin-template with 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 #8
Source File: Messages.java    From lams with 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 #9
Source File: Main.java    From openjdk-8-source with 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 #10
Source File: DatatypeException.java    From openjdk-jdk8u with 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 #11
Source File: Messages.java    From r-course with 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 #12
Source File: CatalogManager.java    From openjdk-8 with 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 #13
Source File: DiagnosticEvent.java    From rtg-tools with 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 #14
Source File: TextToSpeech.java    From android_9.0.0_r45 with 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 #15
Source File: AccessibleBundle.java    From jdk8u_jdk with 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 #16
Source File: ZoneMeta.java    From j2objc with 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 #17
Source File: Messages.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public static String getString(String key, String parm1, String parm2,
        String parm3) {
    try {
        return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
                new Object[] { parm1, parm2, parm3 });
    } catch (MissingResourceException e) {
        return '!' + key + '!';
    }
}
 
Example #18
Source File: Messages.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public static String getString(String key, String parm1, String parm2) {
    try {
        return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
                new Object[] { parm1, parm2 });
    } catch (MissingResourceException e) {
        return '!' + key + '!';
    }
}
 
Example #19
Source File: ArabicShapingRegTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void reportTestFailure(int index, TestData test, ArabicShaping shaper, String result, Exception error) {
    if (error != null && error instanceof MissingResourceException ) {
        warnln(error.getMessage());
    }

    StringBuffer buf = new StringBuffer();
    buf.append("*** test failure ***\n");
    buf.append("index: " + index + "\n");
    buf.append("test: " + test + "\n");
    buf.append("shaper: " + shaper + "\n");
    buf.append("result: " + escapedString(result) + "\n");
    buf.append("error: " + error + "\n");

    if (result != null && test.result != null && !test.result.equals(result)) {
        for (int i = 0; i < Math.max(test.result.length(), result.length()); ++i) {
            String temp = Integer.toString(i);
            if (temp.length() < 2) {
                temp = " ".concat(temp);
            }
            char trg = i < test.result.length() ? test.result.charAt(i) : '\uffff';
            char res = i < result.length() ? result.charAt(i) : '\uffff';

            buf.append("[" + temp + "] ");
            buf.append(escapedString("" + trg) + " ");
            buf.append(escapedString("" + res) + " ");
            if (trg != res) {
                buf.append("***");
            }
            buf.append("\n");
        }
    }
    err(buf.toString());
}
 
Example #20
Source File: WFileDialogPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String run() {
    try {
        ResourceBundle rb = ResourceBundle.getBundle("sun.awt.windows.awtLocalization");
        return rb.getString("allFiles");
    } catch (MissingResourceException e) {
        return "All Files";
    }
}
 
Example #21
Source File: Resources.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the message corresponding to the key in the bundle or a text
 * describing it's missing.
 *
 * @param rb the resource bundle
 * @param key the key
 *
 * @return the message
 */
private static String getMessage(ResourceBundle rb, String key) {
    if (rb == null) {
        return "missing resource bundle";
    }
    try {
        return rb.getString(key);
    } catch (MissingResourceException mre) {
        return "missing message for key = \"" + key
                + "\" in resource bundle ";
    }
}
 
Example #22
Source File: LocaleTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @bug 4147315
 * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
 * Should throw an exception for unknown locales
 */
public void Test4147315() {
    // Try with codes that are the wrong length but happen to match text
    // at a valid offset in the mapping table
    Locale locale = new Locale("aaa", "CCC");

    try {
        String result = locale.getISO3Country();

        errln("ERROR: getISO3Country() returns: " + result +
            " for locale '" + locale + "' rather than exception" );
    } catch(MissingResourceException e) { }
}
 
Example #23
Source File: Messages.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the string.
 * @param key
 *            the key
 * @return the string
 */
public static String getString(String key) {
	try {
		return RESOURCE_BUNDLE.getString(key);
	} catch (MissingResourceException e) {
		return '!' + key + '!';
	}
}
 
Example #24
Source File: HebrewTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * With no fields set, the calendar should use default values.
 */
@Test
public void TestDefaultFieldValues() {
    try{
        HebrewCalendar cal = new HebrewCalendar();
        cal.clear();
        logln("cal.clear() -> " + cal.getTime());
    }catch(MissingResourceException ex){
        warnln("could not load the locale data");
    }
}
 
Example #25
Source File: Messages.java    From uncode-dal-all with GNU General Public License v2.0 5 votes vote down vote up
public static String getString(String key, String parm1) {
    try {
        return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
                new Object[] { parm1 });
    } catch (MissingResourceException e) {
        return '!' + key + '!';
    }
}
 
Example #26
Source File: Messages.java    From tmxeditor8 with 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 File: Messages.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
public static String getString(String key, Object... params) {
  try {
    return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params);
  } catch (MissingResourceException ex) {
    return '!' + key + '!';
  }
}
 
Example #28
Source File: UIDefaults.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example #29
Source File: HintsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String getFileObjectLocalizedName( FileObject fo ) {
    Object o = fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
    if ( o instanceof String ) {
        String bundleName = (String)o;
        try {
            ResourceBundle rb = NbBundle.getBundle(bundleName);            
            String localizedName = rb.getString(fo.getPath());                
            return localizedName;
        }
        catch(MissingResourceException ex ) {
            // Do nothing return file path;
        }
    }
    return fo.getPath();
}
 
Example #30
Source File: Localizer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private String getString(String key) {
    try {
        return getBundle().getString(key);
    } catch( MissingResourceException e ) {
        // delegation
        if(parent!=null)
            return parent.getString(key);
        else
            throw e;
    }
}