You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by gh...@apache.org on 2014/02/03 18:27:30 UTC

svn commit: r1563986 - in /roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor: TemplatesRemove.java ThemeEdit.java

Author: ghuber
Date: Mon Feb  3 17:27:30 2014
New Revision: 1563986

URL: http://svn.apache.org/r1563986
Log:
Make sure switching back from custom does not delete our stylesheet and ensure the style sheet link is reset on switching back after setting alternate themes. NPE on the .clone().

Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java?rev=1563986&r1=1563985&r2=1563986&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java Mon Feb  3 17:27:30 2014
@@ -39,92 +39,92 @@ import org.apache.roller.weblogger.util.
  */
 public class TemplatesRemove extends UIAction {
 
-	private static final long serialVersionUID = 895186156151331087L;
-	private static Log log = LogFactory.getLog(TemplatesRemove.class);
+    private static final long serialVersionUID = 895186156151331087L;
+    private static Log log = LogFactory.getLog(TemplatesRemove.class);
 
-	// Templates to remove
-	private String[] idSelections = null;
+    // Templates to remove
+    private String[] idSelections = null;
 
-	// Limit updates to just this set of comma-separated IDs
-	private String ids = null;
+    // Limit updates to just this set of comma-separated IDs
+    private String ids = null;
 
-	// list of templates to display
-	private List<WeblogTemplate> templates = Collections.emptyList();;
-
-	public TemplatesRemove() {
-		this.actionName = "templatesRemove";
-		this.desiredMenu = "editor";
-		this.pageTitle = "editPages.title.removeOK";
-	}
-
-	@Override
-	public List<String> requiredWeblogPermissionActions() {
-		return Collections.singletonList(WeblogPermission.ADMIN);
-	}
+    // list of templates to display
+    private List<WeblogTemplate> templates = Collections.emptyList();;
+
+    public TemplatesRemove() {
+        this.actionName = "templatesRemove";
+        this.desiredMenu = "editor";
+        this.pageTitle = "editPages.title.removeOK";
+    }
+
+    @Override
+    public List<String> requiredWeblogPermissionActions() {
+        return Collections.singletonList(WeblogPermission.ADMIN);
+    }
 
-	public void myPrepare() {
+    public void myPrepare() {
 
         if (getIdSelections() != null) {
 
-			// query for templates list
-			try {
+            // query for templates list
+            try {
+
+                WeblogManager mgr = WebloggerFactory.getWeblogger()
+                        .getWeblogManager();
+
+                List<WeblogTemplate> pages = new ArrayList<WeblogTemplate>();
+                WeblogTemplate template = null;
+
+                String[] idsToDelete = getIdSelections();
+                if (idsToDelete != null && idsToDelete.length > 0) {
+
+                    for (int i = 0; i < idsToDelete.length; i++) {
+                        if (!idsToDelete[i].equals("")) {
+                            template = mgr.getPage(idsToDelete[i]);
+                            if (template != null) {
+                                pages.add(template);
+                            }
+                        }
+                    }
+
+                }
+
+                // Set page data
+                setTemplates(pages);
+                setIds(Utilities.stringArrayToString(idsToDelete, ","));
+
+                // Flush for operation
+                WebloggerFactory.getWeblogger().flush();
+
+            } catch (Exception ex) {
+                log.error("Error getting templates for weblog - "
+                        + getActionWeblog().getHandle(), ex);
+                addError("error.unexpected");
+            }
 
-				WeblogManager mgr = WebloggerFactory.getWeblogger()
-						.getWeblogManager();
+        }
+    }
+
+    /**
+     * Display the remove template confirmation.
+     */
+    public String execute() {
+
+        if (getIds() != null && getTemplates() != null
+                && getTemplates().size() > 0) {
+            return "confirm";
+        } else {
+            return SUCCESS;
+        }
 
-				List<WeblogTemplate> pages = new ArrayList<WeblogTemplate>();
-				WeblogTemplate template = null;
+    }
 
-				String[] idsToDelete = getIdSelections();
-				if (idsToDelete != null && idsToDelete.length > 0) {
-
-					for (int i = 0; i < idsToDelete.length; i++) {
-						if (!idsToDelete[i].equals("")) {
-							template = mgr.getPage(idsToDelete[i]);
-							if (template != null) {
-								pages.add(template);
-							}
-						}
-					}
-
-				}
-
-				// Set page data
-				setTemplates(pages);
-				setIds(Utilities.stringArrayToString(idsToDelete, ","));
-
-				// Flush for operation
-				WebloggerFactory.getWeblogger().flush();
-
-			} catch (Exception ex) {
-				log.error("Error getting templates for weblog - "
-						+ getActionWeblog().getHandle(), ex);
-				addError("error.unexpected");
-			}
-
-		}
-	}
-
-	/**
-	 * Display the remove template confirmation.
-	 */
-	public String execute() {
-
-		if (getIds() != null && getTemplates() != null
-				&& getTemplates().size() > 0) {
-			return "confirm";
-		} else {
-			return SUCCESS;
-		}
-
-	}
-
-	/**
-	 * Remove Selected templates
-	 */
-	public String remove() {
+    /**
+     * Remove Selected templates
+     */
+    public String remove() {
 
-		if (getIds() != null) {
+        if (getIds() != null) {
             try {
 
                 String[] idsToDelete = Utilities.stringToStringArray(getIds(),
@@ -143,8 +143,8 @@ public class TemplatesRemove extends UIA
                             template = mgr.getPage(idsToDelete[i]);
                             if (!template.isRequired()
                                     || !WeblogTemplate.ACTION_CUSTOM
-                                    .equals(getActionWeblog()
-                                            .getEditorTheme())) {
+                                            .equals(getActionWeblog()
+                                                    .getEditorTheme())) {
 
                                 // if weblog template remove custom style sheet
                                 // also
@@ -157,12 +157,12 @@ public class TemplatesRemove extends UIA
                                     // Delete style sheet if the same name
                                     if (stylesheet != null
                                             && getActionWeblog().getTheme()
-                                            .getStylesheet() != null
+                                                    .getStylesheet() != null
                                             && stylesheet.getLink().equals(
-                                            getActionWeblog()
-                                                    .getTheme()
-                                                    .getStylesheet()
-                                                    .getLink())) {
+                                                    getActionWeblog()
+                                                            .getTheme()
+                                                            .getStylesheet()
+                                                            .getLink())) {
                                         // Same so OK to delete
                                         WeblogTemplate css = mgr.getPageByLink(
                                                 getActionWeblog(),
@@ -206,63 +206,63 @@ public class TemplatesRemove extends UIA
             }
         }
 
-		return "confirm";
-	}
+        return "confirm";
+    }
 
-	/**
-	 * Cancel.
-	 * 
-	 * @return the string
-	 */
-	public String cancel() {
-		return "cancel";
-	}
-
-	/**
-	 * Gets the templates.
-	 * 
-	 * @return the templates
-	 */
-	public List<WeblogTemplate> getTemplates() {
-		return templates;
-	}
-
-	/**
-	 * Sets the templates.
-	 * 
-	 * @param templates
-	 *            the new templates
-	 */
-	public void setTemplates(List<WeblogTemplate> templates) {
-		this.templates = templates;
-	}
-
-	/**
-	 * Select check boxes for deleting records
-	 */
-	public String[] getIdSelections() {
-		return idSelections.clone();
-	}
-
-	/**
-	 * Select check boxes for deleting records
-	 */
-	public void setIdSelections(String[] idSelections) {
-		this.idSelections = idSelections.clone();
-	}
-
-	/**
-	 * Comma separated list if ids to remove
-	 */
-	public String getIds() {
-		return ids;
-	}
-
-	/**
-	 * Comma separated list if ids to remove
-	 */
-	public void setIds(String ids) {
-		this.ids = ids;
-	}
+    /**
+     * Cancel.
+     * 
+     * @return the string
+     */
+    public String cancel() {
+        return "cancel";
+    }
+
+    /**
+     * Gets the templates.
+     * 
+     * @return the templates
+     */
+    public List<WeblogTemplate> getTemplates() {
+        return templates;
+    }
+
+    /**
+     * Sets the templates.
+     * 
+     * @param templates
+     *            the new templates
+     */
+    public void setTemplates(List<WeblogTemplate> templates) {
+        this.templates = templates;
+    }
+
+    /**
+     * Select check boxes for deleting records
+     */
+    public String[] getIdSelections() {
+        return idSelections;
+    }
+
+    /**
+     * Select check boxes for deleting records
+     */
+    public void setIdSelections(String[] idSelections) {
+        this.idSelections = idSelections;
+    }
+
+    /**
+     * Comma separated list if ids to remove
+     */
+    public String getIds() {
+        return ids;
+    }
+
+    /**
+     * Comma separated list if ids to remove
+     */
+    public void setIds(String ids) {
+        this.ids = ids;
+    }
 
 }

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=1563986&r1=1563985&r2=1563986&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 Mon Feb  3 17:27:30 2014
@@ -138,18 +138,24 @@ public class ThemeEdit extends UIAction 
 
                 // do theme import if necessary
                 SharedTheme t = null;
-                if (isImportTheme() && !StringUtils.isEmpty(getImportThemeId())) {
-                    try {
-                        ThemeManager themeMgr = WebloggerFactory.getWeblogger()
-                                .getThemeManager();
-                        t = themeMgr.getTheme(getImportThemeId());
+
+                try {
+                    ThemeManager themeMgr = WebloggerFactory.getWeblogger()
+                            .getThemeManager();
+                    t = themeMgr.getTheme(getImportThemeId());
+                    if (isImportTheme()
+                            && !StringUtils.isEmpty(getImportThemeId())) {
                         themeMgr.importTheme(getActionWeblog(), t);
-                    } catch (Exception re) {
-                        log.error("Error customizing theme for weblog - "
-                                + getActionWeblog().getHandle(), re);
-                        // TODO: i18n
-                        addError("Error importing theme");
+                    } else {
+                        // Reset our custom from base
+                        weblog.setCustomStylesheetPath(t.getStylesheet()
+                                .getLink());
                     }
+                } catch (Exception re) {
+                    log.error("Error customizing theme for weblog - "
+                            + getActionWeblog().getHandle(), re);
+                    // TODO: i18n
+                    addError("Error importing theme");
                 }
 
                 if (!hasActionErrors()) {
@@ -226,7 +232,8 @@ public class ThemeEdit extends UIAction 
                             .getWeblogManager();
 
                     // Remove old style sheet
-                    if (!originalTheme.equals(getThemeId())
+                    if (!WeblogTheme.CUSTOM.equals(originalTheme)
+                            && !originalTheme.equals(getThemeId())
                             && getActionWeblog().getTheme().getStylesheet() != null) {
 
                         WeblogTemplate stylesheet = mgr.getPageByLink(