View Javadoc

1   /**
2    * This file Copyright (c) 2003-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.templating.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.InstallContext;
40  import info.magnolia.module.delta.BootstrapSingleModuleResource;
41  import info.magnolia.module.delta.BootstrapSingleResource;
42  import info.magnolia.module.delta.BootstrapSingleResourceAndOrderBefore;
43  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
44  import info.magnolia.module.delta.DeltaBuilder;
45  import info.magnolia.module.delta.OrderNodeBeforeTask;
46  import info.magnolia.module.delta.Task;
47  import info.magnolia.module.templating.setup.for3_5.IntroduceParagraphRenderers;
48  import info.magnolia.module.templating.setup.for4_0.DeprecateDialogPathAllModules;
49  import info.magnolia.module.templating.setup.for4_0.FixTemplatePathTask;
50  import info.magnolia.module.templating.setup.for4_0.RenamePropertyAllModulesNodeTask;
51  import info.magnolia.module.templating.setup.for4_0.NestPropertiesAllModulesNodeTask;
52  
53  import java.util.ArrayList;
54  import java.util.Arrays;
55  import java.util.List;
56  
57  
58  /**
59   * Module's version handler.
60   * @author gjoseph
61   * @version $Revision: $ ($Author: $)
62   */
63  public class TemplatingModuleVersionHandler extends DefaultModuleVersionHandler {
64  
65      private OrderNodeBeforeTask orderBackwardCompatibilityFilter = new OrderNodeBeforeTask("Move backward compatibility filter", "", ContentRepository.CONFIG, "/server/filters/cms/backwardCompatibility", "rendering");
66  
67      public TemplatingModuleVersionHandler() {
68          register(DeltaBuilder.update("3.5", "")
69                  .addTask(new IntroduceParagraphRenderers())
70                  .addTask(new BootstrapSingleResourceAndOrderBefore(
71                  "Compatibility Filter",
72                  "${actpage} is deprecated. Adds a compatibility filter still supporting it but writing warn messages to the log.",
73                  "/mgnl-bootstrap/templating/config.server.filters.cms.backwardCompatibility.xml",
74                  "rendering"))
75          );
76  
77          // move the filter in case it is in the wrong place
78          // this happened in case of a fresh install of former version
79          register(DeltaBuilder.update("3.5.4", "")
80                  .addTask(orderBackwardCompatibilityFilter)
81          );
82  
83          register(DeltaBuilder.update("4.0", "")
84                  .addTask(new BootstrapSingleResource("Freemarker Template Renderer", "Adds Freemarker template renderer configuration.", "/mgnl-bootstrap/templating/config.modules.templating.template-renderers.freemarker.xml"))
85                  .addTask(new CheckAndModifyPropertyValueTask("Rendering filter", "The rendering filter is now part of the templating module.", ContentRepository.CONFIG, "/server/filters/cms/rendering", "class", "info.magnolia.cms.filters.RenderingFilter", "info.magnolia.module.templating.RenderingFilter"))
86                  .addTask(new BootstrapSingleResource("Freemarker Model for RenderableDefinition", "Plugs in a specific Freemarker model for RenderableDefinition implementations.", "/mgnl-bootstrap/templating/config.server.rendering.freemarker.modelFactories.renderable.xml"))
87                  .addTask(new RenamePropertyAllModulesNodeTask("Templates configuration", "Property path is now templatePath.", "templates", "path", "templatePath"))
88                  .addTask(new NestPropertiesAllModulesNodeTask("Templates configuration", "Property path is now templatePath.", "templates",
89                          Arrays.asList(new String[]{"name", "type", "templatePath", "title", "description", "i18nBasename", "visible", "class"}), "parameters", ItemType.CONTENTNODE.getSystemName()))
90                  .addTask(new RenamePropertyAllModulesNodeTask("Paragraphs configuration", "Property templateType is now type.", "paragraphs", "templateType", "type"))
91                  .addTask(new DeprecateDialogPathAllModules("Paragraphs configuration", "Property dialogPath changed to dialog."))
92          );
93  
94          // TODO 4.1
95          // .addTask( move from admin module: ("Paragraph edit dialog", "The paragraph edition dialog is now a regular dialog.", "/mgnl-bootstrap/templating/config.modules.templating.dialogs.editParagraph.xml"))
96  //                .addTask(new ArrayDelegateTask("Paragraph selection dialog", "The paragraph selection dialog is now part of the Templating module.",
97  //                        new RemoveNodeTask(null, null, ContentRepository.CONFIG, "/modules/adminInterface/dialogs/selectParagraph"),
98  //                        new CreateNodeTask(null, null, ContentRepository.CONFIG, "/modules/templating/dialogs", "selectParagraph", ItemType.CONTENT.getSystemName()),
99  //                        new NewPropertyTask(null, null, ContentRepository.CONFIG, "/modules/templating/dialogs/selectParagraph", "class", ParagraphSelectDialog.class.getName())))
100 
101       //since 4.0 templatePath property was moved into parameters content node
102         //has to be fixed in 4.0.3 and 4.1.1
103         register(DeltaBuilder.update("4.0.3", "")
104                 .addTask(new FixTemplatePathTask("Fix templatePath property", "Moves templatePath property if is not set correct."))
105         );
106 
107         //since 4.0 templatePath property was moved into parameters content node
108         //has to be fixed in 4.0.3 and 4.1.1
109         register(DeltaBuilder.update("4.1.1", "")
110                 .addTask(new FixTemplatePathTask("Fix templatePath property", "Moves templatePath property if is not set correct."))
111         );
112 
113         register(DeltaBuilder.update("4.3", "")
114             .addTask(new BootstrapSingleModuleResource("Rendering Engine", "Add configuration for the new rendering engine.", "config.server.rendering.engine.xml"))
115         );
116 
117         register(DeltaBuilder.update("4.4", "")
118             .addTask(new BootstrapSingleResourceAndOrderBefore(
119                         "Model Execution Filter",
120                         "Add Model Execution Filter",
121                         "/mgnl-bootstrap/templating/config.server.filters.cms.modelExecution.xml",
122                         "backwardCompatibility"))
123         );
124     }
125 
126     protected List<Task> getExtraInstallTasks(InstallContext installContext) {
127         final ArrayList<Task> tasks = new ArrayList<Task>();
128         tasks.add(orderBackwardCompatibilityFilter);
129         tasks.add(new OrderNodeBeforeTask("Order model execution filter", "", ContentRepository.CONFIG, "/server/filters/cms/modelExecution", "backwardCompatibility"));
130         // TODO : make sure the RenderingFilter is the last one ?
131         return tasks;
132     }
133 }