if(WebloggerRuntimeConfig.getBooleanProperty("themes.customtheme.allowed")) {
// do theme import if necessary
SharedTheme importTheme = null;
if(isImportTheme() && !StringUtils.isEmpty(getImportThemeId())) try {
ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
importTheme = themeMgr.getTheme(getImportThemeId());
themeMgr.importTheme(getActionWeblog(), importTheme);
} catch(WebloggerException re) {
log.error("Error customizing theme for weblog - "+getActionWeblog().getHandle(), re);
// TODO: i18n
addError("Error importing theme");
}
if(!hasActionErrors()) try {
weblog.setEditorTheme(WeblogTheme.CUSTOM);
log.debug("Saving custom theme for weblog "+weblog.getHandle());
// save updated weblog and flush
UserManager userMgr = WebloggerFactory.getWeblogger().getUserManager();
userMgr.saveWebsite(weblog);
WebloggerFactory.getWeblogger().flush();
// make sure to flush the page cache so ppl can see the change
CacheManager.invalidate(weblog);
// TODO: i18n
addMessage("Successfully set theme to - "+WeblogTheme.CUSTOM);
if(importTheme != null) {
addMessage("Successfully copied templates from theme - "+importTheme.getName());
}
// reset import theme options
setImportTheme(false);
setImportThemeId(null);
} catch(WebloggerException re) {
log.error("Error saving weblog - "+getActionWeblog().getHandle(), re);
addError("Error setting theme");
}
} else {
// TODO: i18n
addError("Sorry, custom themes are not allowed");
}
// we are dealing with a shared theme scenario
} else if("shared".equals(getThemeType())) {
// make sure theme is valid and enabled
Theme newTheme = null;
if(getThemeId() == null) {
// TODO: i18n
addError("No theme specified");
} else {
try {
ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
newTheme = themeMgr.getTheme(getThemeId());
if(!newTheme.isEnabled()) {
// TODO: i18n
addError("Theme not enabled");
}