use of com.opensymphony.xwork2.LocaleProvider 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.LocaleProvider in project onebusaway-application-modules by camsys.
the class ResourceServiceImpl method getLocalResourceForExternalId.
@Override
public Resource getLocalResourceForExternalId(String externalId, Locale locale) {
Resource resource = _resourceEntriesByExternalId.get(externalId);
if (resource == null) {
/**
* In case the resource has not been first requested as a resource(url)
* first
*/
String resourcePath = getExternalIdAsResourcePath(externalId);
if (resourcePath != null) {
LocaleProvider localeProvider = new LocaleProviderImpl(locale);
/**
* First we see if this is a resource identified by id
*/
if (_resourcePathsById.containsKey(resourcePath)) {
List<String> paths = _resourcePathsById.get(resourcePath);
resource = getResourceForPaths(resourcePath, paths, localeProvider);
}
if (resource == null)
resource = getResourceForPath(resourcePath, localeProvider, null);
}
}
if (resource == null) {
_log.warn("resource not found for external id: " + externalId);
return null;
}
return resource;
}
use of com.opensymphony.xwork2.LocaleProvider 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;
}
use of com.opensymphony.xwork2.LocaleProvider in project onebusaway-application-modules by camsys.
the class ResourceServiceImpl method getExternalUrlForResources.
@Override
public String getExternalUrlForResources(String resourceId, List<String> resourcePaths, Locale locale) {
LocaleProvider localeProvider = new LocaleProviderImpl(locale);
Resource resource = getResourceForPaths(resourceId, resourcePaths, localeProvider);
if (resource == null) {
_log.warn("resource not found: " + resourceId);
return null;
}
if (_debug)
refreshResource(resource);
return resource.getExternalUrl();
}
use of com.opensymphony.xwork2.LocaleProvider in project onebusaway-application-modules by camsys.
the class ResourceServiceImpl method getExternalUrlForResource.
/**
**
* {@link ResourceService} Interface
***
*/
@Override
public String getExternalUrlForResource(String resourcePath, Locale locale) {
LocaleProvider localeProvider = new LocaleProviderImpl(locale);
Resource resource = getResourceForPath(resourcePath, localeProvider, null);
if (resource == null) {
_log.warn("resource not found: " + resourcePath);
return null;
}
if (_debug)
refreshResource(resource);
return resource.getExternalUrl();
}
Aggregations