Example usage for java.util MissingResourceException MissingResourceException

List of usage examples for java.util MissingResourceException MissingResourceException

Introduction

In this page you can find the example usage for java.util MissingResourceException MissingResourceException.

Prototype

public MissingResourceException(String s, String className, String key) 

Source Link

Document

Constructs a MissingResourceException with the specified information.

Usage

From source file:org.apache.openjpa.lib.conf.Configurations.java

/**
 * Set the given {@link Configuration} instance from the command line
 * options provided. All property names of the given configuration are
 * recognized; additionally, if a <code>properties</code> or
 * <code>p</code> argument exists, the resource it
 * points to will be loaded and set into the given configuration instance.
 * It can point to either a file or a resource name.
 *///from  w  ww .j  a  v  a2s . c  om
public static void populateConfiguration(Configuration conf, Options opts) {
    String props = opts.removeProperty("properties", "p", null);
    ConfigurationProvider provider;
    if (!StringUtils.isEmpty(props)) {
        Map<String, String> result = parseConfigResource(props);
        String path = result.get(CONFIG_RESOURCE_PATH);
        String anchor = result.get(CONFIG_RESOURCE_ANCHOR);

        File file = new File(path);
        if ((AccessController.doPrivileged(J2DoPrivHelper.isFileAction(file))).booleanValue())
            provider = ProductDerivations.load(file, anchor, null);
        else {
            file = new File("META-INF" + File.separatorChar + path);
            if ((AccessController.doPrivileged(J2DoPrivHelper.isFileAction(file))).booleanValue())
                provider = ProductDerivations.load(file, anchor, null);
            else
                provider = ProductDerivations.load(path, anchor, null);
        }
        if (provider != null)
            provider.setInto(conf);
        else
            throw new MissingResourceException(_loc.get("no-provider", props).getMessage(),
                    Configurations.class.getName(), props);
    } else {
        provider = ProductDerivations.loadDefaults(null);
        if (provider != null)
            provider.setInto(conf);
    }
    opts.setInto(conf);
}

From source file:org.pentaho.di.i18n.GlobalMessageUtil.java

/**
 * Retrieve a resource bundle of the default or fail-over locales.
 *
 * @param packagePath   The package to search in
 * @param resourceClass the class to use to resolve the bundle
 * @return The resource bundle//  www  .  j ava2  s. com
 * @throws MissingResourceException in case both resource bundles couldn't be found.
 */
public static ResourceBundle getBundle(final String packagePath, final Class<?> resourceClass)
        throws MissingResourceException {
    final Set<Locale> activeLocales = getActiveLocales();
    for (final Locale locale : activeLocales) {
        try {
            return getBundle(locale, packagePath, resourceClass);
        } catch (MissingResourceException e) {
            final StringBuilder msg = new StringBuilder();
            msg.append("Unable to find properties file for package '").append(packagePath)
                    .append("' and class '").append(resourceClass.getName())
                    .append("' in the available locales: ").append(locale);
            // nothing to do, an exception will be thrown if no bundle is found
            log.warn(msg.toString());
        }
    }
    final StringBuilder msg = new StringBuilder();
    msg.append("Unable to find properties file for package '").append(packagePath).append("' and class '")
            .append(resourceClass.getName()).append("' in the available locales: ")
            .append(Arrays.asList(activeLocales));
    throw new MissingResourceException(msg.toString(), resourceClass.getName(), packagePath);
}

From source file:org.apache.openjpa.lib.conf.Configurations.java

public static Map<String, String> parseConfigResource(String props) {
    String path = props;//  w w  w .  j av a 2 s  .c o  m
    String anchor = null;
    int idx = path.lastIndexOf('#');
    if (idx != -1) {
        if (idx < path.length() - 1)
            anchor = path.substring(idx + 1);
        path = path.substring(0, idx);
        if (path.length() == 0)
            throw new MissingResourceException(_loc.get("anchor-only", props).getMessage(),
                    Configurations.class.getName(), props);
    }
    Map<String, String> result = new HashMap<String, String>();
    result.put(CONFIG_RESOURCE_PATH, path);
    result.put(CONFIG_RESOURCE_ANCHOR, anchor);
    return result;
}

From source file:org.pentaho.di.i18n.GlobalMessageUtil.java

/**
 * Returns a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class. Falls-back
 * on the ROOT {@link Locale}, if the {@code fallbackOnRoot} flag is true and the requested Locale is not available.
 *
 * @param locale         the {@link Locale} for which the {@link ResourceBundle} is being requested
 * @param packagePath//w  w w.ja v a 2s  . c  o  m
 * @param resourceClass
 * @param fallbackOnRoot if true, and a {@link ResourceBundle} cannot be found for the requested {@link Locale}, falls
 *                       back on the ROOT {@link Locale}
 * @return a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class
 */
public static ResourceBundle getBundle(final Locale locale, final String packagePath,
        final Class<?> resourceClass, final boolean fallbackOnRoot) {
    final GlobalMessageControl control = new GlobalMessageControl(fallbackOnRoot);
    final String resourceName = control.toResourceName(control.toBundleName(packagePath, locale), "properties");

    ResourceBundle bundle;
    try {
        bundle = ResourceBundle.getBundle(packagePath, locale, resourceClass.getClassLoader(),
                new GlobalMessageControl(fallbackOnRoot));
    } catch (final MissingResourceException e) {
        final StringBuilder msg = new StringBuilder();
        msg.append("Unable to find properties file '").append(resourceName).append("': ").append(e.toString());
        throw new MissingResourceException(msg.toString(), resourceClass.getName(), packagePath);
    }
    return bundle;
}

From source file:org.itracker.core.resources.ITrackerResources.java

public static String getCheckForKey(String key, Locale locale) throws MissingResourceException {
    try {//  www  .  j a  v  a  2s .  c o m
        return getBundle(locale).getString(key);
    } catch (ITrackerDirtyResourceException idre) {
        return getString(key, locale);
    } catch (NullPointerException ex) {
        logger.debug("Unable to get ResourceBundle for locale " + locale, ex);
        throw new MissingResourceException("MISSING LOCALE: " + locale, "ITrackerResources", key);
    }
}

From source file:org.apache.openjpa.lib.conf.ConfigurationImpl.java

/**
 * Find the given localized string, or return null if not found.
 *//* w w w. j  av  a 2s  .  com*/
@SuppressWarnings("unchecked")
private String findLocalized(String key, boolean fatal, Class<?> scope) {
    // find the localizer package that contains this key
    Localizer loc = null;

    // check the package that the value claims to be defined in, if
    // available, before we start guessing.
    if (scope != null) {
        loc = Localizer.forPackage(scope);
        try {
            return loc.getFatal(key).getMessage();
        } catch (MissingResourceException mse) {
        }
    }

    for (Class cls = getClass(); cls != Object.class; cls = cls.getSuperclass()) {
        loc = Localizer.forPackage(cls);
        try {
            return loc.getFatal(key).getMessage();
        } catch (MissingResourceException mse) {
        }
    }

    if (fatal)
        throw new MissingResourceException(key, getClass().getName(), key);
    return null;
}

From source file:org.acmsl.commons.BundleI14able.java

/**
 * Seventh attempt to retrieve the bundle.
 * @param bundleName the bundle name./*from   w w w  .  ja v  a  2s .com*/
 * @return the bundle.
 * @throws MissingResourceException if the resource is missing.
 */
@Nullable
protected final ResourceBundle seventhTry(@NotNull final String bundleName) throws MissingResourceException {
    @Nullable
    ResourceBundle result = null;

    Throwable exceptionThrown = null;

    MissingResourceException exceptionToThrow = null;

    try {
        // last attempt.
        result = new PropertyResourceBundle(new FileInputStream(bundleName));
    } catch (final FileNotFoundException thirdFileNotFoundException) {
        exceptionThrown = thirdFileNotFoundException;
    } catch (final IOException thirdIOException) {
        exceptionThrown = thirdIOException;
    } finally {
        if (exceptionThrown != null) {
            exceptionToThrow = new MissingResourceException(exceptionThrown.getLocalizedMessage(),
                    exceptionThrown.getClass().getName(), "(none)");
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }

    return result;
}

From source file:org.libreplan.business.common.LibrePlanClassValidator.java

/** @deprecated */
private String replace(String message, Annotation parameters) {
    StringTokenizer tokens = new StringTokenizer(message, "#{}", true);
    StringBuilder buf = new StringBuilder(30);
    boolean escaped = false;
    boolean el = false;
    while (tokens.hasMoreTokens()) {
        String token = tokens.nextToken();
        if (!escaped && "#".equals(token)) {
            el = true;/*from  ww w  .  j a v a2 s .c o m*/
        }
        if (!el && "{".equals(token)) {
            escaped = true;
        } else if (escaped && "}".equals(token)) {
            escaped = false;
        } else if (!escaped) {
            if ("{".equals(token))
                el = false;
            buf.append(token);
        } else {
            Method member;
            try {
                member = parameters.getClass().getMethod(token, (Class[]) null);
            } catch (NoSuchMethodException nsfme) {
                member = null;
            }
            if (member != null) {
                try {
                    buf.append(member.invoke(parameters));
                } catch (Exception e) {
                    throw new IllegalArgumentException("could not render message", e);
                }
            } else {
                String string = null;
                try {
                    string = messageBundle != null ? messageBundle.getString(token) : null;
                } catch (MissingResourceException e) {
                    //give a second chance with the default resource bundle
                }
                if (string == null) {
                    try {
                        string = defaultMessageBundle.getString(token);
                    } catch (MissingResourceException e) {
                        throw new MissingResourceException(
                                "Can't find resource in validator bundles, key " + token,
                                defaultMessageBundle.getClass().getName(), token);
                    }
                }
                if (string != null)
                    buf.append(replace(string, parameters));
            }
        }
    }
    return buf.toString();
}

From source file:org.itracker.services.implementations.ConfigurationServiceImpl.java

@Override
public String getLanguageEntry(String key, Locale locale) {
    try {//from w w  w  .j  a va 2s.co m
        Language l = getLanguageItemByKey(key, locale);
        return l.getResourceValue();
    } catch (NoSuchEntityException e) {
        logger.debug("failed to get entry", e);
    }
    throw new MissingResourceException("Entry doesn't exist.", Language.class.getName(), key);
}

From source file:gov.va.vinci.leo.descriptors.LeoAEDescriptor.java

/**
 * Generate the XML for the analysisEngine section of the deployment descriptor.
 *
 * @param thd    the xml transform handler.
 * @param isTopDescriptor   true if this is a top level descriptor, else false.
 * @throws SAXException  if there is no descriptor to output
 * @return this Leo AE Descriptor//w ww .  ja va2 s  .  c  om
 */

public LeoAEDescriptor analysisEngineSection(TransformerHandler thd, boolean isTopDescriptor)
        throws SAXException {
    //validate we have something to output
    if (this.mAEDescriptor == null)
        throw new MissingResourceException("No Descriptor available for XML output",
                AnalysisEngineDescription.class.getCanonicalName(), "mAEDescriptor");

    AttributesImpl atts = new AttributesImpl();
    //<analysisEngine>
    if (!isTopDescriptor)
        atts.addAttribute("", "", "key", "CDATA", mAEDescriptor.getMetaData().getName());
    if (mIsAsync) {
        atts.addAttribute("", "", "async", "CDATA", "true");
    } else {
        atts.addAttribute("", "", "async", "CDATA", "false");
    } //else

    atts.addAttribute("", "", "async", "CDATA", Boolean.toString(mIsAsync));
    thd.startElement("", "", "analysisEngine", atts);
    atts.clear();

    //<scaleout .../>
    atts.addAttribute("", "", "numberOfInstances", "CDATA", Integer.toString(mNumberOfInstances));
    thd.startElement("", "", "scaleout", atts);
    thd.endElement("", "", "scaleout");
    atts.clear();

    //Handle delegate tags for aggregate engines
    if (this.isAggregate() && mIsAsync) {
        //<delegates>
        thd.startElement("", "", "delegates", atts);

        //output all the delegate engines
        for (LeoDelegate delegate : mDelegates) {
            delegate.analysisEngineSection(thd, false);
        } //for

        //</delegates>
        thd.endElement("", "", "delegates");
    } //if

    //<asyncPrimitiveErrorConfiguration> or <asyncAggregateErrorConfiguration>
    if (isTopDescriptor)
        thd.startElement("", "", "asyncPrimitiveErrorConfiguration", atts);
    else
        thd.startElement("", "", "asyncAggregateErrorConfiguration", atts);

    //<getMetadataErrors .../>
    if (!isTopDescriptor) {
        atts.addAttribute("", "", "maxRetries", "CDATA", "0");
        atts.addAttribute("", "", "timeout", "CDATA", "0");
        atts.addAttribute("", "", "errorAction", "CDATA", "terminate");
        thd.startElement("", "", "getMetadataErrors", atts);
        thd.endElement("", "", "getMetadataErrors");
        atts.clear();
    } //if

    //<processCasErrors .../>
    atts.addAttribute("", "", "thresholdCount", "CDATA", "0");
    atts.addAttribute("", "", "thresholdWindow", "CDATA", "0");
    atts.addAttribute("", "", "thresholdAction", "CDATA", "terminate");
    thd.startElement("", "", "processCasErrors", atts);
    thd.endElement("", "", "processCasErrors");
    atts.clear();

    //<collectionProcessCompleteErrors .../>
    atts.addAttribute("", "", "timeout", "CDATA", "0");
    atts.addAttribute("", "", "additionalErrorAction", "CDATA", "terminate");
    thd.startElement("", "", "collectionProcessCompleteErrors", atts);
    thd.endElement("", "", "collectionProcessCompleteErrors");
    atts.clear();

    //</asyncPrimitiveErrorConfiguration> or <asyncAggregateErrorConfiguration>
    if (isTopDescriptor)
        thd.endElement("", "", "asyncPrimitiveErrorConfiguration");
    else
        thd.endElement("", "", "asyncAggregateErrorConfiguration");

    //</analysisEngine>
    thd.endElement("", "", "analysisEngine");
    return this;
}