Replace getSoneStatus and getNotifications with getStatus.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
1 /*
2  * FreenetSone - WebInterface.java - Copyright © 2010 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.web;
19
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22 import java.io.Reader;
23 import java.io.UnsupportedEncodingException;
24 import java.net.URI;
25 import java.net.URISyntaxException;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.logging.Level;
30 import java.util.logging.Logger;
31
32 import net.pterodactylus.sone.core.Core;
33 import net.pterodactylus.sone.core.CoreListener;
34 import net.pterodactylus.sone.data.Post;
35 import net.pterodactylus.sone.data.Reply;
36 import net.pterodactylus.sone.data.Sone;
37 import net.pterodactylus.sone.freenet.L10nFilter;
38 import net.pterodactylus.sone.freenet.wot.Identity;
39 import net.pterodactylus.sone.main.SonePlugin;
40 import net.pterodactylus.sone.notify.ListNotification;
41 import net.pterodactylus.sone.template.CollectionAccessor;
42 import net.pterodactylus.sone.template.CssClassNameFilter;
43 import net.pterodactylus.sone.template.GetPagePlugin;
44 import net.pterodactylus.sone.template.IdentityAccessor;
45 import net.pterodactylus.sone.template.NotificationManagerAccessor;
46 import net.pterodactylus.sone.template.PostAccessor;
47 import net.pterodactylus.sone.template.ReplyAccessor;
48 import net.pterodactylus.sone.template.RequestChangeFilter;
49 import net.pterodactylus.sone.template.SoneAccessor;
50 import net.pterodactylus.sone.template.SubstringFilter;
51 import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
52 import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
53 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
54 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
55 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
56 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
57 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
58 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
59 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
60 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
61 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
62 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
63 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
64 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
65 import net.pterodactylus.sone.web.page.PageToadlet;
66 import net.pterodactylus.sone.web.page.PageToadletFactory;
67 import net.pterodactylus.sone.web.page.StaticPage;
68 import net.pterodactylus.util.logging.Logging;
69 import net.pterodactylus.util.notify.NotificationManager;
70 import net.pterodactylus.util.notify.TemplateNotification;
71 import net.pterodactylus.util.template.DateFilter;
72 import net.pterodactylus.util.template.DefaultTemplateFactory;
73 import net.pterodactylus.util.template.MatchFilter;
74 import net.pterodactylus.util.template.PaginationPlugin;
75 import net.pterodactylus.util.template.ReflectionAccessor;
76 import net.pterodactylus.util.template.Template;
77 import net.pterodactylus.util.template.TemplateException;
78 import net.pterodactylus.util.template.TemplateFactory;
79 import net.pterodactylus.util.template.TemplateProvider;
80 import net.pterodactylus.util.template.XmlFilter;
81 import net.pterodactylus.util.thread.Ticker;
82 import freenet.clients.http.SessionManager;
83 import freenet.clients.http.ToadletContainer;
84 import freenet.l10n.BaseL10n;
85
86 /**
87  * Bundles functionality that a web interface of a Freenet plugin needs, e.g.
88  * references to l10n helpers.
89  *
90  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
91  */
92 public class WebInterface implements CoreListener {
93
94         /** The logger. */
95         private static final Logger logger = Logging.getLogger(WebInterface.class);
96
97         /** The notification manager. */
98         private final NotificationManager notificationManager = new NotificationManager();
99
100         /** The Sone plugin. */
101         private final SonePlugin sonePlugin;
102
103         /** The registered toadlets. */
104         private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
105
106         /** The form password. */
107         private final String formPassword;
108
109         /** The template factory. */
110         private DefaultTemplateFactory templateFactory;
111
112         /** The “new Sone” notification. */
113         private final ListNotification<Sone> newSoneNotification;
114
115         /** The “new post” notification. */
116         private final ListNotification<Post> newPostNotification;
117
118         /** The “new reply” notification. */
119         private final ListNotification<Reply> newReplyNotification;
120
121         /** The “rescuing Sone” notification. */
122         private final ListNotification<Sone> rescuingSonesNotification;
123
124         /** The “Sone rescued” notification. */
125         private final ListNotification<Sone> sonesRescuedNotification;
126
127         /**
128          * Creates a new web interface.
129          *
130          * @param sonePlugin
131          *            The Sone plugin
132          */
133         public WebInterface(SonePlugin sonePlugin) {
134                 this.sonePlugin = sonePlugin;
135                 formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
136
137                 templateFactory = new DefaultTemplateFactory();
138                 templateFactory.addAccessor(Object.class, new ReflectionAccessor());
139                 templateFactory.addAccessor(Collection.class, new CollectionAccessor());
140                 templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
141                 templateFactory.addAccessor(Post.class, new PostAccessor(getCore()));
142                 templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
143                 templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
144                 templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
145                 templateFactory.addFilter("date", new DateFilter());
146                 templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
147                 templateFactory.addFilter("substring", new SubstringFilter());
148                 templateFactory.addFilter("xml", new XmlFilter());
149                 templateFactory.addFilter("change", new RequestChangeFilter());
150                 templateFactory.addFilter("match", new MatchFilter());
151                 templateFactory.addFilter("css", new CssClassNameFilter());
152                 templateFactory.addPlugin("getpage", new GetPagePlugin());
153                 templateFactory.addPlugin("paginate", new PaginationPlugin());
154                 templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
155                 templateFactory.addTemplateObject("formPassword", formPassword);
156
157                 /* create notifications. */
158                 Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
159                 newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
160
161                 Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
162                 newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
163
164                 Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
165                 newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
166
167                 Template rescuingSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/rescuingSonesNotification.html"));
168                 rescuingSonesNotification = new ListNotification<Sone>("sones-being-rescued-notification", "sones", rescuingSonesTemplate);
169
170                 Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
171                 sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
172         }
173
174         //
175         // ACCESSORS
176         //
177
178         /**
179          * Returns the Sone core used by the Sone plugin.
180          *
181          * @return The Sone core
182          */
183         public Core getCore() {
184                 return sonePlugin.core();
185         }
186
187         /**
188          * Returns the notification manager.
189          *
190          * @return The notification manager
191          */
192         public NotificationManager getNotifications() {
193                 return notificationManager;
194         }
195
196         /**
197          * Returns the l10n helper of the node.
198          *
199          * @return The node’s l10n helper
200          */
201         public BaseL10n getL10n() {
202                 return sonePlugin.l10n().getBase();
203         }
204
205         /**
206          * Returns the session manager of the node.
207          *
208          * @return The node’s session manager
209          */
210         public SessionManager getSessionManager() {
211                 try {
212                         return sonePlugin.pluginRespirator().getSessionManager(new URI("/"));
213                 } catch (URISyntaxException use1) {
214                         logger.log(Level.SEVERE, "Could not get Session Manager!", use1);
215                         return null;
216                 }
217         }
218
219         /**
220          * Returns the node’s form password.
221          *
222          * @return The form password
223          */
224         public String getFormPassword() {
225                 return formPassword;
226         }
227
228         //
229         // ACTIONS
230         //
231
232         /**
233          * Starts the web interface and registers all toadlets.
234          */
235         public void start() {
236                 registerToadlets();
237
238                 /* notification templates. */
239                 Template startupNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/startupNotification.html"));
240
241                 final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
242                 notificationManager.addNotification(startupNotification);
243
244                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (120 * 1000), new Runnable() {
245
246                         @Override
247                         public void run() {
248                                 startupNotification.dismiss();
249                         }
250                 }, "Sone Startup Notification Remover");
251
252                 Template wotMissingNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/wotMissingNotification.html"));
253                 final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
254                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), new Runnable() {
255
256                         @Override
257                         @SuppressWarnings("synthetic-access")
258                         public void run() {
259                                 if (getCore().getIdentityManager().isConnected()) {
260                                         wotMissingNotification.dismiss();
261                                 } else {
262                                         notificationManager.addNotification(wotMissingNotification);
263                                 }
264                                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), this, "Sone WoT Connector Checker");
265                         }
266
267                 }, "Sone WoT Connector Checker");
268         }
269
270         /**
271          * Stops the web interface and unregisters all toadlets.
272          */
273         public void stop() {
274                 unregisterToadlets();
275                 Ticker.getInstance().stop();
276         }
277
278         //
279         // PRIVATE METHODS
280         //
281
282         /**
283          * Register all toadlets.
284          */
285         private void registerToadlets() {
286                 Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html"));
287                 Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html"));
288                 Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
289                 Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
290                 Template createPostTemplate = templateFactory.createTemplate(createReader("/templates/createPost.html"));
291                 Template createReplyTemplate = templateFactory.createTemplate(createReader("/templates/createReply.html"));
292                 Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html"));
293                 Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
294                 Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
295                 Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/like.html"));
296                 Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html"));
297                 Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
298                 Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
299                 Template lockSoneTemplate = templateFactory.createTemplate(createReader("/templates/lockSone.html"));
300                 Template unlockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unlockSone.html"));
301                 Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
302                 Template unfollowSoneTemplate = templateFactory.createTemplate(createReader("/templates/unfollowSone.html"));
303                 Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
304                 Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
305                 Template dismissNotificationTemplate = templateFactory.createTemplate(createReader("/templates/dismissNotification.html"));
306                 Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
307                 Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
308                 Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
309                 Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
310
311                 PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
312                 pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
313                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
314                 pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
315                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
316                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
317                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
318                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
319                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
320                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(likePostTemplate, this)));
321                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this)));
322                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
323                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
324                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(lockSoneTemplate, this)));
325                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(unlockSoneTemplate, this)));
326                 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
327                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(unfollowSoneTemplate, this)));
328                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
329                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
330                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout"));
331                 pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
332                 pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
333                 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
334                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(dismissNotificationTemplate, this)));
335                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
336                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
337                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
338                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
339                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
340                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
341                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
342                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
343                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
344                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
345                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
346                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
347                 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
348                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
349                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
350                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
351                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
352
353                 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
354                 toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin);
355                 for (PageToadlet toadlet : pageToadlets) {
356                         String menuName = toadlet.getMenuName();
357                         if (menuName != null) {
358                                 toadletContainer.register(toadlet, "Navigation.Menu.Name", toadlet.path(), true, "Navigation.Menu.Item." + menuName + ".Name", "Navigation.Menu.Item." + menuName + ".Tooltip", false, toadlet);
359                         } else {
360                                 toadletContainer.register(toadlet, null, toadlet.path(), true, false);
361                         }
362                 }
363         }
364
365         /**
366          * Unregisters all toadlets.
367          */
368         private void unregisterToadlets() {
369                 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
370                 for (PageToadlet pageToadlet : pageToadlets) {
371                         toadletContainer.unregister(pageToadlet);
372                 }
373                 toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Name");
374         }
375
376         /**
377          * Creates a {@link Reader} from the {@link InputStream} for the resource
378          * with the given name.
379          *
380          * @param resourceName
381          *            The name of the resource
382          * @return A {@link Reader} for the resource
383          */
384         private Reader createReader(String resourceName) {
385                 try {
386                         return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8");
387                 } catch (UnsupportedEncodingException uee1) {
388                         return null;
389                 }
390         }
391
392         //
393         // CORELISTENER METHODS
394         //
395
396         /**
397          * {@inheritDoc}
398          */
399         @Override
400         public void rescuingSone(Sone sone) {
401                 rescuingSonesNotification.add(sone);
402                 notificationManager.addNotification(rescuingSonesNotification);
403         }
404
405         /**
406          * {@inheritDoc}
407          */
408         @Override
409         public void rescuedSone(Sone sone) {
410                 rescuingSonesNotification.remove(sone);
411                 sonesRescuedNotification.add(sone);
412                 notificationManager.addNotification(sonesRescuedNotification);
413         }
414
415         /**
416          * {@inheritDoc}
417          */
418         @Override
419         public void newSoneFound(Sone sone) {
420                 newSoneNotification.add(sone);
421                 notificationManager.addNotification(newSoneNotification);
422         }
423
424         /**
425          * {@inheritDoc}
426          */
427         @Override
428         public void newPostFound(Post post) {
429                 newPostNotification.add(post);
430                 notificationManager.addNotification(newPostNotification);
431         }
432
433         /**
434          * {@inheritDoc}
435          */
436         @Override
437         public void newReplyFound(Reply reply) {
438                 if (reply.getPost().getSone() == null) {
439                         return;
440                 }
441                 newReplyNotification.add(reply);
442                 notificationManager.addNotification(newReplyNotification);
443         }
444
445         /**
446          * {@inheritDoc}
447          */
448         @Override
449         public void markSoneKnown(Sone sone) {
450                 newSoneNotification.remove(sone);
451         }
452
453         /**
454          * {@inheritDoc}
455          */
456         @Override
457         public void markPostKnown(Post post) {
458                 newPostNotification.remove(post);
459         }
460
461         /**
462          * {@inheritDoc}
463          */
464         @Override
465         public void markReplyKnown(Reply reply) {
466                 newReplyNotification.remove(reply);
467         }
468
469         /**
470          * Template provider implementation that uses
471          * {@link WebInterface#createReader(String)} to load templates for
472          * inclusion.
473          *
474          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
475          */
476         private class ClassPathTemplateProvider implements TemplateProvider {
477
478                 /** The template factory. */
479                 @SuppressWarnings("hiding")
480                 private final TemplateFactory templateFactory;
481
482                 /**
483                  * Creates a new template provider that locates templates on the
484                  * classpath.
485                  *
486                  * @param templateFactory
487                  *            The template factory to create the templates
488                  */
489                 public ClassPathTemplateProvider(TemplateFactory templateFactory) {
490                         this.templateFactory = templateFactory;
491                 }
492
493                 /**
494                  * {@inheritDoc}
495                  */
496                 @Override
497                 @SuppressWarnings("synthetic-access")
498                 public Template getTemplate(String templateName) {
499                         Reader templateReader = createReader("/templates/" + templateName);
500                         if (templateReader == null) {
501                                 return null;
502                         }
503                         Template template = templateFactory.createTemplate(templateReader);
504                         try {
505                                 template.parse();
506                         } catch (TemplateException te1) {
507                                 logger.log(Level.WARNING, "Could not parse template “" + templateName + "” for inclusion!", te1);
508                         }
509                         return template;
510                 }
511
512         }
513
514 }