1 /* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.clearsilver.jsilver; 18 19 import com.google.clearsilver.jsilver.data.Data; 20 import com.google.clearsilver.jsilver.exceptions.JSilverException; 21 import com.google.clearsilver.jsilver.resourceloader.ResourceLoader; 22 import com.google.clearsilver.jsilver.template.Template; 23 24 import java.io.IOException; 25 26 /** 27 * Renders a template. 28 */ 29 public interface TemplateRenderer { 30 31 /** 32 * Renders a given template and provided data, writing to an arbitrary output. 33 * 34 * @param templateName Name of template to load (e.g. "things/blah.cs"). 35 * @param data Data to be used in template. 36 * @param output Where template should be rendered to. This can be a Writer, PrintStream, 37 * System.out/err), StringBuffer/StringBuilder or anything that implements 38 * java.io.Appendable 39 * @param resourceLoader ResourceLoader to use when reading in included files. 40 */ render(String templateName, Data data, Appendable output, ResourceLoader resourceLoader)41 void render(String templateName, Data data, Appendable output, ResourceLoader resourceLoader) 42 throws IOException, JSilverException; 43 44 /** 45 * Same as {@link #render(String, Data, Appendable, ResourceLoader)}, except it uses the default 46 * ResourceLoader passed in to the JSilver constructor. 47 */ render(String templateName, Data data, Appendable output)48 void render(String templateName, Data data, Appendable output) throws IOException, 49 JSilverException; 50 51 /** 52 * Same as {@link #render(String, Data, Appendable)}, except returns rendered template as a 53 * String. 54 */ render(String templateName, Data data)55 String render(String templateName, Data data) throws IOException, JSilverException; 56 57 /** 58 * Renders a given template and provided data, writing to an arbitrary output. 59 * 60 * @param template Template to render. 61 * @param data Data to be used in template. 62 * @param output Where template should be rendered to. This can be a Writer, PrintStream, 63 * System.out/err), StringBuffer/StringBuilder or anything that implements 64 * java.io.Appendable. 65 * @param resourceLoader ResourceLoader to use when reading in included files. 66 * 67 */ render(Template template, Data data, Appendable output, ResourceLoader resourceLoader)68 void render(Template template, Data data, Appendable output, ResourceLoader resourceLoader) 69 throws IOException, JSilverException; 70 71 /** 72 * Same as {@link #render(Template,Data,Appendable,ResourceLoader)}, except it uses the 73 * ResourceLoader passed into the JSilver constructor. 74 */ render(Template template, Data data, Appendable output)75 void render(Template template, Data data, Appendable output) throws IOException, JSilverException; 76 77 /** 78 * Same as {@link #render(Template,Data,Appendable)}, except returns rendered template as a 79 * String. 80 */ render(Template template, Data data)81 String render(Template template, Data data) throws IOException, JSilverException; 82 83 /** 84 * Renders a given template from the content passed in. That is, the first parameter is the actual 85 * template content rather than the filename to load. 86 * 87 * @param content Content of template (e.g. "Hello <cs var:name ?>"). 88 * @param data Data to be used in template. 89 * @param output Where template should be rendered to. This can be a Writer, PrintStream, 90 * System.out/err), StringBuffer/StringBuilder or anything that implements 91 * java.io.Appendable 92 */ renderFromContent(String content, Data data, Appendable output)93 void renderFromContent(String content, Data data, Appendable output) throws IOException, 94 JSilverException; 95 96 /** 97 * Same as {@link #renderFromContent(String, Data, Appendable)}, except returns rendered template 98 * as a String. 99 */ renderFromContent(String content, Data data)100 String renderFromContent(String content, Data data) throws IOException, JSilverException; 101 102 } 103