Author: ghuber
Date: Wed Feb 1 22:03:34 2012
New Revision: 1239357
URL: http://svn.apache.org/viewvc?rev=1239357&view=rev
Log:
Template testing mods.....
Modified:
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
Modified:
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
URL:
http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java?rev=1239357&r1=1239356&r2=1239357&view=diff
==============================================================================
---
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
(original)
+++
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
Wed Feb 1 22:03:34 2012
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
@@ -130,8 +131,10 @@ public class StylesheetEdit extends UIAc
setTemplate(stylesheetTmpl);
}
+ // See if we have a custom style sheet from a
custom theme.
if (!WeblogTheme.CUSTOM.equals(getActionWeblog()
- .getEditorTheme())) {
+ .getEditorTheme())
+ &&
getActionWeblog().getTheme().getStylesheet() != null) {
ThemeTemplate override =
WebloggerFactory
.getWeblogger()
Modified:
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
URL:
http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java?rev=1239357&r1=1239356&r2=1239357&view=diff
==============================================================================
---
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
(original)
+++
roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
Wed Feb 1 22:03:34 2012
@@ -37,258 +37,275 @@ import org.apache.roller.weblogger.pojos
import org.apache.roller.weblogger.ui.struts2.util.UIAction;
import org.apache.roller.weblogger.util.cache.CacheManager;
-
/**
* Action for controlling theme selection.
*/
public class ThemeEdit extends UIAction {
-
- private static Log log = LogFactory.getLog(Templates.class);
-
- // list of available themes
- private List themes = Collections.EMPTY_LIST;
-
- // type of theme desired, either 'shared' or 'custom'
- private String themeType = null;
-
- // the chosen shared theme id
- private String themeId = null;
-
- // import the selected theme to the action weblog
- private boolean importTheme = false;
-
- // the chosen import theme id
- private String importThemeId = null;
-
+
+ private static Log log = LogFactory.getLog(Templates.class);
+
+ // list of available themes
+ private List themes = Collections.EMPTY_LIST;
+
+ // type of theme desired, either 'shared' or 'custom'
+ private String themeType = null;
+
+ // the chosen shared theme id
+ private String themeId = null;
+
+ // import the selected theme to the action weblog
+ private boolean importTheme = false;
+
+ // the chosen import theme id
+ private String importThemeId = null;
+
// Do we have a custom stylesheet already
private boolean customStylesheet = false;
-
- public ThemeEdit() {
- this.actionName = "themeEdit";
- this.desiredMenu = "editor";
- this.pageTitle = "themeEditor.title";
- }
-
-
- public List<String> requiredWeblogPermissionActions() {
- return Collections.singletonList(WeblogPermission.ADMIN);
- }
-
-
- public void myPrepare() {
-
- // See if we have a custom style sheet from a custom theme.
- try {
- if
(WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())
- && StringUtils.isNotEmpty(getActionWeblog()
- .getCustomStylesheetPath())) {
- customStylesheet = true;
- } else if (!WeblogTheme.CUSTOM.equals(getActionWeblog()
- .getEditorTheme())) {
-
- ThemeTemplate override =WebloggerFactory.getWeblogger()
-
.getWeblogManager().getPageByLink(getActionWeblog(),
getActionWeblog().getTheme().getStylesheet().getLink());
-
- if(override != null) {
- customStylesheet = true;
- }
- }
- } catch (WebloggerException ex) {
- log.error("Error looking up stylesheet on weblog - "
- + getActionWeblog().getHandle(), ex);
- }
-
- ThemeManager themeMgr =
WebloggerFactory.getWeblogger().getThemeManager();
- setThemes(themeMgr.getEnabledThemesList());
- }
-
-
- public String execute() {
-
- // set theme to current value
- if(WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
- setThemeId(null);
- } else {
- setThemeId(getActionWeblog().getTheme().getId());
- setImportThemeId(getActionWeblog().getTheme().getId());
- }
-
-
if(!WebloggerRuntimeConfig.getBooleanProperty("themes.customtheme.allowed")) {
- return "input-sharedonly";
- } else {
- return INPUT;
- }
- }
-
-
- /**
- * Save new theme configuration.
- */
- public String save() {
-
- Weblog weblog = getActionWeblog();
-
- // we are dealing with a custom theme scenario
- if(WeblogTheme.CUSTOM.equals(getThemeType())) {
-
- // only continue if custom themes are allowed
-
if(WebloggerRuntimeConfig.getBooleanProperty("themes.customtheme.allowed")) {
-
- // do theme import if necessary
- SharedTheme t = null;
- if(isImportTheme() &&
!StringUtils.isEmpty(getImportThemeId())) try {
- ThemeManager themeMgr =
WebloggerFactory.getWeblogger().getThemeManager();
- t = themeMgr.getTheme(getImportThemeId());
- themeMgr.importTheme(getActionWeblog(), t);
- } catch(Exception 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
-
WebloggerFactory.getWeblogger().getWeblogManager().saveWeblog(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 (t != null) {
- addMessage("Successfully copied templates from theme -
" + t.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");
- }
-
- } catch(Exception ex) {
- log.warn(ex);
- // TODO: i18n
- addError("Theme not found");
- }
- }
-
- if(!hasActionErrors()) try {
- weblog.setEditorTheme(getThemeId());
- log.debug("Saving theme "+getThemeId()+" 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);
-
- // TODO: i18n
- addMessage("Successfully set theme to - "+newTheme.getName());
-
- } catch(WebloggerException re) {
- log.error("Error saving weblog -
"+getActionWeblog().getHandle(), re);
- addError("Error setting theme");
- }
-
- // unknown theme scenario, error
- } else {
- // invalid theme type
- // TODO: i18n
- addError("no valid theme type submitted");
- }
-
- return execute();
- }
-
-
- public boolean isCustomTheme() {
- return (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
- }
-
- // has this weblog had a custom theme before?
- public boolean isFirstCustomization() {
- try {
- return
(WebloggerFactory.getWeblogger().getWeblogManager().getPageByAction(getActionWeblog(),
WeblogTemplate.ACTION_WEBLOG) == null);
- } catch (WebloggerException ex) {
- log.error("Error looking up weblog template", ex);
- }
- return false;
- }
-
-
- public List getThemes() {
- return themes;
- }
-
- public void setThemes(List themes) {
- this.themes = themes;
- }
-
- public String getThemeType() {
- return themeType;
- }
-
- public void setThemeType(String themeType) {
- this.themeType = themeType;
- }
-
- public String getThemeId() {
- return themeId;
- }
-
- public void setThemeId(String theme) {
- this.themeId = theme;
- }
-
- public boolean isImportTheme() {
- return importTheme;
- }
-
- public void setImportTheme(boolean importTheme) {
- this.importTheme = importTheme;
- }
-
- public String getImportThemeId() {
- return importThemeId;
- }
-
- public void setImportThemeId(String importThemeId) {
- this.importThemeId = importThemeId;
- }
-
- /**
- * Checks if is custom stylesheet.
+
+ public ThemeEdit() {
+ this.actionName = "themeEdit";
+ this.desiredMenu = "editor";
+ this.pageTitle = "themeEditor.title";
+ }
+
+ public List<String> requiredWeblogPermissionActions() {
+ return Collections.singletonList(WeblogPermission.ADMIN);
+ }
+
+ public void myPrepare() {
+
+ ThemeManager themeMgr = WebloggerFactory.getWeblogger()
+ .getThemeManager();
+ setThemes(themeMgr.getEnabledThemesList());
+ }
+
+ public String execute() {
+
+ // set theme to current value
+ if
(WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
+ setThemeId(null);
+ } else {
+ setThemeId(getActionWeblog().getTheme().getId());
+ setImportThemeId(getActionWeblog().getTheme().getId());
+ }
+
+ // See if we have a custom style sheet from a custom theme.
+ try {
+ if
(!WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())
+ &&
getActionWeblog().getTheme().getStylesheet() != null) {
+
+ ThemeTemplate override = WebloggerFactory
+ .getWeblogger()
+ .getWeblogManager()
+ .getPageByLink(
+
getActionWeblog(),
+
getActionWeblog().getTheme().getStylesheet()
+
.getLink());
+ if (override != null) {
+ customStylesheet = true;
+ }
+ }
+ } catch (WebloggerException ex) {
+ log.error("Error looking up stylesheet on weblog - "
+ + getActionWeblog().getHandle(), ex);
+ }
+
+ if (!WebloggerRuntimeConfig
+
.getBooleanProperty("themes.customtheme.allowed")) {
+ return "input-sharedonly";
+ } else {
+ return INPUT;
+ }
+ }
+
+ /**
+ * Save new theme configuration.
+ */
+ public String save() {
+
+ Weblog weblog = getActionWeblog();
+
+ // we are dealing with a custom theme scenario
+ if (WeblogTheme.CUSTOM.equals(getThemeType())) {
+
+ // only continue if custom themes are allowed
+ if (WebloggerRuntimeConfig
+
.getBooleanProperty("themes.customtheme.allowed")) {
+
+ // do theme import if necessary
+ SharedTheme t = null;
+ if (isImportTheme() &&
!StringUtils.isEmpty(getImportThemeId()))
+ try {
+ ThemeManager themeMgr =
WebloggerFactory.getWeblogger()
+
.getThemeManager();
+ t =
themeMgr.getTheme(getImportThemeId());
+
themeMgr.importTheme(getActionWeblog(), t);
+ } catch (Exception 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
+
WebloggerFactory.getWeblogger().getWeblogManager()
+
.saveWeblog(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 (t != null) {
+
addMessage("Successfully copied templates from theme - "
+ +
t.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");
+ }
+
+ } catch (Exception ex) {
+ log.warn(ex);
+ // TODO: i18n
+ addError("Theme not found");
+ }
+ }
+
+ if (!hasActionErrors())
+ try {
+ weblog.setEditorTheme(getThemeId());
+ log.debug("Saving theme " +
getThemeId() + " 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);
+
+ // TODO: i18n
+ addMessage("Successfully set theme to -
"
+ + newTheme.getName());
+
+ } catch (WebloggerException re) {
+ log.error("Error saving weblog - "
+ +
getActionWeblog().getHandle(), re);
+ addError("Error setting theme");
+ }
+
+ // unknown theme scenario, error
+ } else {
+ // invalid theme type
+ // TODO: i18n
+ addError("no valid theme type submitted");
+ }
+
+ return execute();
+ }
+
+ public boolean isCustomTheme() {
+ return
(WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
+ }
+
+ // has this weblog had a custom theme before?
+ public boolean isFirstCustomization() {
+ try {
+ return (WebloggerFactory
+ .getWeblogger()
+ .getWeblogManager()
+ .getPageByAction(getActionWeblog(),
+
WeblogTemplate.ACTION_WEBLOG) == null);
+ } catch (WebloggerException ex) {
+ log.error("Error looking up weblog template", ex);
+ }
+ return false;
+ }
+
+ public List getThemes() {
+ return themes;
+ }
+
+ public void setThemes(List themes) {
+ this.themes = themes;
+ }
+
+ public String getThemeType() {
+ return themeType;
+ }
+
+ public void setThemeType(String themeType) {
+ this.themeType = themeType;
+ }
+
+ public String getThemeId() {
+ return themeId;
+ }
+
+ public void setThemeId(String theme) {
+ this.themeId = theme;
+ }
+
+ public boolean isImportTheme() {
+ return importTheme;
+ }
+
+ public void setImportTheme(boolean importTheme) {
+ this.importTheme = importTheme;
+ }
+
+ public String getImportThemeId() {
+ return importThemeId;
+ }
+
+ public void setImportThemeId(String importThemeId) {
+ this.importThemeId = importThemeId;
+ }
+
+ /**
+ * Checks if we have a custom stylesheet.
*
* @return true, if checks if is custom stylesheet
*/
@@ -305,5 +322,5 @@ public class ThemeEdit extends UIAction
public void setCustomStylesheet(boolean customStylesheet) {
this.customStylesheet = customStylesheet;
}
-
+
}