Clover Coverage Report - magnolia-module-templating 4.4.5
Coverage timestamp: Mon Sep 12 2011 16:32:30 CEST
../../../../img/srcFileCovDistChart8.png 25% of files have more coverage
28   181   24   1.27
2   106   0.86   22
22     1.09  
1    
 
  AbstractRenderable       Line # 57 28 0% 24 10 80.8% 0.8076923
 
  (21)
 
1    /**
2    * This file Copyright (c) 2008-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;
35   
36    import java.lang.reflect.InvocationTargetException;
37    import java.util.HashMap;
38    import java.util.Map;
39   
40    import org.apache.commons.beanutils.BeanUtils;
41    import org.apache.commons.lang.ArrayUtils;
42    import org.apache.commons.lang.builder.ToStringBuilder;
43   
44    import info.magnolia.cms.core.Content;
45    import info.magnolia.context.MgnlContext;
46    import info.magnolia.objectfactory.Classes;
47    import info.magnolia.objectfactory.MgnlInstantiationException;
48   
49   
50    /**
51    * Base implementation for paragraph and template definitions. Provides the
52    * {@link #modelClass} property which is used in the method
53    * {@link #newModel(Content, RenderableDefinition , RenderingModel)}
54    * @author pbracher
55    * @version $Id: AbstractRenderable.java 41137 2011-01-06 18:19:25Z gjoseph $
56    */
 
57    public class AbstractRenderable implements RenderableDefinition {
58    private String name;
59    private String title;
60    private String templatePath;
61    private String dialog;
62    private String type;
63    private String description;
64    private String i18nBasename;
65    private Class<? extends RenderingModel> modelClass = RenderingModelImpl.class;
66    private Map parameters = new HashMap();
67   
68    /**
69    * Return always the {@link #templatePath} property.
70    */
 
71  6 toggle public String determineTemplatePath(String actionResult, RenderingModel model ) {
72  6 return this.getTemplatePath();
73    }
74   
75    /**
76    * Instantiates the model based on the class defined by the {@link #modelClass} property. The class must provide a
77    * constructor similar to {@link RenderingModelImpl#RenderingModelImpl(Content, RenderableDefinition, RenderingModel)}.
78    * All the request parameters are then mapped to the model's properties.
79    */
 
80  11 toggle public RenderingModel newModel(Content content, RenderableDefinition definition, RenderingModel parentModel) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
81  11 try {
82  11 final RenderingModel model = Classes.getClassFactory().newInstance(getModelClass(), new Class[]{Content.class, definition.getClass(), RenderingModel.class}, content, definition, parentModel);
83  9 final Map<String, String> params = MgnlContext.getParameters();
84  9 if (params != null) {
85  1 BeanUtils.populate(model, params);
86    }
87  9 return model;
88    } catch (MgnlInstantiationException e) {
89  2 throw new IllegalArgumentException(MISSING_CONSTRUCTOR_MESSAGE + "Can't instantiate " + getModelClass(), e);
90    }
91    }
92   
 
93  41 toggle public String getName() {
94  41 return this.name;
95    }
96   
 
97  0 toggle public String getTitle() {
98  0 return this.title;
99    }
100   
 
101  6 toggle public String getTemplatePath() {
102  6 return this.templatePath;
103    }
104   
 
105  24 toggle public String getType() {
106  24 return type;
107    }
108   
 
109  0 toggle public String getDescription() {
110  0 return this.description;
111    }
112   
 
113  0 toggle public void setDescription(String description) {
114  0 this.description = description;
115    }
116   
 
117  24 toggle public void setName(String name) {
118  24 this.name = name;
119    }
120   
 
121  7 toggle public void setTemplatePath(String templatePath) {
122  7 this.templatePath = templatePath;
123    }
124   
 
125  12 toggle public void setType(String type) {
126  12 this.type = type;
127    }
128   
 
129  0 toggle public void setTitle(String title) {
130  0 this.title = title;
131    }
132   
 
133  12 toggle public String getDialog() {
134  12 return this.dialog;
135    }
136   
 
137  9 toggle public void setDialog(String dialog) {
138  9 this.dialog = dialog;
139    }
140   
 
141  3 toggle public String getI18nBasename() {
142  3 return this.i18nBasename;
143    }
144   
 
145  1 toggle public void setI18nBasename(String basename) {
146  1 this.i18nBasename = basename;
147    }
148   
 
149  4 toggle public Map getParameters() {
150  4 return this.parameters;
151    }
152   
 
153  3 toggle public void setParameters(Map params) {
154  3 this.parameters = params;
155    }
156   
 
157  13 toggle public Class<? extends RenderingModel> getModelClass() {
158  13 return this.modelClass;
159    }
160   
 
161  7 toggle public void setModelClass(Class<? extends RenderingModel> modelClass) {
162  7 this.modelClass = modelClass;
163    }
164   
 
165  0 toggle public String toString() {
166  0 return new ToStringBuilder(this)
167    .append("name", this.name) //$NON-NLS-1$
168    .append("type", this.type) //$NON-NLS-1$
169    .append("description", this.description) //$NON-NLS-1$
170    .append("dialog", this.dialog) //$NON-NLS-1$
171    .append("title", this.title) //$NON-NLS-1$
172    .append("templatePath", this.templatePath) //$NON-NLS-1$
173    .toString();
174    }
175   
176    private static final Class<?>[] MODEL_CONSTRUCTOR_TYPES = new Class[]{Content.class, RenderableDefinition.class, RenderingModel.class};
177    private static final String MISSING_CONSTRUCTOR_MESSAGE;
 
178  1 toggle static {
179  1 MISSING_CONSTRUCTOR_MESSAGE = "A model class must define a constructor with types " + ArrayUtils.toString(MODEL_CONSTRUCTOR_TYPES) + ". ";
180    }
181    }