1 /* 2 * Copyright (c) 2002-2020, City of Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 package fr.paris.lutece.portal.service.template; 35 36 import fr.paris.lutece.util.html.HtmlTemplate; 37 import java.util.List; 38 39 import java.util.Locale; 40 41 /** 42 * 43 * IFreeMarkerTemplateService 44 * 45 */ 46 public interface IFreeMarkerTemplateService 47 { 48 /** 49 * Get the absolute path from relative path 50 * 51 * @param strPath 52 * the path 53 * @return the absolute path from relative path 54 */ 55 String getAbsolutePathFromRelativePath( String strPath ); 56 57 /** 58 * Get the default date pattern 59 * 60 * @param locale 61 * the locale 62 * @return the default date pattern 63 */ 64 String getDefaultPattern( Locale locale ); 65 66 /** 67 * Set the template update delay 68 * 69 * @param nTemplateUpdateDelay 70 * the template update delay 71 */ 72 void setTemplateUpdateDelay( int nTemplateUpdateDelay ); 73 74 /** 75 * Adds a macro file (like the main commons.html) brought by a plugin. This file will be included for every template (autoinclude). 76 * 77 * @param strFileName 78 * the filename 79 */ 80 void addPluginMacros( String strFileName ); 81 82 /** 83 * Add a shared variable into every template 84 * 85 * @param name 86 * name of the shared variable 87 * @param obj 88 * value 89 */ 90 void setSharedVariable( String name, Object obj ); 91 92 /** 93 * Initializes the service with the templates's path 94 * 95 * @param strTemplatePath 96 * The template path 97 */ 98 void init( String strTemplatePath ); 99 100 /** 101 * Initializes the service with the templates's path 102 * 103 * @param strTemplatePath 104 * The template path 105 * @param bAcceptIncompatibleImprovements 106 * Use Freemarker new features or stay backward compatible 107 */ 108 void init( String strTemplatePath, boolean bAcceptIncompatibleImprovements ); 109 110 /** 111 * Load a template 112 * 113 * @param strPath 114 * the root path 115 * @param strTemplate 116 * the path of the template from the root path 117 * @return the html template 118 */ 119 HtmlTemplate loadTemplate( String strPath, String strTemplate ); 120 121 /** 122 * Load a template and process a model 123 * 124 * @param strPath 125 * the root path 126 * @param strTemplate 127 * the path of the template from the root path 128 * @param locale 129 * The locale 130 * @param rootMap 131 * the model root 132 * @return the processed html template 133 */ 134 HtmlTemplate loadTemplate( String strPath, String strTemplate, Locale locale, Object rootMap ); 135 136 /** 137 * Load a template from a String and process a model. 138 * the template data is stored in the StringTemplateLoader of freemarker. 139 * the template key is generate by a hash of the template data. 140 * 141 * 142 * @param strTemplateData 143 * The template as a string 144 * @param locale 145 * The {@link Locale} 146 * @param rootMap 147 * the model root 148 * @return the processed html template 149 */ 150 HtmlTemplate loadTemplateFromStringFtl( String strTemplateData, Locale locale, Object rootMap ); 151 152 153 /** 154 * Load a template from a String and process a model. 155 * the template data is stored in the StringTemplateLoader of freemarker using strTemplateName as key 156 157 * @param strTemplateName the key of the template put in the StringTemplateLoader. The template name must be a Fully qualified name (skin.plugins.myplugin.manage_my_objects) 158 * @param strTemplateData The template as a string 159 * @param locale The {@link Locale} 160 * @param rootMap the model root 161 * @param bResetCacheTemplate force the update of the template data stored in the StringTemplateLoader 162 * @return the processed html template 163 */ 164 165 HtmlTemplate loadTemplateFromStringFtl(String strTemplateName,String strTemplateData, Locale locale, Object rootMap,boolean bResetCacheTemplate); 166 167 /** 168 * Clears the configuration cache 169 */ 170 void resetConfiguration( ); 171 172 /** 173 * Reset the cache 174 */ 175 void resetCache( ); 176 177 /** 178 * Get the list of auto includes files 179 * 180 * @return The list or null if no configuration is available 181 */ 182 List<String> getAutoIncludes( ); 183 184 /** 185 * Add an auto include file 186 * 187 * @param strFile 188 * The file to add 189 */ 190 void addAutoInclude( String strFile ); 191 192 /** 193 * Remove an auto include file 194 * 195 * @param strFile 196 * The file to remove 197 */ 198 void removeAutoInclude( String strFile ); 199 }