1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2WebGui library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 */
20
21 package com.pow2.webgui.contentprovider;
22
23
24 import org.apache.velocity.VelocityContext;
25
26 import com.pow2.util.Util;
27 import com.pow2.util.VelocityUtil;
28 import com.pow2.webgui.Widget;
29
30
31
32 /***
33 * ContentProvider class
34 *
35 * @author Luca Fossato
36 * @created 06 July 2002
37 */
38 public class ContentProvider extends BaseContentProvider
39 {
40 /***
41 * Constructor.
42 *
43 * @param widget the parent widget to provide the content to
44 */
45 public ContentProvider(Widget widget)
46 {
47 super(widget);
48 }
49
50
51 /***
52 * Gets the contentProvider content.
53 *
54 * @return the ContentProvider content
55 * @exception Exception if any error occurs
56 */
57 public StringBuffer getContent() throws Exception
58 {
59 if (Util.isNull(template))
60 throw new Exception("template attribute is null");
61
62 VelocityContext context = new VelocityContext();
63
64 if (propertiesMap != null)
65 {
66 String[] props = new String[propertiesMap.size()];
67 props = (String[])propertiesMap.keySet().toArray(props);
68
69 if (props != null)
70 {
71 for (int i = 0; i < props.length; i++)
72 {
73 String key = props[i];
74 context.put(key, propertiesMap.get(key));
75 }
76 }
77 }
78
79
80 if (collection != null)
81 context.put("array", collection.toArray());
82
83 content.append(VelocityUtil.getTemplate(context, template));
84 return content;
85 }
86 }