View Javadoc

1   /**
2    * This file Copyright (c) 2007-2011 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.samples.setup;
35  
36  import info.magnolia.cms.beans.config.ContentRepository;
37  import info.magnolia.module.DefaultModuleVersionHandler;
38  import info.magnolia.module.InstallContext;
39  import info.magnolia.module.admininterface.setup.AddMainMenuItemTask;
40  import info.magnolia.module.admininterface.setup.AddSubMenuItemTask;
41  import info.magnolia.module.admininterface.setup.SetDefaultPublicURI;
42  import info.magnolia.module.delta.BackupTask;
43  import info.magnolia.module.delta.BootstrapConditionally;
44  import info.magnolia.module.delta.BootstrapResourcesTask;
45  import info.magnolia.module.delta.BootstrapSingleResource;
46  import info.magnolia.module.delta.DeltaBuilder;
47  import info.magnolia.module.delta.FilterOrderingTask;
48  import info.magnolia.module.delta.NodeExistsDelegateTask;
49  import info.magnolia.module.delta.RegisterModuleServletsTask;
50  import info.magnolia.module.delta.RemoveNodeTask;
51  
52  import java.util.ArrayList;
53  import java.util.List;
54  
55  
56  /**
57   * Used to update previous version of samples module to the new one, as the module has major changes
58   * there are some tasks to perform.
59   *
60   * @author philipp
61   * @version $Id: SamplesVersionHandler.java 41137 2011-01-06 18:19:25Z gjoseph $
62   *
63   */
64  public class SamplesVersionHandler extends DefaultModuleVersionHandler {
65      private static final String I18N_BASENAME = "info.magnolia.module.samples.messages";
66  
67      /**
68       * First thing is to back up the old module, configuration and templates.
69       * Then the new content is bootstraped.
70       */
71      public SamplesVersionHandler() {
72          register(DeltaBuilder.update("4.0", "New samples module, replaces the old one.")
73                  .addTask(new NodeExistsDelegateTask("Backup samples config", "Creates a backup", "config",
74                          "/modules/samples", new BackupTask("config", "/modules/samples", true)))
75                  .addTask(new NodeExistsDelegateTask("Backup samples website samples", "Creates a backup", "website",
76                          "/help", new BackupTask("website", "/help", true)))
77                  .addTask(new NodeExistsDelegateTask("Backup samples website samples", "Creates a backup", "website",
78                          "/mailform", new BackupTask("website", "/mailform", true)))
79                  .addTask(new NodeExistsDelegateTask("Backup samples website samples", "Creates a backup", "website",
80                          "/mails", new BackupTask("website", "/mails", true)))
81                  .addTask(new BootstrapResourcesTask("New configuration", "Bootstraps new default samples configuration.") {
82                      protected String[] getResourcesToBootstrap(final InstallContext installContext) {
83                          return new String[]{
84                                  "/mgnl-bootstrap/samples/config.modules.samples.dialogs.controlsShowRoom.xml",
85                                  "/mgnl-bootstrap/samples/config.modules.samples.dialogs.howTo.xml",
86                                  "/mgnl-bootstrap/samples/config.modules.samples.dialogs.mainProperties.xml",
87                                  "/mgnl-bootstrap/samples/config.modules.samples.paragraphs.samplesControlsShowRoom.xml",
88                                  "/mgnl-bootstrap/samples/config.modules.samples.paragraphs.samplesHowToFTL.xml",
89                                  "/mgnl-bootstrap/samples/config.modules.samples.paragraphs.samplesHowToJSP.xml",
90                                  "/mgnl-bootstrap/samples/config.modules.samples.paragraphs.samplesSearchResult.xml",
91                                  "/mgnl-bootstrap/samples/config.modules.samples.templates.samplesMainFTL.xml",
92                                  "/mgnl-bootstrap/samples/config.modules.samples.templates.samplesMainJSP.xml",
93                                  "/mgnl-bootstrap/samples/config.modules.samples.templates.samplesVirtualURI.xml",
94                                  "/mgnl-bootstrap/samples/config.server.filters.sample.xml",
95                          };
96                      }
97                  })
98                  .addTask(new BootstrapSingleResource("Sample VirtualUri", "Adds a sample",
99                          "/mgnl-bootstrap-samples/samples/config.modules.samples.virtualURIMapping.xml"))
100                 .addTask(new BootstrapSingleResource("Sample how to freemarker", "Adds a sample",
101                         "/mgnl-bootstrap-samples/samples/website.howTo-freemarker.xml"))
102                 .addTask(new BootstrapSingleResource("Sample how to jsp", "Adds a sample",
103                         "/mgnl-bootstrap-samples/samples/website.howTo-jsp.xml"))
104                 .addTask(new BootstrapSingleResource("Sample of search result", "Adds a sample",
105                         "/mgnl-bootstrap-samples/samples/website.searchResult-jsp.xml"))
106                 .addTask(new BootstrapSingleResource("Sample using wirtual uri", "Adds a sample",
107                         "/mgnl-bootstrap-samples/samples/website.products-freemarker.xml"))
108                 .addTask(new BootstrapConditionally("Samples developers", "Adds developers group if does not exist",
109                         "/mgnl-bootstrap-samples/samples/usergroups.developers.xml"))
110                 .addTask(new BootstrapConditionally("Samples employees", "Adds employees group if does not exist",
111                         "/mgnl-bootstrap-samples/samples/usergroups.employees.xml"))
112                 .addTask(new BootstrapConditionally("Samples editor", "Adds editor role if does not exist",
113                         "/mgnl-bootstrap-samples/samples/userroles.editor.xml"))
114                 .addTask(new BootstrapConditionally("Samples user", "Adds user if does not exist",
115                         "/mgnl-bootstrap-samples/samples/users.admin.david.xml"))
116                 .addTask(new BootstrapConditionally("Samples user", "Adds user if does not exist",
117                         "/mgnl-bootstrap-samples/samples/users.admin.eve.xml"))
118                 .addTask(new BootstrapConditionally("Samples user", "Adds user if does not exist",
119                         "/mgnl-bootstrap-samples/samples/users.admin.patrick.xml"))
120                 .addTask(new RemoveNodeTask("Remove menu items", "Removes the samples menu config item sample templates.",
121                             ContentRepository.CONFIG, "/modules/adminInterface/config/menu/config/sample-templates"))
122                 .addTask(new RemoveNodeTask("Remove menu items", "Removes the samples menu config item sample paragraphs.",
123                             ContentRepository.CONFIG, "/modules/adminInterface/config/menu/config/sample-paragraphs"))
124                 .addTask(new RemoveNodeTask("Remove menu items", "Removes the samples menu config item sample dialogs.",
125                             ContentRepository.CONFIG, "/modules/adminInterface/config/menu/config/sample-dialogs"))
126 
127                 .addTask(new RegisterModuleServletsTask())
128                 .addTasks(getCommonTasks())
129         );
130     }
131 
132     /**
133      * There are some tasks common to the update process and the new installation process
134      * that are not automatically bootstraped.
135      * Add new menu item, and three sub menu items and then set the new menu item in the proper place
136      * And then sets the default virtual URI on public instances
137      *
138      * @return
139      */
140     protected List getCommonTasks() {
141         final List commonTasks = new ArrayList();
142         // add the default uri task
143         commonTasks.add(new AddMainMenuItemTask("samples", "samples.menu.label", I18N_BASENAME, "", "/.resources/icons/24/compass.gif", "security"));
144 
145         commonTasks.add(submenu("config", "/modules/samples"));
146         commonTasks.add(submenu("filter", "/server/filters/sample"));
147         commonTasks.add(submenu("servlet", "/server/filters/servlets/DisplaySamplesSourcesServlet"));
148 
149         commonTasks.add(new FilterOrderingTask("sample", new String[]{"servlets"}));
150 
151         commonTasks.add(new SetDefaultPublicURI("defaultPublicURI"));
152 
153         return commonTasks;
154     }
155 
156     private AddSubMenuItemTask submenu(String name, String path) {
157         return new AddSubMenuItemTask("samples", name, "samples." + name + ".menu.label", I18N_BASENAME, "MgnlAdminCentral.showTree('config', '" + path + "')", "/.resources/icons/16/gears.gif");
158     }
159 
160     /**
161      * Installation process will boostrap everything in the bootstrap folder, then
162      * we have to add some extra tasks.
163      */
164     protected List getExtraInstallTasks(InstallContext installContext) {
165         return getCommonTasks();
166     }
167 
168 }