1 package com.atlassian.plugin.web.model;
2
3 import com.atlassian.plugin.PluginAccessor;
4 import com.atlassian.plugin.web.renderer.RendererException;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import java.util.Map;
9
10
11
12
13
14
15
16
17
18
19
20
21 public class EmbeddedTemplateWebPanel extends AbstractWebPanel
22 {
23 private String templateBody;
24 private static final Logger logger = LoggerFactory.getLogger(EmbeddedTemplateWebPanel.class.getName());
25
26 public EmbeddedTemplateWebPanel(PluginAccessor pluginAccessor)
27 {
28 super(pluginAccessor);
29 }
30
31
32
33
34
35 public void setTemplateBody(String templateBody)
36 {
37 this.templateBody = templateBody;
38 }
39
40 public String getHtml(final Map<String, Object> context)
41 {
42 try
43 {
44 return getRenderer().renderFragment(templateBody, plugin, context);
45 }
46 catch (RendererException e)
47 {
48 final String message = String.format("Error rendering WebPanel: %s\n" +
49 "Template contents: %s", e.getMessage(), templateBody);
50 logger.warn(message, e);
51 return message;
52 }
53 }
54 }