1 /* 2 * This file is part of Pease Plate Template Engine. 3 * 4 * Pease Plate Template Engine is free software: you can redistribute 5 * it and/or modify it under the terms of the GNU Lesser General 6 * Public License as published by the Free Software Foundation, 7 * either version 3 of the License, or any later version. 8 * 9 * Pease Plate Template Engine is distributed in the hope that it 10 * will be useful, but WITHOUT ANY WARRANTY; without even the implied 11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * See the GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with Pease Plate Template Engine. If not, see 16 * <http://www.gnu.org/licenses/>. 17 * 18 * Copyright (c) 2008 Manfred HANTSCHEL 19 */ 20 package org.peaseplate; 21 22 import java.io.IOException; 23 import java.io.Writer; 24 import java.util.List; 25 import java.util.Locale; 26 27 import org.peaseplate.internal.BuildContext; 28 import org.peaseplate.internal.ResourceKey; 29 import org.peaseplate.internal.template.MacroReference; 30 import org.peaseplate.locator.TemplateLocator; 31 32 /** 33 * Represents a loaded and compiled template. 34 * 35 * @author Manfred HANTSCHEL 36 */ 37 public interface Template { 38 39 /** 40 * Returns the template engine that was used to create this template. 41 * @return the template engine 42 */ 43 public TemplateEngine getEngine(); 44 45 /** 46 * Returns the template locator 47 * @return the template locator 48 */ 49 public TemplateLocator getLocator(); 50 51 /** 52 * Resolves the messages for this template 53 * @param engine the engine 54 * @return the messages for this template 55 * @throws TemplateException on occasion 56 */ 57 public Messages getMessages(TemplateEngine engine) throws TemplateException; 58 59 /** 60 * Returns the imported resource key 61 * @return the imported resource key, may be null 62 */ 63 public List<ResourceKey> getImportedResourceKeys(); 64 65 /** 66 * Returns the macro refernce with the specified name 67 * and the specified extension 68 * @param qualifiedName the qualified name of the macro 69 * @return the macro reference or null if not found 70 */ 71 public MacroReference getMacroReference(String qualifiedName); 72 73 /** 74 * Render the template to the specified writer. 75 * Uses the default values from the template engine this template was create with. 76 * @param writer the writer 77 * @param workingObject the working object 78 * @throws TemplateException on occasion 79 * @throws IOException on occasion 80 */ 81 public void render(Writer writer, Object workingObject) throws TemplateException, IOException; 82 83 /** 84 * Render the template to the specified writer. 85 * Uses the default values from the template engine this template was create with. 86 * @param writer the writer 87 * @param workingObject the working object 88 * @param locale the locale 89 * @throws TemplateException on occasion 90 * @throws IOException on occasion 91 */ 92 public void render(Writer writer, Object workingObject, Locale locale) throws TemplateException, IOException; 93 94 /** 95 * Renders the template to the specified writer 96 * @param writer the writer 97 * @param workingObject the working object 98 * @param locale the locale 99 * @param lineSeparator the line separator 100 * @throws TemplateException on occasion 101 * @throws IOException on occasion 102 */ 103 public void render(Writer writer, Object workingObject, Locale locale, LineSeparator lineSeparator) throws TemplateException, IOException; 104 105 /** 106 * Renders the template to the specified writer using the 107 * specified build context 108 * @param context the context 109 * @param writer the writer 110 * @throws TemplateException on occasion 111 * @throws IOException on occasion 112 */ 113 public void render(Writer writer, BuildContext context) throws TemplateException, IOException; 114 115 }