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.templating;
35  
36  import javax.jcr.RepositoryException;
37  
38  import org.slf4j.Logger;
39  import org.slf4j.LoggerFactory;
40  
41  import info.magnolia.cms.beans.config.ContentRepository;
42  import info.magnolia.cms.core.Content;
43  import info.magnolia.cms.util.DeprecationUtil;
44  import info.magnolia.cms.util.NodeDataUtil;
45  import info.magnolia.context.MgnlContext;
46  
47  /**
48   * Represents a paragraph definition. Following are most of the properties you can use
49   * to configure your paragraphs. Of course, if you're using specific subclasses,
50   * other properties could be available.
51   * <br/>
52   * <br/>
53   * <table border="1">
54   * <tbody>
55   * <tr>
56   * <th>Property</th>
57   * <th>Default</th>
58   * <th>Values</th>
59   * <th>Description</th>
60   * </tr>
61   * <tr>
62   * <td>class</td>
63   * <td> {@link Paragraph}</td>
64   * <td>&nbsp;</td>
65   * <td>&nbsp;</td>
66   * </tr>
67   * <tr>
68   * <td>type</td>
69   * <td><code>jsp</code></td>
70   * <td><code>jsp</code>,<code>freemarker</code>,…</td>
71   * <td>Determines which <code>ParagraphRenderer</code> to use. Out of the box,
72   * Magnolia provides support for JSP and FreeMarker.</td>
73   * </tr>
74   * <tr>
75   * <td>templatePath</td>
76   * <td>&nbsp;</td>
77   * <td>This property follows conventional syntax for path definitions.</td>
78   * <td>This property defines the path to the template to be used for this
79   * paragraph.</td>
80   * </tr>
81   * <tr>
82   * <td>modelClass</td>
83   * <td>&nbsp;</td>
84   * <td>The fully qualified name of a class implementing
85   * {@link RenderingModel}</td>
86   * <td>The bean created by the renderer based on the modelClass defined on the
87   * paragraph or template definition. The current content, definition and the
88   * parent model are passed to the constructor. This object is instantiated for
89   * each rendering of a template or a paragraph.</td>
90   * </tr>
91   * <tr>
92   * <td>i18nBasename</td>
93   * <td>info.magnolia.module. admininterface.messages or whatever the
94   * i18nBasename is set to in the dialog for this paragraph.</td>
95   * <td>This can be any properly defined Magnolia message bundle.</td>
96   * <td>This property defines the message bundle to use for this paragraph.</td>
97   * </tr>
98   * <tr>
99   * <td>title</td>
100  * <td>&nbsp;</td>
101  * <td>The title or a message bundle key to be used with the bundle defined by
102  * <code>i18nBasename</code>.</td>
103  * <td>This property defines the title of the paragraph.</td>
104  * </tr>
105  * <tr>
106  * <td>description</td>
107  * <td>&nbsp;</td>
108  * <td>The description or a message bundle key to be used with the bundle
109  * defined by <code>i18nBasename</code>.</td>
110  * <td>This property is used to describe the paragraph.</td>
111  * </tr>
112  * <tr>
113  * <td>dialog</td>
114  * <td>&nbsp;</td>
115  * <td>&nbsp;</td>
116  * <td>This property is used to specify the name of the dialog associated with
117  * this paragraph.</td>
118  * </tr>
119  * </tbody>
120  * </table>
121  *
122  * @author Sameer Charles
123  */
124 public class Paragraph extends AbstractRenderable {
125 
126     private final static Logger log = LoggerFactory.getLogger(Paragraph.class);
127 
128     /**
129      * @deprecated since 4.0 use the type property
130      */
131     public String getTemplateType(){
132         DeprecationUtil.isDeprecated("The property templateType in paragraph definitions has changed to type" );
133         return getType();
134     }
135 
136     /**
137      * @deprecated since 4.0 use the type property
138      */
139     public void setTemplateType(String type){
140         DeprecationUtil.isDeprecated("The property templateType in paragraph definitions has changed to type" );
141         setType(type);
142     }
143 
144     /**
145      * @deprecated since 4.0 use the dialog property
146      */
147     public String getDialogPath(String path){
148         String msg = "The property dialogPath in paragraph definitions has been deprecated, use the dialog property instead";
149         DeprecationUtil.isDeprecated(msg);
150         throw new UnsupportedOperationException(msg);
151     }
152 
153     /**
154      * @deprecated since 4.0 use the dialog property
155      */
156     public void setDialogPath(String path){
157         DeprecationUtil.isDeprecated("The property dialogPath in paragraph definitions has been deprecated, use the dialog property instead");
158         Content node;
159         try {
160             node = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG).getContent(path);
161             String name = NodeDataUtil.getString(node, "name", node.getName());
162             setDialog(name);
163         }
164         catch (RepositoryException e) {
165             log.error("Can't determine dialog name using the path [" + path + "]", e);
166         }
167     }
168 
169 }