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 info.magnolia.cms.core.Content;
37  import info.magnolia.cms.i18n.Messages;
38  import info.magnolia.cms.i18n.MessagesManager;
39  import info.magnolia.cms.security.AccessManager;
40  import info.magnolia.cms.security.Permission;
41  import info.magnolia.cms.util.DeprecationUtil;
42  import info.magnolia.context.MgnlContext;
43  
44  import java.util.HashMap;
45  import java.util.Map;
46  
47  
48  /**
49   * @author Sameer Charles
50   * @author Fabrizio Giustina
51   * @version $Revision: 36178 $ ($Author: gjoseph $)
52   */
53  public class Template extends AbstractRenderable {
54      private Content content;
55  
56      private boolean visible = true;
57  
58      private Map<String, Template> subTemplates = new HashMap<String, Template>();
59  
60      /**
61       * Used internally for SubTemplates.
62       */
63      public Template() {
64  
65      }
66  
67      /**
68       * Getter for <code>path</code>.
69       * @return Returns the path.
70       * @deprecated since 4.0. use getTemplatePath() instead
71       */
72      public String getPath() {
73          DeprecationUtil.isDeprecated("The 'path' property is deprecated: use the templatePath property instead. (current value: " + getTemplatePath() + ")");
74          return getTemplatePath();
75      }
76  
77  
78      public String getI18NTitle() {
79          Messages msgs = MessagesManager.getMessages(getI18nBasename());
80  
81          return msgs.getWithDefault(getTitle(), getTitle());
82      }
83  
84      public String getParameter(String key) {
85          return (String) getParameters().get(key);
86      }
87  
88      /**
89       * Getter for <code>visible</code>.
90       * @return Returns the visible.
91       */
92      public boolean isVisible() {
93          return this.visible;
94      }
95  
96      public Template getSubTemplate(String extension) {
97          return this.subTemplates.get(extension);
98      }
99  
100     public void addSubTemplate(String extension, Template subTemplate) {
101         this.subTemplates.put(extension, subTemplate);
102     }
103 
104     public Map<String, Template> getSubTemplates() {
105         return this.subTemplates;
106     }
107 
108     public void setSubTemplates(Map<String, Template> subTemplates) {
109         this.subTemplates = subTemplates;
110     }
111 
112     /**
113      * @deprecated since 4.0 use {@link #setTemplatePath(String)}
114      */
115     public void setPath(String path) {
116         // log message can only output the templatePath, as there is not guarantee the name or content name have been set already
117         DeprecationUtil.isDeprecated("The 'path' property is deprecated: use the templatePath property instead. (setting to value: " + path + ")");
118         setTemplatePath(path);
119     }
120 
121     public void setVisible(boolean visible) {
122         this.visible = visible;
123     }
124 
125     public boolean isAvailable(Content node) {
126         // TODO is called quite often and should be faster
127         AccessManager am = MgnlContext.getAccessManager(getContent().getHierarchyManager().getName());
128         return am.isGranted(getContent().getHandle(), Permission.READ);
129     }
130 
131     public Content getContent() {
132         return this.content;
133     }
134 
135     // this is set by content2bean
136     public void setContent(Content content) {
137         this.content = content;
138     }
139 
140 }