use of org.jaffa.config.ApplicationResourceLoader in project jaffa-framework by jaffa-projects.
the class LabelEditorComponent method performSave.
/**
* This will perform the following tasks.
* - Add an entry for each label having an override value, to the ApplicationResources.override file.
* - Remove all entries from the ApplicationResources.override file, for which the override value is blank
* - Migrate all changes to the ApplicationResources.properties file by invoking InitApp.generateApplicationResources()
* - Flush the struts properties cache by invoking the flushCache() method on the MessageResources, provided its an instance of 'org.jaffa.util.PropertyMessageResources'
* @param request The request we are processing.
* @param messageResources The MessageResources object, which will be flushed, if its an instance of 'org.jaffa.util.PropertyMessageResources'.
* @throws FrameworkException if any error occurs.
*/
protected void performSave(HttpServletRequest request, MessageResources messageResources) throws FrameworkException {
String applicationResourcesOverrideLocation = (String) Config.getProperty(Config.PROP_APPLICATION_RESOURCES_OVERRIDE_LOCATION, null);
try {
// load the ApplicationResources.override file
Properties applicationResourcesOverrideProperties = loadPropertiesFromFile(applicationResourcesOverrideLocation, true);
ApplicationResourceLoader appResourceLoader = ApplicationResourceLoader.getInstance();
String localeKey = localeKey(LocaleContext.getLocale());
// Either update or remove a property
for (Iterator itr = m_labels.keySet().iterator(); itr.hasNext(); ) {
String label = (String) itr.next();
Map map = (Map) m_labels.get(label);
String override = (String) map.get(OVERRIDE);
if (override != null) {
// setting the override label into override file
applicationResourcesOverrideProperties.setProperty(label, override);
// Applying the changes into ApplicationResources in memory
appResourceLoader.getLocaleProperties(localeKey).setProperty(label, override);
} else {
// removing the override from file if there is any
applicationResourcesOverrideProperties.remove(label);
// remove it from memory
if (ApplicationResourceLoader.getApplicationResourcesManager().getApplicationResourcesLocaleRepository().query(localeKey) != null) {
appResourceLoader.getApplicationResourcesOverride(localeKey).remove(label);
} else {
appResourceLoader.getApplicationResourcesOverride(null);
}
// reverting/leaving the default value if the override removed.
appResourceLoader.getLocaleProperties(LocaleContext.getLocale().toString()).setProperty(label, appResourceLoader.getApplicationResourcesDefault().getProperty(label));
}
}
// Sort the ApplicationResources.override file
if (applicationResourcesOverrideProperties instanceof ListProperties)
((ListProperties) applicationResourcesOverrideProperties).sort();
// Now save the ApplicationResources.override file into user data directory
storePropertiesToFile(applicationResourcesOverrideProperties, applicationResourcesOverrideLocation);
// Flush the struts properties cache by invoking the flushCache() method on the MessageResources, provided its an instance of 'org.jaffa.util.PropertyMessageResources'
if (messageResources != null && messageResources instanceof PropertyMessageResources) {
((PropertyMessageResources) messageResources).flushCache();
if (log.isDebugEnabled())
log.debug("Flushed the struts message cache");
} else {
if (log.isDebugEnabled())
log.debug("The struts message cache has not been implemented using the org.jaffa.util.PropertyMessageResources class. Reload the webapp to see the changes to the labels.");
}
clearCacheAndRefreshMenu(request);
} catch (IOException e) {
String str = "Exception thrown while storing the override values";
log.error(str, e);
throw new LabelEditorException(LabelEditorException.WRITE_FAILED, null, e);
}
}
use of org.jaffa.config.ApplicationResourceLoader in project jaffa-framework by jaffa-projects.
the class LabelHelper method performSave.
/**
* This will perform the following tasks.
* - Add an entry for each label having an override value, to the ApplicationResources.override file.
* - Remove all entries from the ApplicationResources.override file, for which the override value is blank
* - Migrate all changes to the ApplicationResources.properties file by invoking InitApp.generateApplicationResources()
* - Flush the struts properties cache by invoking the flushCache() method on the MessageResources, provided its an instance of 'org.jaffa.util.PropertyMessageResources'
* @param request The request we are processing.
* @param messageResources The MessageResources object, which will be flushed, if its an instance of 'org.jaffa.util.PropertyMessageResources'.
* @throws FrameworkException if any error occurs.
*/
protected static void performSave(Map labels) throws FrameworkException {
String applicationResourcesOverrideLocation = (String) Config.getProperty(Config.PROP_APPLICATION_RESOURCES_OVERRIDE_LOCATION, null);
try {
// load the ApplicationResources.override file
Properties applicationResourcesOverrideProperties = loadPropertiesFromFile(applicationResourcesOverrideLocation, true);
ApplicationResourceLoader appResourceLoader = ApplicationResourceLoader.getInstance();
// Either update or remove a property
for (Iterator itr = labels.keySet().iterator(); itr.hasNext(); ) {
String label = (String) itr.next();
Map map = (Map) labels.get(label);
String override = (String) map.get(OVERRIDE);
if (override != null) {
// setting the override label into override file
applicationResourcesOverrideProperties.setProperty(label, override);
// Applying the changes into ApplicationResources in memory
appResourceLoader.getLocaleProperties(ApplicationResourceLoader.DEFAULT_PROP_LOCALE_KEY).setProperty(label, override);
} else {
// removing the override from file if there is any
applicationResourcesOverrideProperties.remove(label);
// reverting/leaving the default value if the override removed.
appResourceLoader.getLocaleProperties(ApplicationResourceLoader.DEFAULT_PROP_LOCALE_KEY).setProperty(label, appResourceLoader.getApplicationResourcesDefault().getProperty(label));
}
}
// Sort the ApplicationResources.override file
if (applicationResourcesOverrideProperties instanceof ListProperties)
((ListProperties) applicationResourcesOverrideProperties).sort();
// Now save the ApplicationResources.override file
storePropertiesToFile(applicationResourcesOverrideProperties, applicationResourcesOverrideLocation);
// Migrate all changes to the ApplicationResources.properties file by invoking InitApp.generateApplicationResources()
// InitApp.generateApplicationResources();
((PropertyMessageResources) PropertyMessageResourcesFactory.getDefaultMessageResources()).flushCache();
if (log.isDebugEnabled())
log.debug("Flushed the struts message cache");
} catch (IOException e) {
throw new LabelException(LabelException.WRITE_ERROR);
}
}
Aggregations