Search in sources :

Example 36 with MissingResourceException

use of java.util.MissingResourceException in project android_frameworks_base by DirtyUnicorns.

the class TextToSpeechService method onIsValidVoiceName.

/**
     * Checks whether the engine supports a voice with a given name.
     *
     * Can be called on multiple threads.
     *
     * The default implementation treats the voice name as a language tag, creating a Locale from
     * the voice name, and passes it to {@link #onIsLanguageAvailable(String, String, String)}.
     *
     * @param voiceName Name of the voice.
     * @return {@link TextToSpeech#ERROR} or {@link TextToSpeech#SUCCESS}.
     */
public int onIsValidVoiceName(String voiceName) {
    Locale locale = Locale.forLanguageTag(voiceName);
    if (locale == null) {
        return TextToSpeech.ERROR;
    }
    int expectedStatus = getExpectedLanguageAvailableStatus(locale);
    try {
        int localeStatus = onIsLanguageAvailable(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
        if (localeStatus != expectedStatus) {
            return TextToSpeech.ERROR;
        }
        return TextToSpeech.SUCCESS;
    } catch (MissingResourceException e) {
        return TextToSpeech.ERROR;
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException)

Example 37 with MissingResourceException

use of java.util.MissingResourceException in project android_frameworks_base by DirtyUnicorns.

the class TtsEngines method parseLocaleString.

/**
     * Parses a locale encoded as a string, and tries its best to return a valid {@link Locale}
     * object, even if the input string is encoded using the old-style 3 character format e.g.
     * "deu-deu". At the end, we test if the resulting locale can return ISO3 language and
     * country codes ({@link Locale#getISO3Language()} and {@link Locale#getISO3Country()}),
     * if it fails to do so, we return null.
     */
public Locale parseLocaleString(String localeString) {
    String language = "", country = "", variant = "";
    if (!TextUtils.isEmpty(localeString)) {
        String[] split = localeString.split("[" + LOCALE_DELIMITER_OLD + LOCALE_DELIMITER_NEW + "]");
        language = split[0].toLowerCase();
        if (split.length == 0) {
            Log.w(TAG, "Failed to convert " + localeString + " to a valid Locale object. Only" + " separators");
            return null;
        }
        if (split.length > 3) {
            Log.w(TAG, "Failed to convert " + localeString + " to a valid Locale object. Too" + " many separators");
            return null;
        }
        if (split.length >= 2) {
            country = split[1].toUpperCase();
        }
        if (split.length >= 3) {
            variant = split[2];
        }
    }
    String normalizedLanguage = sNormalizeLanguage.get(language);
    if (normalizedLanguage != null) {
        language = normalizedLanguage;
    }
    String normalizedCountry = sNormalizeCountry.get(country);
    if (normalizedCountry != null) {
        country = normalizedCountry;
    }
    if (DBG)
        Log.d(TAG, "parseLocalePref(" + language + "," + country + "," + variant + ")");
    Locale result = new Locale(language, country, variant);
    try {
        result.getISO3Language();
        result.getISO3Country();
        return result;
    } catch (MissingResourceException e) {
        Log.w(TAG, "Failed to convert " + localeString + " to a valid Locale object.");
        return null;
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException) Secure.getString(android.provider.Settings.Secure.getString)

Example 38 with MissingResourceException

use of java.util.MissingResourceException in project OpenAM by OpenRock.

the class CommandManager method init.

private void init(Map env) throws CLIException {
    environment = new HashMap();
    Locale locale = (Locale) env.get(CLIConstants.ARGUMENT_LOCALE);
    if (locale == null) {
        locale = Locale.getDefault();
    }
    environment.put(CLIConstants.ARGUMENT_LOCALE, locale);
    try {
        rbMessages = ResourceBundle.getBundle(RESOURCE_BUNDLE_NAME, locale);
    } catch (MissingResourceException e) {
        outputWriter.printlnError(e.getMessage());
        System.exit(ExitCodes.MISSING_RESOURCE_BUNDLE);
    }
    String defintionFiles = (String) env.get(CLIConstants.SYS_PROPERTY_DEFINITION_FILES);
    setupDefinitions(defintionFiles);
    commandName = (String) env.get(CLIConstants.SYS_PROPERTY_COMMAND_NAME);
    if ((commandName == null) || (commandName.length() == 0)) {
        throw new CLIException(rbMessages.getString("exception-message-missing-command-name"), ExitCodes.MISSING_COMMAND_NAME);
    }
    outputWriter = (IOutput) env.get(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER);
    if (outputWriter == null) {
        throw new CLIException("output writer is not defined.", ExitCodes.OUTPUT_WRITER_CLASS_CANNOT_INSTANTIATE);
    }
    if (env.get(CLIConstants.ARGUMENT_DEBUG) != null) {
        environment.put(CLIConstants.ARGUMENT_DEBUG, Boolean.TRUE);
    }
    if (env.get(CLIConstants.ARGUMENT_VERBOSE) != null) {
        environment.put(CLIConstants.ARGUMENT_VERBOSE, Boolean.TRUE);
    }
    String webEnabledURL = (String) env.get(CLIConstants.WEB_ENABLED_URL);
    if (webEnabledURL != null) {
        environment.put(CLIConstants.WEB_ENABLED_URL, webEnabledURL);
    }
    debugger = Debug.getInstance("amCLI");
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) MissingResourceException(java.util.MissingResourceException)

Example 39 with MissingResourceException

use of java.util.MissingResourceException in project ORCID-Source by ORCID.

the class RetryListener method processMessage.

/**
     * Processes messages on receipt.
     * 
     * @param map
     * @throws JsonProcessingException
     * @throws JAXBException
     * @throws AmazonClientException
     */
@JmsListener(destination = MessageConstants.Queues.RETRY)
public void processMessage(final Map<String, String> map) throws JsonProcessingException, AmazonClientException, JAXBException {
    RetryMessage message = new RetryMessage(map);
    String orcid = message.getOrcid();
    if (message.getMap() == null || message.getMap().get(RetryMessage.BROKER_NAME) == null) {
        throw new MissingResourceException("Unable to find destination broker", String.class.getName(), RetryMessage.BROKER_NAME);
    }
    AvailableBroker destinationBroker = AvailableBroker.fromValue(message.getMap().get(RetryMessage.BROKER_NAME));
    LOG.info("Recieved " + MessageConstants.Queues.RETRY + " message for orcid " + orcid + " to broker " + destinationBroker);
    if (AvailableBroker.DUMP_STATUS_1_2_API.equals(destinationBroker) || AvailableBroker.DUMP_STATUS_2_0_API.equals(destinationBroker)) {
        s3Processor.accept(message);
    } else if (AvailableBroker.SOLR.equals(destinationBroker)) {
        solrProcessor.accept(message);
    }
}
Also used : AvailableBroker(org.orcid.listener.persistence.util.AvailableBroker) MissingResourceException(java.util.MissingResourceException) RetryMessage(org.orcid.utils.listener.RetryMessage) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 40 with MissingResourceException

use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.

the class LoggerResourceBundleRace method executeRace.

public void executeRace(WorkerThread wt) {
    super.executeRace(wt);
    Logger myLogger = null;
    try {
        // short hand
        MyWorkerThread mwt = (MyWorkerThread) wt;
        // Here is the race:
        // - the target Logger object has already been created by
        //   the DriverThread without a ResourceBundle name
        // - in parallel, each WorkerThread calls Logger.getLogger()
        //   with a different ResourceBundle name
        // - Logger.getLogger() should only successfully set the
        //   ResourceBundle name for one WorkerThread; all other
        //   WorkerThread calls to Logger.getLogger() should throw
        //   IllegalArgumentException
        myLogger = Logger.getLogger(LOGGER_PREFIX + getLoopCnt(), mwt.rbName);
        if (myLogger.getResourceBundleName().equals(mwt.rbName)) {
            // no exception and the ResourceBundle names match
            // ignore return
            worksCnt.incrementAndGet();
        } else {
            System.err.println(wt.getName() + ": ERROR: expected ResourceBundleName '" + mwt.rbName + "' does not match actual '" + myLogger.getResourceBundleName() + "'");
            // ignore return
            incAndGetFailCnt();
        }
    } catch (IllegalArgumentException iae) {
        // ignore return
        iaeCnt.incrementAndGet();
    } catch (MissingResourceException mre) {
        // This exception happens when N_THREADS above does not
        // match the number of MyResources inner classes below.
        // We exit since this is a coding error.
        unexpectedException(wt, mre);
        System.exit(2);
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) Logger(java.util.logging.Logger)

Aggregations

MissingResourceException (java.util.MissingResourceException)163 ResourceBundle (java.util.ResourceBundle)85 Locale (java.util.Locale)67 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)10 MessageFormat (java.text.MessageFormat)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 File (java.io.File)7 PropertyResourceBundle (java.util.PropertyResourceBundle)7 SMSException (com.sun.identity.sm.SMSException)6 Secure.getString (android.provider.Settings.Secure.getString)5 SSOException (com.iplanet.sso.SSOException)5 Iterator (java.util.Iterator)5 Set (java.util.Set)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ISResourceBundle (com.sun.identity.common.ISResourceBundle)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Enumeration (java.util.Enumeration)3