View Javadoc
1   /**
2    * This file Copyright (c) 2008-2018 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.rendering.model;
35  
36  import info.magnolia.jcr.util.ContentMap;
37  import info.magnolia.rendering.template.RenderableDefinition;
38  
39  import javax.jcr.Node;
40  
41  
42  /**
43   * A RenderingModel is used during rendering, it is analogous to the model part of the MVC pattern. It is associated with
44   * a renderable and is executed before a content node using the renderable is rendered. The renderer instantiates the
45   * RenderingModel and calls its execute method. While rendering the model is available to the template script under the
46   * name <code>model</code> and the value returned by the execute method is available under the name
47   * <code>actionResult</code>. It is commonly used to add backing logic to a component.
48   *
49   * <h3>Instantiation</h3>
50   * It is created using reflection for each renderable and used only once, its constructor can declare as arguments any
51   * components that can be provided by the current ComponentProvider and in addition it can declare any of the following
52   * constructor arguments:
53   * <ul>
54   * <li>Node the node that is currently being rendered</li>
55   * <li>RenderableDefinition the renderable definition begin used to render the node</li>
56   * <li>RenderingModel the rendering model of the parent renderable</li>
57   * </ul>
58   *
59   * After instantiation all request parameters are then mapped to the model's properties.
60   *
61   * <p>It can also abort the rendering by returning {@link #SKIP_RENDERING} from its execute method.</p>
62   *
63   * @param <RD> - an instance of {@link RenderableDefinition}
64   */
65  public interface RenderingModel<RD extends RenderableDefinition> {
66  
67      /**
68       * A constant used in some special cases where rendering must be skipped, i.e. a redirect template.
69       * It can be used by template models as a return value for the {@link RenderingModel#execute()} method to inform
70       * {@link info.magnolia.rendering.renderer.AbstractRenderer} that it should not render anything in that particular
71       * case.
72       */
73      public static final String SKIP_RENDERING = "skip-rendering";
74  
75      /**
76       * The model of the parent component or template.
77       */
78      RenderingModel<?> getParent();
79  
80      /**
81       * The content node tied to this model.
82       */
83      Node getNode();
84  
85      /**
86       * Map representation of the content node tied to this model.
87       */
88      ContentMap getContent();
89  
90      /**
91       * The renderable (template, area or component) tied to this model.
92       */
93      RD getDefinition();
94  
95      /**
96       * Called after all properties were set. Can return a string which is passed
97       * to the method.
98       * {@link RenderableDefinition#determineTemplatePath(String, RenderingModel)}
99       */
100     String execute();
101 
102     /**
103      * The top root model of the rendering process.
104      * In for example the scope of rendering a page this would be the pages model.
105      */
106     RenderingModel<?> getRoot();
107 
108 }