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);
}
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");
}
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;
}
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;
}
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()));
}
Aggregations