View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.mail.setup;
35  
36  import info.magnolia.cms.beans.config.ContentRepository;
37  import info.magnolia.cms.core.ItemType;
38  import info.magnolia.module.DefaultModuleVersionHandler;
39  import info.magnolia.module.delta.Condition;
40  import info.magnolia.module.mail.commands.MailCommand;
41  import info.magnolia.module.delta.BootstrapConditionally;
42  import info.magnolia.module.delta.BootstrapSingleResource;
43  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
44  import info.magnolia.module.delta.DeltaBuilder;
45  import info.magnolia.module.delta.PropertyValueDelegateTask;
46  import info.magnolia.module.delta.RegisterModuleServletsTask;
47  import info.magnolia.module.delta.RemoveNodeTask;
48  import info.magnolia.module.delta.WebXmlConditionsUtil;
49  
50  import java.util.ArrayList;
51  import java.util.List;
52  
53  /**
54   * @author gjoseph
55   * @version $Revision: $ ($Author: $)
56   */
57  public class MailModuleVersionHandler extends DefaultModuleVersionHandler {
58      static final String MAIL_COMMAND_CLASS_PRIOR_TO_4_0 = "info.magnolia.cms.mail.commands.MailCommand";
59      static final String COMMAND_IN_ADMININTERFACEMODULE_PATH = "/modules/adminInterface/commands/default/sendMail";
60  
61      public MailModuleVersionHandler() {
62  
63          register(DeltaBuilder.update("3.5", "")
64                  .addTask(new RegisterModuleServletsTask())
65                  .addConditions(mailServletIsWrappedSince_3_5())
66          );
67  
68          final CheckAndModifyPropertyValueTask mailServletMapping = new CheckAndModifyPropertyValueTask("Mapping for mail servlet", "Fixes the mapping for the mail servlet, making it specification compliant.",
69                  ContentRepository.CONFIG,
70                  "/server/filters/servlets/Mail/mappings/--magnolia-mail-",
71                  "pattern", "/.magnolia/mail*", "/.magnolia/mail"
72          );
73  
74          register(DeltaBuilder.update("3.6.2", "")
75                  .addTask(mailServletMapping)
76          );
77  
78          final RemoveNodeTask removeMailServletMapping = new RemoveNodeTask("Remove mail servlet", "Removes the mail servlet.",
79                  ContentRepository.CONFIG,
80                  "/server/filters/servlets/Mail"
81          );
82  
83          final RemoveNodeTask replaceConfigMenuMail = new RemoveNodeTask("Remove tools mail menu", "Removes the tools mail menu.",
84                  ContentRepository.CONFIG,
85                  "/modules/adminInterface/config/menu/tools/mails"
86          );
87  
88          final MoveNodeContentTask moveTemplates = new MoveNodeContentTask("Rename templates", "Templates will be renamed to templatesConfiguration.",
89                  ContentRepository.CONFIG,
90                  "/modules/mail/config/templates",
91                  "/modules/mail/config/templatesConfiguration",
92                  ItemType.CONTENT,
93                  false);
94  
95          register(DeltaBuilder.update("4.0", "")
96                  .addTask(removeMailServletMapping)
97                  .addTask(replaceConfigMenuMail)
98                  .addTask(moveTemplates)
99                  .addTask(new BootstrapConditionally("Mail handlers", "Installs mail handlers.", "/mgnl-bootstrap/mail/config.modules.mail.config.handler.xml"))
100                 .addTask(new BootstrapConditionally("Mail page", "Installs mail page.", "/mgnl-bootstrap/mail/config.modules.mail.pages.xml"))
101                 .addTask(new BootstrapConditionally("Mail factory", "Installs mail factories.", "/mgnl-bootstrap/mail/config.modules.mail.config.factory.xml"))
102                 .addTask(new BootstrapSingleResource("Mail menu", "Installs mail tools menu.", "/mgnl-bootstrap/mail/config.modules.adminInterface.config.menu.tools.sendMail.xml"))
103                 .addTask(new CheckAndModifyPropertyValueTask("Mail command", "", ContentRepository.CONFIG, COMMAND_IN_ADMININTERFACEMODULE_PATH, "class", MAIL_COMMAND_CLASS_PRIOR_TO_4_0, MailCommand.class.getName()))
104         );
105 
106         register(DeltaBuilder.update("4.0.3", "")
107                 //since 4.0 mail command class was not updated to the new value
108                 //mail command class was changed on 4.0, needs to be fixed for 4.0.3 and 4.1.1
109                 .addTask(fixMailCommand(MAIL_COMMAND_CLASS_PRIOR_TO_4_0, MailCommand.class.getName()))
110         );
111 
112         register(DeltaBuilder.update("4.1.1", "")
113               //since 4.0 mail command class was not updated to the new value
114               //mail command class was changed on 4.0, needs to be fixed for 4.0.3 and 4.1.1
115               .addTask(fixMailCommand(MAIL_COMMAND_CLASS_PRIOR_TO_4_0, MailCommand.class.getName()))
116         );
117     }
118 
119     protected List<Condition> mailServletIsWrappedSince_3_5() {
120         final ArrayList<Condition> conditions = new ArrayList<Condition>();
121         final WebXmlConditionsUtil u = new WebXmlConditionsUtil(conditions);
122         u.servletIsNowWrapped("Mail");
123         return conditions;
124     }
125 
126     private PropertyValueDelegateTask fixMailCommand(final String previouslyWrongValue, final String fixedValue) {
127         final String workspaceName = ContentRepository.CONFIG;
128         final CheckAndModifyPropertyValueTask fixTask = new CheckAndModifyPropertyValueTask(null, null, workspaceName, COMMAND_IN_ADMININTERFACEMODULE_PATH,
129                 "class", previouslyWrongValue, fixedValue);
130 
131         return new PropertyValueDelegateTask("Mail Command",
132                 "Checks and updates the mail command if not correct.",
133                 workspaceName, COMMAND_IN_ADMININTERFACEMODULE_PATH, "class", previouslyWrongValue, false, fixTask);
134     }
135 }