You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by gm...@apache.org on 2014/09/04 21:32:04 UTC
svn commit: r1622537 - in /roller/trunk/app/src/main:
java/org/apache/roller/weblogger/business/themes/
java/org/apache/roller/weblogger/ui/struts2/editor/
webapp/WEB-INF/jsps/editor/
Author: gmazza
Date: Thu Sep 4 19:32:04 2014
New Revision: 1622537
URL: http://svn.apache.org/r1622537
Log:
ROL-2052 fix for custom stylesheets not getting updated correctly when user switches between shared and custom themes.
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java?rev=1622537&r1=1622536&r2=1622537&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java Thu Sep 4 19:32:04 2014
@@ -76,11 +76,16 @@ public interface ThemeManager {
* The weblog (website) to import the theme into.
* @param theme
* The theme that should be imported.
+ * @param skipStylesheet
+ * Whether the stylesheet should be omitted from the import. Useful
+ * when moving from a shared theme with a custom stylesheet to a custom
+ * theme importing the same shared theme, as it allows the user's custom
+ * stylesheet to remain.
*
* @throws WebloggerException
* If there is some kind of error in saving.
*/
- void importTheme(Weblog website, SharedTheme theme)
+ void importTheme(Weblog website, SharedTheme theme, boolean skipStylesheet)
throws WebloggerException;
/**
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java?rev=1622537&r1=1622536&r2=1622537&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java Thu Sep 4 19:32:04 2014
@@ -129,7 +129,7 @@ public class ThemeManagerImpl implements
public SharedTheme getTheme(String id) throws WebloggerException {
// try to lookup theme from library
- SharedTheme theme = (SharedTheme) this.themes.get(id);
+ SharedTheme theme = this.themes.get(id);
// no theme? throw exception.
if (theme == null) {
@@ -186,9 +186,9 @@ public class ThemeManagerImpl implements
/**
* @see org.apache.roller.weblogger.business.themes.ThemeManager#importTheme(Weblog,
- * SharedTheme)
+ * SharedTheme, boolean)
*/
- public void importTheme(Weblog weblog, SharedTheme theme)
+ public void importTheme(Weblog weblog, SharedTheme theme, boolean skipStylesheet)
throws WebloggerException {
log.debug("Importing theme [" + theme.getName() + "] to weblog ["
@@ -199,8 +199,7 @@ public class ThemeManagerImpl implements
MediaFileDirectory root = fileMgr.getDefaultMediaFileDirectory(weblog);
if (root == null) {
- log.warn("Weblog " + weblog.getHandle()
- + " does not have a root MediaFile directory");
+ log.warn("Weblog " + weblog.getHandle() + " does not have a root MediaFile directory");
}
Set<ComponentType> importedActionTemplates = new HashSet<ComponentType>();
@@ -228,14 +227,8 @@ public class ThemeManagerImpl implements
newTmpl = true;
}
- // TODO: fix conflict situation
- // it's possible that someone has defined a theme template which
- // matches 2 existing templates, 1 by action, the other by name
-
- // update template attributes
- // NOTE: we don't want to copy the template data for an existing
- // stylesheet
- if (newTmpl || !themeTemplate.equals(stylesheetTemplate)) {
+ // update template attributes except leave existing custom stylesheets as-is
+ if (!themeTemplate.equals(stylesheetTemplate) || !skipStylesheet) {
template.setAction(themeTemplate.getAction());
template.setName(themeTemplate.getName());
template.setDescription(themeTemplate.getDescription());
@@ -247,33 +240,32 @@ public class ThemeManagerImpl implements
// save it
wmgr.saveTemplate(template);
- }
- // create weblog template code objects and save them
- for (RenditionType type : RenditionType.values()) {
+ // create weblog template code objects and save them
+ for (RenditionType type : RenditionType.values()) {
- // See if we already have some code for this template already (eg previous theme)
- CustomTemplateRendition weblogTemplateCode = template.getTemplateRendition(type);
+ // See if we already have some code for this template already (eg previous theme)
+ CustomTemplateRendition weblogTemplateCode = template.getTemplateRendition(type);
- // Get the template for the new theme
- TemplateRendition templateCode = themeTemplate.getTemplateRendition(type);
- if (templateCode != null) {
-
- // Check for existing template
- if (weblogTemplateCode == null) {
- // Does not exist so create a new one
- weblogTemplateCode = new CustomTemplateRendition(
- template, type);
- }
- weblogTemplateCode.setType(type);
- weblogTemplateCode.setTemplate(templateCode.getTemplate());
- weblogTemplateCode.setTemplateLanguage(templateCode
- .getTemplateLanguage());
- WebloggerFactory.getWeblogger().getWeblogManager()
- .saveTemplateRendition(weblogTemplateCode);
- }
+ // Get the template for the new theme
+ TemplateRendition templateCode = themeTemplate.getTemplateRendition(type);
+ if (templateCode != null) {
+
+ // Check for existing template
+ if (weblogTemplateCode == null) {
+ // Does not exist so create a new one
+ weblogTemplateCode = new CustomTemplateRendition(template, type);
+ }
+ weblogTemplateCode.setType(type);
+ weblogTemplateCode.setTemplate(templateCode.getTemplate());
+ weblogTemplateCode.setTemplateLanguage(templateCode
+ .getTemplateLanguage());
+ WebloggerFactory.getWeblogger().getWeblogManager()
+ .saveTemplateRendition(weblogTemplateCode);
+ }
- }
+ }
+ }
}
// now, see if the weblog has left over non-custom action templates that
@@ -286,8 +278,7 @@ public class ThemeManagerImpl implements
if (!importedActionTemplates.contains(action)) {
WeblogTemplate toDelete = wmgr.getTemplateByAction(weblog, action);
if (toDelete != null) {
- log.debug("Removing stale action template "
- + toDelete.getId());
+ log.debug("Removing stale action template " + toDelete.getId());
wmgr.removeTemplate(toDelete);
}
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java?rev=1622537&r1=1622536&r2=1622537&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java Thu Sep 4 19:32:04 2014
@@ -62,8 +62,8 @@ public class ThemeEdit extends UIAction
// a potentially new selected theme
private String selectedThemeId = null;
- // Do we have a custom stylesheet already
- private boolean customStylesheet = false;
+ // Are we using a shared theme with a custom stylesheet
+ private boolean sharedThemeCustomStylesheet = false;
public ThemeEdit() {
this.actionName = "themeEdit";
@@ -75,21 +75,8 @@ public class ThemeEdit extends UIAction
ThemeManager themeMgr = WebloggerFactory.getWeblogger()
.getThemeManager();
themes = themeMgr.getEnabledThemesList();
- }
-
- public String execute() {
-
- // set theme to current value
- if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
- setThemeId(null);
- setSelectedThemeId(null);
- setImportTheme(false);
- } else {
- setThemeId(getActionWeblog().getTheme().getId());
- setSelectedThemeId(getThemeId());
- }
- // See if we have a custom style sheet from a custom theme.
+ // See if we're using a shared theme with a custom template
try {
if (!WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())
&& getActionWeblog().getTheme().getStylesheet() != null) {
@@ -102,13 +89,26 @@ public class ThemeEdit extends UIAction
getActionWeblog().getTheme().getStylesheet()
.getLink());
if (override != null) {
- customStylesheet = true;
+ sharedThemeCustomStylesheet = true;
}
}
} catch (WebloggerException ex) {
log.error("Error looking up stylesheet on weblog - "
+ getActionWeblog().getHandle(), ex);
}
+ }
+
+ public String execute() {
+
+ // set theme to current value
+ if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
+ setThemeId(null);
+ setSelectedThemeId(null);
+ setImportTheme(false);
+ } else {
+ setThemeId(getActionWeblog().getTheme().getId());
+ setSelectedThemeId(getThemeId());
+ }
return INPUT;
}
@@ -123,41 +123,37 @@ public class ThemeEdit extends UIAction
// Are we dealing with a custom theme scenario?
if (WeblogTheme.CUSTOM.equals(getThemeType())) {
- // do theme import if necessary
- SharedTheme t = null;
-
- try {
- ThemeManager themeMgr = WebloggerFactory.getWeblogger()
- .getThemeManager();
- if (importTheme && !StringUtils.isEmpty(selectedThemeId)) {
- t = themeMgr.getTheme(selectedThemeId);
- themeMgr.importTheme(getActionWeblog(), t);
+ // 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();
}
- } catch (Exception re) {
- log.error("Error customizing theme for weblog - "
- + getActionWeblog().getHandle(), re);
- addError("generic.error.check.logs");
- return execute();
}
if (!hasActionErrors()) {
try {
- weblog.setEditorTheme(WeblogTheme.CUSTOM);
- log.debug("Saving custom theme for weblog "
- + weblog.getHandle());
-
// save updated weblog and flush
- WebloggerFactory.getWeblogger().getWeblogManager()
- .saveWeblog(weblog);
+ 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);
- if (importTheme && t != null) {
- addMessage("themeEditor.setCustomTheme.success", t.getName());
- }
addMessage("themeEditor.setCustomTheme.instructions");
} catch (WebloggerException re) {
@@ -166,48 +162,35 @@ public class ThemeEdit extends UIAction
addError("generic.error.check.logs");
}
}
+
} else if ("shared".equals(getThemeType())) {
// make sure theme is valid and enabled
Theme newTheme = null;
- if (selectedThemeId == null) {
- addError("No theme specified");
- } else {
- try {
- ThemeManager themeMgr = WebloggerFactory.getWeblogger()
- .getThemeManager();
- newTheme = themeMgr.getTheme(selectedThemeId);
- if (!newTheme.isEnabled()) {
- addError("Theme not enabled");
- }
-
- } catch (Exception ex) {
- log.warn(ex);
- addError("Theme not found");
- }
+ 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();
+ WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
// Remove old style sheet
- if (!WeblogTheme.CUSTOM.equals(originalTheme)
- && !originalTheme.equals(selectedThemeId)
- && getActionWeblog().getTheme().getStylesheet() != null) {
-
- WeblogTemplate stylesheet = mgr.getTemplateByLink(
- getActionWeblog(), getActionWeblog().getTheme()
- .getStylesheet().getLink());
+ 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;
}
}
@@ -230,16 +213,10 @@ public class ThemeEdit extends UIAction
}
} catch (WebloggerException re) {
- log.error("Error saving weblog - "
- + getActionWeblog().getHandle(), re);
- addError("Error setting theme");
+ log.error("Error saving weblog - " + getActionWeblog().getHandle(), re);
+ addError("generic.error.check.logs");
}
}
-
- // unknown theme scenario, error
- } else {
- // invalid theme type
- addError("no valid theme type submitted");
}
return execute();
@@ -300,12 +277,12 @@ public class ThemeEdit extends UIAction
}
/**
- * Checks if we have a custom stylesheet.
+ * Checks if we are using a shared theme with a custom stylesheet.
*
- * @return true, if checks if is custom stylesheet
+ * @return true, if using a shared theme with a custom stylesheet; false otherwise.
*/
- public boolean isCustomStylesheet() {
- return customStylesheet;
+ public boolean isSharedThemeCustomStylesheet() {
+ return sharedThemeCustomStylesheet;
}
}
Modified: roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp?rev=1622537&r1=1622536&r2=1622537&view=diff
==============================================================================
--- roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp (original)
+++ roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp Thu Sep 4 19:32:04 2014
@@ -78,7 +78,7 @@ function updateThemeChooser(selected) {
<s:text name="themeEditor.yourCurrentTheme" />:
<b><s:property value="actionWeblog.theme.name"/></b>
<%-- The type of stylesheet we are using --%>
- <s:if test="%{customStylesheet}">
+ <s:if test="%{sharedThemeCustomStylesheet}">
<s:text name="themeEditor.yourCustomStylesheet" />
</s:if>
<s:else>