Search in sources :

Example 51 with ResourceBundle

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

the class Debug method initialize.

/**
     * Initializes the Debug Service by locating the SPI implementations and
     * instantiating the appropriate classes.
     */
private static synchronized void initialize() {
    if (!serviceInitialized) {
        String providerName = SystemPropertiesManager.get(DebugConstants.CONFIG_DEBUG_PROVIDER);
        IDebugProvider provider = null;
        boolean providerLoadFailed = false;
        Exception exceptionCatched = null;
        if (providerName != null && providerName.trim().length() > 0) {
            try {
                provider = (IDebugProvider) Class.forName(providerName).newInstance();
            } catch (ClassNotFoundException cnex) {
                providerLoadFailed = true;
                exceptionCatched = cnex;
            } catch (InstantiationException iex) {
                providerLoadFailed = true;
                exceptionCatched = iex;
            } catch (IllegalAccessException iaex) {
                providerLoadFailed = true;
                exceptionCatched = iaex;
            } catch (ClassCastException ccex) {
                providerLoadFailed = true;
                exceptionCatched = ccex;
            }
        }
        if (provider == null) {
            if (providerLoadFailed) {
                ResourceBundle bundle = com.sun.identity.shared.locale.Locale.getInstallResourceBundle("amUtilMsgs");
                StdDebugFile.printError(Debug.class.getSimpleName(), bundle.getString("com.iplanet" + ".services" + ".debug.invalidprovider"), exceptionCatched);
            }
            provider = new DebugProviderImpl();
        }
        setDebugProvider(provider);
        serviceInitialized = true;
    }
}
Also used : ResourceBundle(java.util.ResourceBundle) DebugProviderImpl(com.sun.identity.shared.debug.impl.DebugProviderImpl)

Example 52 with ResourceBundle

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

the class AMResourceBundleCache method getResBundle.

/**
     * Returns resource bundle from cache.
     * 
     * @param name Name of bundle.
     * @param locale Localeof bundle.
     * @return Resource bundle.
     */
public ResourceBundle getResBundle(String name, Locale locale) {
    ResourceBundle resBundle = null;
    Map map = (Map) mapBundles.get(name);
    if (map != null) {
        resBundle = (ResourceBundle) map.get(locale);
    }
    if (resBundle == null) {
        try {
            resBundle = ResourceBundle.getBundle(name, locale);
        } catch (MissingResourceException mre) {
            debug.error("AMResourceBundleCache.getResBundle", mre);
        }
        synchronized (mapBundles) {
            if (map == null) {
                map = new HashMap(5);
                mapBundles.put(name, map);
            }
            map.put(locale, resBundle);
        }
    }
    return resBundle;
}
Also used : HashMap(java.util.HashMap) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) HashMap(java.util.HashMap)

Example 53 with ResourceBundle

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

the class EmailPassword method sendEmailToUser.

/**
     * Sents reset password email to the user.
     *
     * @param emailAddres email address of the user
     * @param password new password
     */
private void sendEmailToUser(String emailAddress, String password) throws MessagingException {
    String[] obj = new String[1];
    obj[0] = password;
    ResourceBundle rb = PWResetResBundleCacher.getBundle(bundleName, userLocale);
    String msg = MessageFormat.format(rb.getString("resetPassMail.message"), (Object[]) obj);
    String subject = rb.getString("resetSubject.message");
    String[] to = new String[1];
    to[0] = emailAddress;
    String from = rb.getString("fromAddress.label");
    String charset = g11nSettings.getDefaultCharsetForLocale(userLocale);
    AMSendMail sendMail = new AMSendMail();
    sendMail.postMail(to, subject, msg, from, charset);
}
Also used : AMSendMail(com.iplanet.am.util.AMSendMail) ResourceBundle(java.util.ResourceBundle)

Example 54 with ResourceBundle

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

the class ResourceBundleTest method addResourceBundle.

@Parameters({ "bundle-name", "bundle-file-name", "locale" })
@Test(groups = { "cli-resource-bundle", "add-res-bundle" })
public void addResourceBundle(String bundleName, String fileName, String locale) throws CLIException, SSOException {
    entering("addResourceBundle", null);
    String[] args = (locale.length() == 0) ? new String[5] : new String[7];
    args[0] = "add-res-bundle";
    args[1] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.RESOURCE_BUNDLE_NAME;
    args[2] = bundleName;
    args[3] = CLIConstants.PREFIX_ARGUMENT_LONG + AddResourceBundle.ARGUMENT_RESOURCE_BUNDLE_FILE_NAME;
    args[4] = fileName;
    if (locale.length() > 0) {
        args[5] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.RESOURCE_BUNDLE_LOCALE;
        args[6] = locale;
    }
    CLIRequest req = new CLIRequest(null, args, getAdminSSOToken());
    cmdManager.addToRequestQueue(req);
    cmdManager.serviceRequestQueue();
    ResourceBundle res = (locale.length() == 0) ? ISResourceBundle.getResourceBundle(getAdminSSOToken(), bundleName, (String) null) : ISResourceBundle.getResourceBundle(getAdminSSOToken(), bundleName, locale);
    assert (res != null);
    exiting("addResourceBundle");
}
Also used : ISResourceBundle(com.sun.identity.common.ISResourceBundle) ResourceBundle(java.util.ResourceBundle) Parameters(org.testng.annotations.Parameters) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 55 with ResourceBundle

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

the class ResourceBundleTest method removeResourceBundle.

@Parameters({ "bundle-name", "locale" })
@Test(groups = { "cli-resource-bundle", "remove-res-bundle" }, dependsOnMethods = { "getResourceBundle" })
public void removeResourceBundle(String bundleName, String locale) throws CLIException, SSOException {
    entering("removeResourceBundle", null);
    String[] args = (locale.length() == 0) ? new String[3] : new String[5];
    args[0] = "remove-res-bundle";
    args[1] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.RESOURCE_BUNDLE_NAME;
    args[2] = bundleName;
    if (locale.length() > 0) {
        args[3] = CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.RESOURCE_BUNDLE_LOCALE;
        args[4] = locale;
    }
    CLIRequest req = new CLIRequest(null, args, getAdminSSOToken());
    cmdManager.addToRequestQueue(req);
    cmdManager.serviceRequestQueue();
    try {
        ResourceBundle res = (locale.length() == 0) ? ISResourceBundle.getResourceBundle(getAdminSSOToken(), bundleName, (String) null) : ISResourceBundle.getResourceBundle(getAdminSSOToken(), bundleName, locale);
        assert (res.getLocale() == null);
    } catch (MissingResourceException e) {
    //Ignored
    }
    if (!locale.isEmpty()) {
        //clean up the default resourcebundle too, after removing the JP version
        removeResourceBundle(bundleName, "");
    }
    exiting("removeResourceBundle");
}
Also used : MissingResourceException(java.util.MissingResourceException) ISResourceBundle(com.sun.identity.common.ISResourceBundle) ResourceBundle(java.util.ResourceBundle) Parameters(org.testng.annotations.Parameters) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Aggregations

ResourceBundle (java.util.ResourceBundle)1189 Locale (java.util.Locale)180 MissingResourceException (java.util.MissingResourceException)150 Test (org.junit.Test)100 ArrayList (java.util.ArrayList)71 HashMap (java.util.HashMap)70 IOException (java.io.IOException)67 PropertyResourceBundle (java.util.PropertyResourceBundle)56 URL (java.net.URL)48 File (java.io.File)47 Map (java.util.Map)45 InputStream (java.io.InputStream)43 Enumeration (java.util.Enumeration)34 HashSet (java.util.HashSet)30 Test (org.junit.jupiter.api.Test)30 ActionMessage (org.apache.struts.action.ActionMessage)29 MessageFormat (java.text.MessageFormat)28 ListResourceBundle (java.util.ListResourceBundle)28 Set (java.util.Set)26 Preferences (java.util.prefs.Preferences)21