roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [roller] 02/02: Implement template remove.
Date Sat, 14 Dec 2019 22:58:58 GMT
This is an automated email from the ASF dual-hosted git repository.

snoopdave pushed a commit to branch roller-6.0.x
in repository https://gitbox.apache.org/repos/asf/roller.git

commit 4373757c98defb39a48e2b300ea367f903a5a974
Author: David M. Johnson <snoopdave@apache.org>
AuthorDate: Sat Dec 14 17:58:34 2019 -0500

    Implement template remove.
---
 .../ui/struts2/editor/TemplateRemove.java          | 153 ---------------------
 .../weblogger/ui/struts2/editor/Templates.java     |  78 ++++++++++-
 app/src/main/resources/struts.xml                  |   4 +-
 .../webapp/WEB-INF/jsps/editor/TemplateRemove.jsp  |  55 --------
 .../main/webapp/WEB-INF/jsps/editor/Templates.jsp  |   5 +-
 .../WEB-INF/jsps/editor/TemplatesSidebar.jsp       |   2 +-
 6 files changed, 80 insertions(+), 217 deletions(-)

diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java
deleted file mode 100644
index 80ae5af..0000000
--- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.roller.weblogger.ui.struts2.editor;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.WeblogManager;
-import org.apache.roller.weblogger.business.WebloggerFactory;
-import org.apache.roller.weblogger.pojos.ThemeTemplate;
-import org.apache.roller.weblogger.pojos.Weblog;
-import org.apache.roller.weblogger.pojos.WeblogTemplate;
-import org.apache.roller.weblogger.pojos.WeblogTheme;
-import org.apache.roller.weblogger.ui.struts2.util.UIAction;
-import org.apache.roller.weblogger.util.Utilities;
-import org.apache.roller.weblogger.util.cache.CacheManager;
-import org.apache.struts2.convention.annotation.AllowedMethods;
-
-/**
- * Remove a template.
- */
-// TODO: make this work @AllowedMethods({"execute","remove","cancel"})
-public class TemplateRemove extends UIAction {
-
-    private static Log log = LogFactory.getLog(TemplateRemove.class);
-
-    // id of template to remove
-    private String removeId = null;
-
-    // template object that we will remove
-    private WeblogTemplate template = null;
-
-    public TemplateRemove() {
-        this.actionName = "templateRemove";
-        this.desiredMenu = "editor";
-        this.pageTitle = "editPages.title.removeOK";
-    }
-
-    @Override
-    public void myPrepare() {
-        if (StringUtils.isNotEmpty(getRemoveId())) {
-            try {
-                setTemplate(
-                    WebloggerFactory.getWeblogger().getWeblogManager().getTemplate(getRemoveId()));
-            } catch (WebloggerException ex) {
-                log.error("Error looking up template by id - " + getRemoveId(), ex);
-                addError("editPages.remove.notFound", getRemoveId());
-            }
-        }
-    }
-
-    /**
-     * Display the remove template confirmation.
-     */
-    @Override
-    public String execute() {
-        return "confirm";
-    }
-
-    /**
-     * Remove a new template.
-     */
-    public String remove() {
-
-        if (getTemplate() != null) {
-            try {
-                if (!getTemplate().isRequired()
-                    || !WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
-
-                    WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
-
-                    // if weblog template remove custom style sheet also
-                    if (getTemplate().getName().equals(WeblogTemplate.DEFAULT_PAGE)) {
-
-                        Weblog weblog = getActionWeblog();
-
-                        ThemeTemplate stylesheet = getActionWeblog().getTheme().getStylesheet();
-
-                        // Delete style sheet if the same name
-                        if (stylesheet != null
-                            && getActionWeblog().getTheme().getStylesheet() != null
-                            && stylesheet.getLink().equals(
-                            getActionWeblog().getTheme().getStylesheet().getLink())) {
-
-                            // Same so OK to delete
-                            WeblogTemplate css =
-                                mgr.getTemplateByLink(getActionWeblog(), stylesheet.getLink());
-
-                            if (css != null) {
-                                mgr.removeTemplate(css);
-                            }
-                        }
-                    }
-
-                    // notify cache
-                    CacheManager.invalidate(getTemplate());
-                    mgr.removeTemplate(getTemplate());
-                    WebloggerFactory.getWeblogger().flush();
-
-                    return SUCCESS;
-                } else {
-                    addError("editPages.remove.requiredTemplate");
-                }
-
-            } catch (Exception ex) {
-                log.error("Error removing page - " + getRemoveId(), ex);
-                addError("editPages.remove.error");
-            }
-        }
-
-        return "confirm";
-    }
-
-
-    @Override
-    public String cancel() {
-        return CANCEL;
-    }
-
-    public String getRemoveId() {
-        return removeId;
-    }
-
-    public void setRemoveId(String removeId) {
-        this.removeId = removeId;
-    }
-
-    public WeblogTemplate getTemplate() {
-        return template;
-    }
-
-    public void setTemplate(WeblogTemplate template) {
-        this.template = template;
-    }
-
-}
diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java
index ff92a8a..d9eb4d9 100644
--- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java
+++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java
@@ -23,14 +23,14 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.util.RollerConstants;
 import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.business.WeblogManager;
 import org.apache.roller.weblogger.business.WebloggerFactory;
-import org.apache.roller.weblogger.pojos.CustomTemplateRendition;
+import org.apache.roller.weblogger.pojos.*;
 import org.apache.roller.weblogger.pojos.TemplateRendition.RenditionType;
 import org.apache.roller.weblogger.pojos.TemplateRendition.TemplateLanguage;
 import org.apache.roller.weblogger.pojos.ThemeTemplate.ComponentType;
-import org.apache.roller.weblogger.pojos.WeblogTemplate;
-import org.apache.roller.weblogger.pojos.WeblogTheme;
 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
+import org.apache.roller.weblogger.util.cache.CacheManager;
 import org.apache.struts2.convention.annotation.AllowedMethods;
 
 import java.util.ArrayList;
@@ -58,6 +58,9 @@ public class Templates extends UIAction {
     private String newTmplName = null;
     private ComponentType newTmplAction = null;
 
+    // id of template to remove
+    private String removeId = null;
+
     public Templates() {
         this.actionName = "templates";
         this.desiredMenu = "editor";
@@ -201,6 +204,68 @@ public class Templates extends UIAction {
         return execute();
     }
 
+    /**
+     * Remove a new template.
+     */
+    public String remove() {
+
+        WeblogTemplate template = null;
+        try {
+            template = WebloggerFactory.getWeblogger().getWeblogManager().getTemplate(getRemoveId());
+        } catch (WebloggerException e) {
+            addError("Error deleting template - check Roller logs");
+        }
+
+        if (template != null) {
+            try {
+                if (!template.isRequired()
+                    || !WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
+
+                    WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
+
+                    // if weblog template remove custom style sheet also
+                    if (template.getName().equals(WeblogTemplate.DEFAULT_PAGE)) {
+
+                        Weblog weblog = getActionWeblog();
+
+                        ThemeTemplate stylesheet = getActionWeblog().getTheme().getStylesheet();
+
+                        // Delete style sheet if the same name
+                        if (stylesheet != null
+                            && getActionWeblog().getTheme().getStylesheet() != null
+                            && stylesheet.getLink().equals(
+                            getActionWeblog().getTheme().getStylesheet().getLink())) {
+
+                            // Same so OK to delete
+                            WeblogTemplate css =
+                                mgr.getTemplateByLink(getActionWeblog(), stylesheet.getLink());
+
+                            if (css != null) {
+                                mgr.removeTemplate(css);
+                            }
+                        }
+                    }
+
+                    // notify cache
+                    CacheManager.invalidate(template);
+                    mgr.removeTemplate(template);
+                    WebloggerFactory.getWeblogger().flush();
+
+                } else {
+                    addError("editPages.remove.requiredTemplate");
+                }
+
+            } catch (Exception ex) {
+                log.error("Error removing page - " + getRemoveId(), ex);
+                addError("editPages.remove.error");
+            }
+        } else {
+            addError("editPages.remove.error");
+        }
+
+        return execute();
+    }
+
     // validation when adding a new template
     private void myValidate() {
 
@@ -270,4 +335,11 @@ public class Templates extends UIAction {
         this.newTmplAction = newTmplAction;
     }
 
+    public String getRemoveId() {
+        return removeId;
+    }
+
+    public void setRemoveId(String removeId) {
+        this.removeId = removeId;
+    }
 }
diff --git a/app/src/main/resources/struts.xml b/app/src/main/resources/struts.xml
index 63d5bb3..bc92b4b 100644
--- a/app/src/main/resources/struts.xml
+++ b/app/src/main/resources/struts.xml
@@ -556,9 +556,9 @@
         <action name="templates"
                 class="org.apache.roller.weblogger.ui.struts2.editor.Templates">
             <result name="list" type="tiles">.Templates</result>
-            <allowed-methods>add,execute</allowed-methods>
+            <allowed-methods>add,remove,execute</allowed-methods>
         </action>
-        
+
         <action name="templateEdit"
                 class="org.apache.roller.weblogger.ui.struts2.editor.TemplateEdit">
             <result name="list" type="chain">templates</result>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/TemplateRemove.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/TemplateRemove.jsp
deleted file mode 100644
index 67d26cb..0000000
--- a/app/src/main/webapp/WEB-INF/jsps/editor/TemplateRemove.jsp
+++ /dev/null
@@ -1,55 +0,0 @@
-<%--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  The ASF licenses this file to You
-  under the Apache License, Version 2.0 (the "License"); you may not
-  use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.  For additional information regarding
-  copyright in this work, please see the NOTICE file in the top level
-  directory of this distribution.
---%>
-<%@ include file="/WEB-INF/jsps/taglibs-struts2.jsp" %>
-
-<p class="subtitle">
-    <s:text name="pageRemove.subtitle" />
-</p>
-
-<p>
-    <s:text name="pageRemove.youSure"> 
-        <s:param value="template.name" />
-    </s:text>
-    <br/>
-	<br/>
-	<span class="warning">
-		<s:text name="pageRemoves.youSureWarning" />
-	</span>
-</p>
-
-<p>
-    <s:text name="pageRemove.pageId" /> = [<s:property value="template.id" />]
-    <br />
-    <s:text name="pageRemove.pageName" /> = [<s:property value="template.name" />]
-</p>
-
-<table>
-    <tr>
-        <td>
-            <s:form action="templateRemove!remove">
-                <s:hidden name="salt" />
-
-                <s:hidden name="removeId" />
-                <s:hidden name="weblog" value="%{actionWeblog.handle}" />
-                
-                <s:submit value="%{getText('generic.yes')}" />&nbsp;
-                <s:submit value="%{getText('generic.no')}" action="templateRemove!cancel"
/>
-            </s:form>
-        </td>
-    </tr>
-</table>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp
index fefbab6..05bd6cb 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp
@@ -30,7 +30,7 @@
     <p><s:text name="pagesForm.themesReminder"><s:param value="actionWeblog.editorTheme"/></s:text></p>
 </s:if>
 
-<s:form action="templateRemove!remove" theme="bootstrap" cssClass="form-horizontal">
+<s:form action="templates!remove" theme="bootstrap" cssClass="form-horizontal">
     <s:hidden name="salt"/>
     <s:hidden name="weblog" value="%{actionWeblog.handle}"/>
     <s:hidden name="removeId" id="removeId"/>
@@ -104,8 +104,7 @@
     function confirmTemplateDelete(templateId, templateName) {
         $('#removeId').val(templateId);
         if (window.confirm('<s:text name="pageRemove.confirm"/>: \'' + templateName
+ '\'?')) {
-            document.templateRemove.action = "<s:url action='templateRemove!remove' />";
-            document.templateRemove.submit();
+            document.getElementById("templates").submit();
         }
     }
 </script>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/TemplatesSidebar.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/TemplatesSidebar.jsp
index 38e3df0..a5bdc60 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/TemplatesSidebar.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/TemplatesSidebar.jsp
@@ -20,7 +20,7 @@
 <h3><s:text name="pagesForm.addNewPage"/></h3>
 <hr size="1" noshade="noshade"/>
 
-<s:form action="templates!add" theme="bootstrap" cssClass="form-horizontal">
+<s:form action="templates!add" theme="bootstrap" cssClass="form-horizontal" id="templateAdd">
     <s:hidden name="salt"/>
     <s:hidden name="weblog"/>
 


Mime
View raw message