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.template; 18 19 import com.google.clearsilver.jsilver.autoescape.EscapeMode; 20 import com.google.clearsilver.jsilver.data.Data; 21 import com.google.clearsilver.jsilver.resourceloader.ResourceLoader; 22 23 import java.io.IOException; 24 25 /** 26 * Represents a template that can be rendered with data. 27 */ 28 public interface Template { 29 30 /** 31 * Render the template. 32 * 33 * @param data Data to merge with template. 34 * @param out Target to write to. 35 * @param resourceLoader ResourceLoader to use instead of the default template one when loading 36 * files. 37 */ render(Data data, Appendable out, ResourceLoader resourceLoader)38 void render(Data data, Appendable out, ResourceLoader resourceLoader) throws IOException; 39 40 /** 41 * Render the template with a custom RenderingContext. 42 * 43 * @param context RenderingContext to use during rendering. 44 */ render(RenderingContext context)45 void render(RenderingContext context) throws IOException; 46 47 /** 48 * Create a new RenderingContext. 49 * 50 * @param data Data to merge with template. 51 * @param out Target to write to. 52 * @param resourceLoader ResourceLoader to load files. 53 */ createRenderingContext(Data data, Appendable out, ResourceLoader resourceLoader)54 RenderingContext createRenderingContext(Data data, Appendable out, ResourceLoader resourceLoader); 55 56 /** 57 * Name of template (e.g. mytemplate.cs). 58 */ getTemplateName()59 String getTemplateName(); 60 61 /** 62 * Name to use when displaying error or log messages. May return the same value as 63 * #getTemplateName, or may contain more information. 64 */ getDisplayName()65 String getDisplayName(); 66 67 /** 68 * Return the EscapeMode in which this template was generated. 69 * 70 * @return EscapeMode 71 */ getEscapeMode()72 EscapeMode getEscapeMode(); 73 } 74