1 package com.atlassian.plugin.web.renderer;
2
3 import com.atlassian.plugin.Plugin;
4
5 import java.io.IOException;
6 import java.io.Writer;
7 import java.util.Map;
8
9 /**
10 * This interface allows the plugin system to be extended by adding new
11 * renderers for new markup formats. Currently the atlassian-template-renderer
12 * project provides a velocity implementation.
13 *
14 * @see {@link com.atlassian.plugin.web.descriptors.WebPanelRendererModuleDescriptor#getModule()}
15 * @since 2.5.0
16 */
17 public interface WebPanelRenderer
18 {
19 /**
20 * @return the name of the resource type supported by this renderer. {@code <resource>} elements defined in plugin
21 * descriptors to be rendered by this renderer should specify this String as their {@code type} attribute.
22 */
23 String getResourceType();
24
25 /**
26 * Renders the template to the writer.
27 *
28 * @param templateName file name of the template to render
29 * @param plugin the context plugin. Used, for example, to resolve templates and other resources from the classpath
30 * via {@link Plugin#getClassLoader()}
31 * @param context Map of objects to make available in the template rendering process
32 * @param writer where to write the rendered template
33 * @throws RendererException thrown if there is an internal exception when rendering the template
34 * @throws java.io.IOException thrown if there is a problem reading the template file or writing to the writer
35 */
36 void render(String templateName, Plugin plugin, Map<String, Object> context, Writer writer)
37 throws RendererException, IOException;
38
39 /**
40 * Renders the {@code fragment} using the given context and adding {@code I18nResolver} and {@code
41 * WebResourceManager}.
42 *
43 * @param fragment template fragment to render
44 * @param plugin the context plugin. Used, for example, to resolve templates and other resources from the classpath
45 * via {@link Plugin#getClassLoader()}
46 * @param context Map of objects to make available in the template rendering process
47 * @return rendered template
48 * @throws RendererException thrown if there is an internal exception when rendering the template
49 * @deprecated since 2.11. Use {@link #renderFragment(java.io.Writer, String, com.atlassian.plugin.Plugin, java.util.Map)}
50 * instead. Method no longer used inside the atlassian-plugins-webfragment module.
51 */
52 String renderFragment(String fragment, Plugin plugin, Map<String, Object> context) throws RendererException;
53
54 /**
55 * Renders the {@code fragment} using the given context and adding {@code I18nResolver} and {@code
56 * WebResourceManager}, writing the output to the provided writer.
57 *
58 * @param writer the writer to append the output to
59 * @param fragment template fragment to render
60 * @param plugin the context plugin. Used, for example, to resolve templates and other resources from the classpath
61 * via {@link Plugin#getClassLoader()}
62 * @param context Map of objects to make available in the template rendering process
63 * @return rendered template
64 * @throws RendererException thrown if there is an internal exception when rendering the template
65 * @throws IOException if there is some problem writing to the supplied writer
66 * @since 2.11
67 */
68 void renderFragment(Writer writer, String fragment, Plugin plugin, Map<String, Object> context) throws RendererException, IOException;
69 }