View Javadoc
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  import java.util.Map;
39  
40  import java.util.Locale;
41  
42  /**
43   *
44   * IFreeMarkerTemplateService
45   *
46   */
47  public interface IFreeMarkerTemplateService
48  {
49      /**
50       * Get the absolute path from relative path
51       * 
52       * @param strPath
53       *            the path
54       * @return the absolute path from relative path
55       */
56      String getAbsolutePathFromRelativePath( String strPath );
57  
58      /**
59       * Get the default date pattern
60       * 
61       * @param locale
62       *            the locale
63       * @return the default date pattern
64       */
65      String getDefaultPattern( Locale locale );
66  
67      /**
68       * Set the template update delay
69       * 
70       * @param nTemplateUpdateDelay
71       *            the template update delay
72       */
73      void setTemplateUpdateDelay( int nTemplateUpdateDelay );
74  
75      /**
76       * Adds a macro file (like the main commons.html) brought by a plugin. This file will be included for every template (autoinclude).
77       * 
78       * @param strFileName
79       *            the filename
80       */
81      @Deprecated
82      void addPluginMacros( String strFileName );
83  
84      /**
85       * Adds a macro file (like the main commons.html) brought by a plugin. This file will be included for every template (auto-include).
86       * 
87       * @param strFileName
88       *            the filename
89       */
90      void addPluginAutoInclude( String strFileName );
91  
92      /**
93       * Adds an import file brought by a plugin. This file will be imported for every template (auto-import).
94       * 
95       * @param strNamespace
96       *            The namespace corresponding to the import file
97       * @param strFileName
98       *            the filename
99       */
100     void addPluginAutoImport( String strNamespace, String strFileName );
101 
102     /**
103      * Add a shared variable into every template
104      * 
105      * @param name
106      *            name of the shared variable
107      * @param obj
108      *            value
109      */
110     void setSharedVariable( String name, Object obj );
111 
112     /**
113      * Initializes the service with the templates's path
114      * 
115      * @param strTemplatePath
116      *            The template path
117      */
118     void init( String strTemplatePath );
119 
120     /**
121      * Initializes the service with the templates's path
122      * 
123      * @param strTemplatePath
124      *            The template path
125      * @param bAcceptIncompatibleImprovements
126      *            Use Freemarker new features or stay backward compatible
127      */
128     void init( String strTemplatePath, boolean bAcceptIncompatibleImprovements );
129 
130     /**
131      * Load a template
132      * 
133      * @param strPath
134      *            the root path
135      * @param strTemplate
136      *            the path of the template from the root path
137      * @return the html template
138      */
139     HtmlTemplate loadTemplate( String strPath, String strTemplate );
140 
141     /**
142      * Load a template and process a model
143      * 
144      * @param strPath
145      *            the root path
146      * @param strTemplate
147      *            the path of the template from the root path
148      * @param locale
149      *            The locale
150      * @param rootMap
151      *            the model root
152      * @return the processed html template
153      */
154     HtmlTemplate loadTemplate( String strPath, String strTemplate, Locale locale, Object rootMap );
155 
156     /**
157      * Load a template from a String and process a model.
158      * the template data is stored in the StringTemplateLoader of freemarker. 
159      * the template key is generate by a hash of the template data.
160      *    
161      *
162      * @param strTemplateData
163      *            The template as a string
164      * @param locale
165      *            The {@link Locale}
166      * @param rootMap
167      *            the model root
168      * @return the processed html template
169      */
170     HtmlTemplate loadTemplateFromStringFtl( String strTemplateData, Locale locale, Object rootMap );
171     
172     
173     /**
174      * Load a template from a String and process a model.
175      * the template data is stored in the StringTemplateLoader of freemarker using strTemplateName as key 
176 
177      * @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)
178      * @param strTemplateData The template as a string
179      * @param locale  The {@link Locale}
180      * @param rootMap  the model root
181      * @param bResetCacheTemplate force the update of the template data stored in the StringTemplateLoader
182      * @return the processed html template
183      */
184     
185     HtmlTemplate loadTemplateFromStringFtl(String strTemplateName,String strTemplateData, Locale locale, Object rootMap,boolean bResetCacheTemplate);
186 
187     /**
188      * Clears the configuration cache
189      */
190     void resetConfiguration( );
191 
192     /**
193      * Reset the cache
194      */
195     void resetCache( );
196 
197     /**
198      * Get the list of auto includes files
199      * 
200      * @return The list or null if no configuration is available
201      */
202     List<String> getAutoIncludes(  );
203 
204     /**
205      * Add an auto include file
206      * 
207      * @param strFile
208      *            The file to add
209      */
210     void addAutoInclude( String strFile );
211 
212     /**
213      * Remove an auto include file
214      * 
215      * @param strFile
216      *            The file to remove
217      */
218     void removeAutoInclude( String strFile );
219 
220     /**
221      * Get the list of auto imports files
222      * 
223      * @return The list or null if no configuration is available
224      */
225     Map<String,String> getAutoImports(  );
226 
227     /**
228      * Add an auto import file
229      * 
230      * @param strNamespace
231      *            The namespace corresponding to the import file
232      * @param strFile
233      *            The file to add
234      */
235     void addAutoImport( String strNamespace, String strFile );
236 
237     /**
238      * Remove an auto import file
239      * 
240      * @param strNamespace
241      *            The namespace corresponding to the import file to remove
242      */
243     void removeAutoImport( String strNamespace );
244 }