View Javadoc

1   /**
2    * This file Copyright (c) 2008-2013 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 javax.jcr.Node;
37  
38  import info.magnolia.jcr.util.ContentMap;
39  import info.magnolia.rendering.template.RenderableDefinition;
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   * @version $Id$
65   */
66  public interface RenderingModel <RD extends RenderableDefinition> {
67  
68      /**
69       * A constant used in some special cases where rendering must be skipped, i.e. a redirect template.
70       * It can be used by template models as a return value for the {@link RenderingModel#execute()} method to inform
71       * {@link info.magnolia.rendering.renderer.AbstractRenderer} that it should not render anything in that particular
72       * case.
73       */
74      public static final String SKIP_RENDERING = "skip-rendering";
75  
76      /**
77       * The model of the parent component or template.
78       */
79      RenderingModel< ? > getParent();
80  
81      /**
82       * The content node tied to this model.
83       */
84      Node getNode();
85  
86      /**
87       * Map representation of the content node tied to this model.
88       */
89      ContentMap getContent();
90  
91      /**
92       * The renderable (template, area or component) tied to this model.
93       */
94      RD getDefinition();
95  
96      /**
97       * Called after all properties were set. Can return a string which is passed
98       * to the method.
99       * {@link RenderableDefinition#determineTemplatePath(String, RenderingModel)}
100      */
101     String execute();
102 
103     /**
104      * The top root model of the rendering process.
105      * In for example the scope of rendering a page this would be the pages model.
106      */
107     RenderingModel<?> getRoot();
108 
109 }