Java Code Examples for java.util.MissingResourceException

The following are top voted examples for showing how to use java.util.MissingResourceException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: sstore-soft   File: RefCapablePropertyResourceBundle.java   Source Code and License 6 votes vote down vote up
/**
 * Return a ref to a new or existing RefCapablePropertyResourceBundle,
 * or throw a MissingResourceException.
 */
static private RefCapablePropertyResourceBundle getRef(String baseName,
        ResourceBundle rb, ClassLoader loader) {
    if (!(rb instanceof PropertyResourceBundle))
        throw new MissingResourceException(
                "Found a Resource Bundle, but it is a "
                        + rb.getClass().getName(),
                PropertyResourceBundle.class.getName(), null);
    if (allBundles.containsKey(rb))
        return (RefCapablePropertyResourceBundle) allBundles.get(rb);
    RefCapablePropertyResourceBundle newPRAFP =
            new RefCapablePropertyResourceBundle(baseName,
                    (PropertyResourceBundle) rb, loader);
    allBundles.put(rb, newPRAFP);
    return newPRAFP;
}
 
Example 2
Project: openjdk-jdk10   File: IIOMetadataFormatImpl.java   Source Code and License 6 votes vote down vote up
private String getResource(String key, Locale locale) {
    if (locale == null) {
        locale = Locale.getDefault();
    }

    /**
     * Per the class documentation, resource bundles, including localized ones
     * are intended to be delivered by the subclasser - ie supplier of the
     * metadataformat. For the standard format and all standard plugins that
     * is the JDK. For 3rd party plugins that they will supply their own.
     * This includes plugins bundled with applets/applications.
     * In all cases this means it is sufficient to search for those resource
     * in the module that is providing the MetadataFormatImpl subclass.
     */
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(resourceBaseName, locale,
                                                        this.getClass().getModule());
        return bundle.getString(key);
    } catch (MissingResourceException e) {
        return null;
    }
}
 
Example 3
Project: AWGW   File: WorldFrame.java   Source Code and License 6 votes vote down vote up
private void configureMenuItem(JMenuItem item, String resource, ActionListener listener) {
    configureAbstractButton(item, resource);
    item.addActionListener(listener);
    try {
        String accel = resources.getString(resource + ".accel");
        String metaPrefix = "@";
        if (accel.startsWith(metaPrefix)) {
            int menuMask = getToolkit().getMenuShortcutKeyMask();
            KeyStroke key = KeyStroke.getKeyStroke(
                    KeyStroke.getKeyStroke(accel.substring(metaPrefix.length())).getKeyCode(), menuMask);
            item.setAccelerator(key);
        } else {
            item.setAccelerator(KeyStroke.getKeyStroke(accel));
        }
    } catch (MissingResourceException ex) {
        // no accelerator
    }
}
 
Example 4
Project: swing-desktop-starter   File: I18N.java   Source Code and License 6 votes vote down vote up
/**
 * Method to create the ResourceBundle object if not exists.
 *
 * @return The ResourceBundle object if not exist.
 */
public static ResourceBundle getInstance()
{
    if (messages == null)
    {
        log.debug("Internationalization settings...");
        try
        {
            // user default Locale :
            locale = Locale.getDefault();

            log.info("Default user Locale : " + locale.getLanguage() + "_" + locale.getCountry());

            messages = ResourceBundle.getBundle("messages", locale);
        } catch (MissingResourceException e)
        {
            log.error("Cannot configure Locale, missing resources file => " + e);
            System.exit(0);
        }
    }

    return messages;
}
 
Example 5
Project: openjdk-jdk10   File: AppletResourceTest.java   Source Code and License 6 votes vote down vote up
public void init() {
    DummyImageReaderImpl reader;
    MyReadWarningListener listener = new MyReadWarningListener();
    Locale[] locales = {new Locale("ru"),
                        new Locale("fr"),
                        new Locale("uk")};

    reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());
    reader.setAvailableLocales(locales);
    reader.setLocale(new Locale("fr"));
    reader.addIIOReadWarningListener(listener);

    String baseName = "AppletResourceTest$BugStats";
    try {
        reader.processWarningOccurred("WarningMessage");
        reader.processWarningOccurred(baseName, "water");
    } catch (MissingResourceException mre) {
        throw new RuntimeException("Test failed: couldn't load resource");
    }


}
 
Example 6
Project: fitnotifications   File: UResourceBundle.java   Source Code and License 6 votes vote down vote up
private static RootType getRootType(String baseName, ClassLoader root) {
    RootType rootType = ROOT_CACHE.get(baseName);

    if (rootType == null) {
        String rootLocale = (baseName.indexOf('.')==-1) ? "root" : "";
        try{
            ICUResourceBundle.getBundleInstance(baseName, rootLocale, root, true);
            rootType = RootType.ICU;
        }catch(MissingResourceException ex){
            try{
                ResourceBundleWrapper.getBundleInstance(baseName, rootLocale, root, true);
                rootType = RootType.JAVA;
            }catch(MissingResourceException e){
                //throw away the exception
                rootType = RootType.MISSING;
            }
        }

        ROOT_CACHE.put(baseName, rootType);
    }

    return rootType;
}
 
Example 7
Project: s-store   File: Resources.java   Source Code and 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 8
Project: jdk8u-jdk   File: LoadItUp2.java   Source Code and License 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 9
Project: fitnotifications   File: NumberingSystem.java   Source Code and License 6 votes vote down vote up
private static NumberingSystem lookupInstanceByName(String name) {
    int radix;
    boolean isAlgorithmic;
    String description;
    try {
        UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "numberingSystems");
        UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
        UResourceBundle nsTop = nsCurrent.get(name);

        description = nsTop.getString("desc");
        UResourceBundle nsRadixBundle = nsTop.get("radix");
        UResourceBundle nsAlgBundle = nsTop.get("algorithmic");
        radix = nsRadixBundle.getInt();
        int algorithmic = nsAlgBundle.getInt();

        isAlgorithmic = ( algorithmic == 1 );

    } catch (MissingResourceException ex) {
        return null;
    }

    return getInstance(name, radix, isAlgorithmic, description);
}
 
Example 10
Project: OpenJSharp   File: DatatypeException.java   Source Code and License 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
Project: parabuild-ci   File: RefCapablePropertyResourceBundle.java   Source Code and License 6 votes vote down vote up
/**
 * Return a ref to a new or existing RefCapablePropertyResourceBundle,
 * or throw a MissingResourceException.
 */
static private RefCapablePropertyResourceBundle getRef(String baseName,
        ResourceBundle rb, ClassLoader loader) {
    if (!(rb instanceof PropertyResourceBundle))
        throw new MissingResourceException(
                "Found a Resource Bundle, but it is a "
                        + rb.getClass().getName(),
                PropertyResourceBundle.class.getName(), null);
    if (allBundles.containsKey(rb))
        return (RefCapablePropertyResourceBundle) allBundles.get(rb);
    RefCapablePropertyResourceBundle newPRAFP =
            new RefCapablePropertyResourceBundle(baseName,
                    (PropertyResourceBundle) rb, loader);
    allBundles.put(rb, newPRAFP);
    return newPRAFP;
}
 
Example 12
Project: incubator-netbeans   File: Switches.java   Source Code and License 6 votes vote down vote up
/**
 * Defines the tab placement. The possible bundle values are <code>top</code>, <code>bottom</code>, <code>left</code>, <code>right</code>.
 * @return Tab placement when JTabbedPane implementation of Tab Control is
 * being used. The return value is one of <code>JTabbedPane.TOP</code> (default), <code>JTabbedPane.BOTTOM</code>,
 * <code>JTabbedPane.LEFT</code>, <code>JTabbedPane.RIGHT</code>.
 * 
 * @see JTabbedPane#getTabPlacement() 
 * 
 * @since 2.44
 */
public static int getSimpleTabsPlacement() {
    int result = JTabbedPane.TOP;
    try {
        String resValue = NbBundle.getMessage(Switches.class, "WinSys.TabControl.SimpleTabs.Placement" ); //NOI18N
        if( "bottom".equals( resValue ) )
            result = JTabbedPane.BOTTOM;
        else if( "right".equals( resValue ) )
            result = JTabbedPane.RIGHT;
        else if( "left".equals( resValue ) )
            result = JTabbedPane.LEFT;
    } catch( MissingResourceException mrE ) {
        //ignore
    }
    return result;
}
 
Example 13
Project: openjdk-jdk10   File: JavacMessages.java   Source Code and License 6 votes vote down vote up
private static String getLocalizedString(List<ResourceBundle> bundles,
                                         String key,
                                         Object... args) {
   String msg = null;
   for (List<ResourceBundle> l = bundles; l.nonEmpty() && msg == null; l = l.tail) {
       ResourceBundle rb = l.head;
       try {
           msg = rb.getString(key);
       }
       catch (MissingResourceException e) {
           // ignore, try other bundles in list
       }
   }
   if (msg == null) {
       msg = "compiler message file broken: key=" + key +
           " arguments={0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}";
   }
   return MessageFormat.format(msg, args);
}
 
Example 14
Project: OpenJSharp   File: CatalogManager.java   Source Code and License 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 15
Project: sstore-soft   File: Resources.java   Source Code and 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 16
Project: lams   File: NLS.java   Source Code and License 6 votes vote down vote up
private static Object getResourceBundleObject(String messageKey, Locale locale) {

    // slow resource checking
    // need to loop thru all registered resource bundles
    for (Iterator<String> it = bundles.keySet().iterator(); it.hasNext();) {
      Class<? extends NLS> clazz = bundles.get(it.next());
      ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(),
          locale);
      if (resourceBundle != null) {
        try {
          Object obj = resourceBundle.getObject(messageKey);
          if (obj != null)
            return obj;
        } catch (MissingResourceException e) {
          // just continue it might be on the next resource bundle
        }
      }
    }
    // if resource is not found
    return null;
  }
 
Example 17
Project: fitnotifications   File: ICUResourceBundle.java   Source Code and License 6 votes vote down vote up
ICUResourceBundle get(String aKey, HashMap<String, String> aliasesVisited, UResourceBundle requested) {
    ICUResourceBundle obj = (ICUResourceBundle)handleGet(aKey, aliasesVisited, requested);
    if (obj == null) {
        obj = getParent();
        if (obj != null) {
            //call the get method to recursively fetch the resource
            obj = obj.get(aKey, aliasesVisited, requested);
        }
        if (obj == null) {
            String fullName = ICUResourceBundleReader.getFullName(getBaseName(), getLocaleID());
            throw new MissingResourceException(
                    "Can't find resource for bundle " + fullName + ", key "
                            + aKey, this.getClass().getName(), aKey);
        }
    }
    return obj;
}
 
Example 18
Project: incubator-netbeans   File: TestBundleKeys.java   Source Code and License 6 votes vote down vote up
/**
 * Performs the test itself.
 *
 * @throws java.lang.Throwable
 */
protected void runTest() throws Throwable {

    String keys = getProperties(getDescendantClassLoader(), getPropertiesName()).getProperty(getName());

    ResourceBundle lrBundle=NbBundle.getBundle(getName());

    String[] lrTokens = keys.split(",");        
    int lnNumMissing = 0;
    StringBuffer lrBufMissing = new StringBuffer();
    for (String lsKey : lrTokens)
    try {
        lrBundle.getObject(lsKey);
    } catch (MissingResourceException mre) {
        lrBufMissing.append(lsKey).append(" ");
        lnNumMissing++;
    }
    if (lnNumMissing > 0)
        throw new AssertionFailedError("Missing "+String.valueOf(lnNumMissing)+" key(s): "+ lrBufMissing.toString());

}
 
Example 19
Project: jdk8u-jdk   File: AccessibleBundle.java   Source Code and License 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 20
Project: OpenJSharp   File: JavacMessages.java   Source Code and License 6 votes vote down vote up
public List<ResourceBundle> getBundles(Locale locale) {
    if (locale == currentLocale && currentBundles != null)
        return currentBundles;
    SoftReference<List<ResourceBundle>> bundles = bundleCache.get(locale);
    List<ResourceBundle> bundleList = bundles == null ? null : bundles.get();
    if (bundleList == null) {
        bundleList = List.nil();
        for (String bundleName : bundleNames) {
            try {
                ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
                bundleList = bundleList.prepend(rb);
            } catch (MissingResourceException e) {
                throw new InternalError("Cannot find javac resource bundle for locale " + locale);
            }
        }
        bundleCache.put(locale, new SoftReference<List<ResourceBundle>>(bundleList));
    }
    return bundleList;
}
 
Example 21
Project: lazycat   File: ResourceBundleELResolver.java   Source Code and License 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property)
		throws NullPointerException, PropertyNotFoundException, ELException {

	if (context == null) {
		throw new NullPointerException();
	}

	if (base instanceof ResourceBundle) {
		context.setPropertyResolved(true);

		if (property != null) {
			try {
				return ((ResourceBundle) base).getObject(property.toString());
			} catch (MissingResourceException mre) {
				return "???" + property.toString() + "???";
			}
		}
	}

	return null;
}
 
Example 22
Project: incubator-netbeans   File: MakeDefaultCatalogAction.java   Source Code and License 6 votes vote down vote up
/**
 * If DDL exception was caused by a closed connection, log info and display
 * a simple error dialog. Otherwise let users report the exception.
 */
private void handleDLLException(DatabaseConnection dbConn,
        DDLException e) throws SQLException, MissingResourceException {
    Connection conn = dbConn == null ? null : dbConn.getJDBCConnection();
    if (conn != null && !conn.isValid(1000)) {
        LOGGER.log(Level.INFO, e.getMessage(), e);
        NotifyDescriptor nd = new NotifyDescriptor.Message(
                NbBundle.getMessage(
                MakeDefaultCatalogAction.class,
                "ERR_ConnectionToServerClosed"), //NOI18N
                NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notifyLater(nd);
    } else {
        Exceptions.printStackTrace(e);
    }
}
 
Example 23
Project: logistimo-web-service   File: Resources.java   Source Code and License 6 votes vote down vote up
public ResourceBundle getBundle(String baseName, Locale locale) throws MissingResourceException {
  if (baseName == null || locale == null) {
    return null;
  }
  // Get the resource bundle, if not already present
  String key = baseName + "_" + locale.toString();
  xLogger.fine("Resources.getBundle(): trying first key = {0}", key);
  ResourceBundle bundle = rmap.get(key);
  if (bundle == null) {
    key = baseName + "_" + locale.getLanguage();
    bundle = rmap.get(key);
    xLogger.fine("Resources.getBundle(): tried second key = {0}, bundle = {1}", key, bundle);
    if (bundle == null) {
      bundle = getUTF8Bundle(baseName, locale);
      key =
          baseName + "_" + bundle.getLocale()
              .toString(); // actual (fallback) locale used to get the file
      xLogger.fine(
          "Resource.getBundle(): getting it first time using locale = {0}, actual key = {0}",
          locale.toString(), key);
      rmap.put(key, bundle);
    }
  }
  return bundle;
}
 
Example 24
Project: myfaces-trinidad   File: CompositeRenderingContext.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a translated value from the skin's resource bundle.
 * Logs a severe message if there is a MissingResourceException.
 */
public Object getTranslatedValue(String key)
{
  String mappedKey = getSkinResourceMappedKey(key);

  if (mappedKey != null)
  {
    try{
      return getParentContext().getTranslatedValue(mappedKey);
    }
    catch (MissingResourceException e)
    {
      // log the error and return
      _LOG.severe(e);

      return null;
    }
  }
  else
    return null;

}
 
Example 25
Project: openjdk-jdk10   File: DatatypeException.java   Source Code and License 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 26
Project: parabuild-ci   File: RefCapablePropertyResourceBundle.java   Source Code and License 6 votes vote down vote up
/**
 * Return a ref to a new or existing RefCapablePropertyResourceBundle,
 * or throw a MissingResourceException.
 */
static private RefCapablePropertyResourceBundle getRef(String baseName,
        ResourceBundle rb, ClassLoader loader) {
    if (!(rb instanceof PropertyResourceBundle))
        throw new MissingResourceException(
                "Found a Resource Bundle, but it is a "
                        + rb.getClass().getName(),
                PropertyResourceBundle.class.getName(), null);
    if (allBundles.containsKey(rb))
        return (RefCapablePropertyResourceBundle) allBundles.get(rb);
    RefCapablePropertyResourceBundle newPRAFP =
            new RefCapablePropertyResourceBundle(baseName,
                    (PropertyResourceBundle) rb, loader);
    allBundles.put(rb, newPRAFP);
    return newPRAFP;
}
 
Example 27
Project: fitnotifications   File: Calendar.java   Source Code and License 6 votes vote down vote up
private static WeekData getWeekDataForRegionInternal(String region) {
    if (region == null) {
        region = "001";
    }

    UResourceBundle rb = UResourceBundle.getBundleInstance(
            ICUData.ICU_BASE_NAME,
            "supplementalData",
            ICUResourceBundle.ICU_DATA_CLASS_LOADER);
    UResourceBundle weekDataInfo = rb.get("weekData");
    UResourceBundle weekDataBundle = null;

    try {
        weekDataBundle = weekDataInfo.get(region);
    } catch (MissingResourceException mre) {
        if (!region.equals("001")) {
            // use "001" as fallback
            weekDataBundle = weekDataInfo.get("001");
        } else {
            throw mre;
        }
    }

    int[] wdi = weekDataBundle.getIntVector();
    return new WeekData(wdi[0],wdi[1],wdi[2],wdi[3],wdi[4],wdi[5]);
}
 
Example 28
Project: tomcat7   File: StringManager.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new StringManager for a given package. This is a
 * private method and all access to it is arbitrated by the
 * static getManager method call so that only one StringManager
 * per package will be created.
 *
 * @param packageName Name of package to create StringManager for.
 */
private StringManager(String packageName) {
    String bundleName = packageName + ".LocalStrings";
    try {
        bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
    } catch( MissingResourceException ex ) {
        // Try from the current loader (that's the case for trusted apps)
        // Should only be required if using a TC5 style classloader structure
        // where common != shared != server
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if( cl != null ) {
            try {
                bundle = ResourceBundle.getBundle(
                        bundleName, Locale.getDefault(), cl);
            } catch(MissingResourceException ex2) {
                // Ignore
            }
        }
    }
    // Get the actual locale, which may be different from the requested one
    if (bundle != null) {
        locale = bundle.getLocale();
    }
}
 
Example 29
Project: openjdk-jdk10   File: XSMessageFormatter.java   Source Code and License 5 votes vote down vote up
/**
 * Formats a message with the specified arguments using the given
 * locale information.
 *
 * @param locale    The locale of the message.
 * @param key       The message key.
 * @param arguments The message replacement text arguments. The order
 *                  of the arguments must match that of the placeholders
 *                  in the actual message.
 *
 * @return Returns the formatted message.
 *
 * @throws MissingResourceException Thrown if the message with the
 *                                  specified key cannot be found.
 */
 public String formatMessage(Locale locale, String key, Object[] arguments)
    throws MissingResourceException {

    if (fResourceBundle == null || locale != fLocale) {
        if (locale != null) {
            fResourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", locale);
            // memorize the most-recent locale
            fLocale = locale;
        }
        if (fResourceBundle == null)
            fResourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages");
    }

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

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

    return msg;
}
 
Example 30
Project: SimQRI   File: MetamodelModelWizard.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the label for the specified type name.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected String getLabel(String typeName) {
	try {
		return MetamodelEditPlugin.INSTANCE.getString("_UI_" + typeName + "_type");
	}
	catch(MissingResourceException mre) {
		MetamodelEditorPlugin.INSTANCE.log(mre);
	}
	return typeName;
}
 
Example 31
Project: apache-tomcat-7.0.73-with-comment   File: StringManager.java   Source Code and License 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle or return null if the
 * String is not found.
 *
 * @param key to desired resource String
 *
 * @return resource String matching <i>key</i> from underlying bundle or
 *         null if not found.
 *
 * @throws IllegalArgumentException if <i>key</i> is null
 */
public String getString(String key) {
    if (key == null){
        String msg = "key may not have a null value";
        throw new IllegalArgumentException(msg);
    }

    String str = null;

    try {
        // Avoid NPE if bundle is null and treat it like an MRE
        if (bundle != null) {
            str = bundle.getString(key);
        }
    } catch (MissingResourceException mre) {
        //bad: shouldn't mask an exception the following way:
        //   str = "[cannot find message associated with key '" + key +
        //         "' due to " + mre + "]";
        //     because it hides the fact that the String was missing
        //     from the calling code.
        //good: could just throw the exception (or wrap it in another)
        //      but that would probably cause much havoc on existing
        //      code.
        //better: consistent with container pattern to
        //      simply return null.  Calling code can then do
        //      a null check.
        str = null;
    }

    return str;
}
 
Example 32
Project: jdk8u-jdk   File: Resources.java   Source Code and License 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 33
Project: oscm   File: Messages.java   Source Code and License 5 votes vote down vote up
public static String get(String locale, String key) {

        try {
            if (bundleList.containsKey(locale))
                return bundleList.get(locale).getString(key);
            else
                return bundleList.get(DEFAULT_LOCALE).getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
 
Example 34
Project: OpenJSharp   File: RegexParser.java   Source Code and License 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 35
Project: lams   File: Localizer.java   Source Code and License 5 votes vote down vote up
public static String getMessage(String errCode) {
String errMsg = errCode;
try {
    errMsg = bundle.getString(errCode);
} catch (MissingResourceException e) {
}
return errMsg;
   }
 
Example 36
Project: myfaces-trinidad   File: TranslationsResourceLoader.java   Source Code and License 5 votes vote down vote up
private ResourceBundle _getResourceBundle(Locale locale)
  throws MissingResourceException
{
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  return ResourceBundle.getBundle(getBundleName(),
                                  locale,
                                  loader);
}
 
Example 37
Project: org.mybatis.generator.core-1.3.5   File: Messages.java   Source Code and License 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 38
Project: jdk8u-jdk   File: Agent.java   Source Code and License 5 votes vote down vote up
private static void initResource() {
    try {
        messageRB =
                ResourceBundle.getBundle("sun.management.resources.agent");
    } catch (MissingResourceException e) {
        throw new Error("Fatal: Resource for management agent is missing");
    }
}
 
Example 39
Project: tomcat7   File: MessageFactory.java   Source Code and License 5 votes vote down vote up
public static String get(final String key) {
    try {
        return bundle.getString(key);
    } catch (MissingResourceException e) {
        return key;
    }
}
 
Example 40
Project: openjdk-jdk10   File: SecuritySupport.java   Source Code and License 5 votes vote down vote up
/**
 * Gets a resource bundle using the specified base name and locale, and the caller's class loader.
 * @param bundle the base name of the resource bundle, a fully qualified class name
 * @param locale the locale for which a resource bundle is desired
 * @return a resource bundle for the given base name and locale
 */
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) {
    return AccessController.doPrivileged((PrivilegedAction<ResourceBundle>) () -> {
        try {
            return PropertyResourceBundle.getBundle(bundle, locale);
        } catch (MissingResourceException e) {
            try {
                return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US"));
            } catch (MissingResourceException e2) {
                throw new MissingResourceException(
                        "Could not load any resource bundle by " + bundle, bundle, "");
            }
        }
    });
}