Search in sources :

Example 1 with LocalizedTextProvider

use of com.opensymphony.xwork2.LocalizedTextProvider in project struts by apache.

the class StrutsLocalizedTextProviderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
    container.inject(provider);
    loadConfigurationProviders(provider);
    localizedTextProvider = container.getInstance(LocalizedTextProvider.class);
    ActionContext.getContext().withLocale(Locale.US);
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) LocalizedTextProvider(com.opensymphony.xwork2.LocalizedTextProvider)

Example 2 with LocalizedTextProvider

use of com.opensymphony.xwork2.LocalizedTextProvider in project struts by apache.

the class DispatcherTest method testDefaultResurceBundlePropertyLoaded.

public void testDefaultResurceBundlePropertyLoaded() throws Exception {
    LocalizedTextProvider localizedTextProvider = container.getInstance(LocalizedTextProvider.class);
    // some i18n messages from xwork-messages.properties
    assertEquals(localizedTextProvider.findDefaultText("xwork.error.action.execution", Locale.US), "Error during Action invocation");
    // some i18n messages from struts-messages.properties
    assertEquals(localizedTextProvider.findDefaultText("struts.messages.error.uploading", Locale.US, new Object[] { "some error messages" }), "Error uploading: some error messages");
}
Also used : LocalizedTextProvider(com.opensymphony.xwork2.LocalizedTextProvider)

Example 3 with LocalizedTextProvider

use of com.opensymphony.xwork2.LocalizedTextProvider in project onebusaway-application-modules by camsys.

the class ResourceBundleSupport method getLocaleMap.

public static Map<String, String> getLocaleMap(LocaleProvider localeProvider, Class<?> resourceType) {
    StrutsLocalizedTextProvider localizedTextProvider = new StrutsLocalizedTextProvider();
    ResourceBundle bundle = localizedTextProvider.findResourceBundle(resourceType.getName(), Locale.getDefault());
    Map<String, String> m = new LinkedHashMap<String, String>();
    for (Enumeration<String> en = bundle.getKeys(); en.hasMoreElements(); ) {
        String key = en.nextElement();
        String value = bundle.getString(key);
        m.put(key, value);
    }
    return m;
}
Also used : StrutsLocalizedTextProvider(com.opensymphony.xwork2.util.StrutsLocalizedTextProvider) ResourceBundle(java.util.ResourceBundle) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with LocalizedTextProvider

use of com.opensymphony.xwork2.LocalizedTextProvider in project struts by apache.

the class TokenHelper method validToken.

/**
 * Checks for a valid transaction token in the current request params. If a valid token is found, it is
 * removed so the it is not valid again.
 *
 * @return false if there was no token set into the params (check by looking for {@link #TOKEN_NAME_FIELD}), true if a valid token is found
 */
public static boolean validToken() {
    String tokenName = getTokenName();
    if (tokenName == null) {
        LOG.debug("No token name found -> Invalid token ");
        return false;
    }
    String token = getToken(tokenName);
    if (token == null) {
        LOG.debug("No token found for token name {} -> Invalid token ", tokenName);
        return false;
    }
    Map session = ActionContext.getContext().getSession();
    String tokenSessionName = buildTokenSessionAttributeName(tokenName);
    String sessionToken = (String) session.get(tokenSessionName);
    if (!token.equals(sessionToken)) {
        if (LOG.isWarnEnabled()) {
            LocalizedTextProvider localizedTextProvider = ActionContext.getContext().getContainer().getInstance(LocalizedTextProvider.class);
            LOG.warn(localizedTextProvider.findText(TokenHelper.class, "struts.internal.invalid.token", ActionContext.getContext().getLocale(), "Form token {0} does not match the session token {1}.", new Object[] { token, sessionToken }));
        }
        return false;
    }
    // remove the token so it won't be used again
    session.remove(tokenSessionName);
    return true;
}
Also used : LocalizedTextProvider(com.opensymphony.xwork2.LocalizedTextProvider) Map(java.util.Map)

Example 5 with LocalizedTextProvider

use of com.opensymphony.xwork2.LocalizedTextProvider in project struts by apache.

the class SettingsTest method testDefaultResourceBundlesLoaded.

public void testDefaultResourceBundlesLoaded() {
    Settings settings = new DefaultSettings();
    LocalizedTextProvider localizedTextProvider = container.getInstance(LocalizedTextProvider.class);
    assertEquals("testmessages,testmessages2", settings.get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES));
    assertEquals("This is a test message", localizedTextProvider.findDefaultText("default.testmessage", Locale.getDefault()));
    assertEquals("This is another test message", localizedTextProvider.findDefaultText("default.testmessage2", Locale.getDefault()));
}
Also used : LocalizedTextProvider(com.opensymphony.xwork2.LocalizedTextProvider)

Aggregations

LocalizedTextProvider (com.opensymphony.xwork2.LocalizedTextProvider)5 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)1 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)1 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)1 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)1 StrutsLocalizedTextProvider (com.opensymphony.xwork2.util.StrutsLocalizedTextProvider)1 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ResourceBundle (java.util.ResourceBundle)1 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)1