in app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java [123:227]
public String save() {
Weblog weblog = getActionWeblog();
// Are we dealing with a custom theme scenario?
if (WeblogTheme.CUSTOM.equals(getThemeType())) {
// do theme import if requested
if (importTheme) {
try {
ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
if (!StringUtils.isEmpty(selectedThemeId)) {
SharedTheme t = themeMgr.getTheme(selectedThemeId);
// if moving from shared w/custom SS to custom import of same shared theme,
// keep the custom stylesheet.
boolean skipStylesheet = (sharedThemeCustomStylesheet && selectedThemeId.equals(weblog.getEditorTheme()));
themeMgr.importTheme(getActionWeblog(), t, skipStylesheet);
addMessage("themeEditor.setCustomTheme.success", t.getName());
}
} catch (Exception re) {
log.error("Error customizing theme for weblog - "
+ getActionWeblog().getHandle(), re);
addError("generic.error.check.logs");
return execute();
}
}
if (!hasActionErrors()) {
try {
// save updated weblog and flush
weblog.setEditorTheme(WeblogTheme.CUSTOM);
WebloggerFactory.getWeblogger().getWeblogManager().saveWeblog(weblog);
WebloggerFactory.getWeblogger().flush();
// make sure to flush the page cache so ppl can see the change
CacheManager.invalidate(weblog);
addMessage("themeEditor.setTheme.success", WeblogTheme.CUSTOM);
addMessage("themeEditor.setCustomTheme.instructions");
} catch (WebloggerException re) {
log.error("Error saving weblog - "
+ getActionWeblog().getHandle(), re);
addError("generic.error.check.logs");
}
}
} else if ("shared".equals(getThemeType())) {
// make sure theme is valid and enabled
Theme newTheme = null;
try {
ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
newTheme = themeMgr.getTheme(selectedThemeId);
} catch (Exception ex) {
log.warn(ex);
addError("Theme not found");
}
if (!hasActionErrors()) {
try {
String originalTheme = weblog.getEditorTheme();
WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
// Remove old style sheet
if (!originalTheme.equals(selectedThemeId) && getActionWeblog().getTheme().getStylesheet() != null) {
WeblogTemplate stylesheet = mgr.getTemplateByAction(getActionWeblog(),
ComponentType.STYLESHEET);
if (stylesheet != null) {
// Remove template and its renditions
mgr.removeTemplate(stylesheet);
sharedThemeCustomStylesheet = false;
}
}
weblog.setEditorTheme(selectedThemeId);
log.debug("Saving theme " + selectedThemeId + " for weblog "
+ weblog.getHandle());
// save updated weblog and flush
WebloggerFactory.getWeblogger().getWeblogManager()
.saveWeblog(weblog);
WebloggerFactory.getWeblogger().flush();
// make sure to flush the page cache so ppl can see the change
CacheManager.invalidate(weblog);
// Theme set to..
if (!originalTheme.equals(selectedThemeId)) {
addMessage("themeEditor.setTheme.success", newTheme.getName());
}
} catch (WebloggerException re) {
log.error("Error saving weblog - " + getActionWeblog().getHandle(), re);
addError("generic.error.check.logs");
}
}
}
return execute();
}