use of com.opensymphony.xwork2.TextProvider in project onebusaway-application-modules by camsys.
the class ResourceServiceImpl method getMessagesResourceAsSourceUrl.
private URL getMessagesResourceAsSourceUrl(String resourceName, LocaleProvider localeProvider) {
int index = resourceName.indexOf('=');
if (index == -1)
throw new IllegalStateException("invalid resource messages specifier: " + resourceName);
String messagesPrefix = resourceName.substring(0, index);
String messagesResourceClassName = resourceName.substring(index + 1);
Class<?> messagesResourceClass = null;
try {
messagesResourceClass = Class.forName(messagesResourceClassName);
} catch (Throwable ex) {
throw new IllegalStateException("error loading messages resource class " + messagesResourceClassName, ex);
}
TextProvider provider = _textProviderFactory.createInstance(messagesResourceClass, localeProvider);
ResourceBundle bundle = provider.getTexts();
Map<String, String> resourceMapping = new HashMap<String, String>();
for (Enumeration<String> en = bundle.getKeys(); en.hasMoreElements(); ) {
String key = en.nextElement();
String value = bundle.getString(key);
resourceMapping.put(key, value);
}
try {
File file = getOutputFile(PREFIX_MESSAGES + messagesPrefix + ".js");
PrintWriter out = new PrintWriter(file);
JSONObject obj = new JSONObject(resourceMapping);
out.println("var OBA = window.OBA || {};");
out.println("if(!OBA.Resources) { OBA.Resources = {}; }");
out.println("OBA.Resources." + messagesPrefix + " = " + obj.toString() + ";");
out.close();
return getFileAsUrl(file);
} catch (IOException ex) {
throw new IllegalStateException("error loading resources", ex);
}
}
use of com.opensymphony.xwork2.TextProvider in project onebusaway-application-modules by camsys.
the class MessageComponent method end.
@Override
public boolean end(Writer writer, String body) {
if (_key != null) {
ValueStack stack = getStack();
CompoundRoot root = stack.getRoot();
TextProvider textProvider = null;
for (Object obj : root) {
if (obj instanceof TextProvider) {
textProvider = (TextProvider) obj;
break;
}
}
if (textProvider != null) {
String message = textProvider.getText(_key, _arguments);
if (message != null) {
try {
writer.write(message);
} catch (IOException e) {
LOG.error("Could not write out tag", e);
}
}
}
}
return super.end(writer, "");
}
use of com.opensymphony.xwork2.TextProvider in project onebusaway-application-modules by camsys.
the class ResourceBundleSupport method getLocaleMap.
public static Map<String, String> getLocaleMap(LocaleProvider localeProvider, Class<?> resourceType) {
TextProviderFactory factory = new TextProviderFactory();
TextProvider provider = factory.createInstance(resourceType, localeProvider);
ResourceBundle bundle = provider.getTexts();
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;
}
Aggregations