1 package org.apache.turbine.services.template;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.io.File;
58
59 import java.util.HashMap;
60 import java.util.Hashtable;
61
62 import org.apache.turbine.modules.ScreenLoader;
63 import org.apache.turbine.modules.LayoutLoader;
64 import org.apache.turbine.modules.NavigationLoader;
65
66 import org.apache.turbine.util.RunData;
67
68 import org.apache.turbine.services.TurbineBaseService;
69 import org.apache.turbine.services.InitializationException;
70 import org.apache.turbine.services.resources.TurbineResources;
71 import org.apache.turbine.services.servlet.TurbineServlet;
72
73 import org.apache.commons.configuration.Configuration;
74
75
76 /***
77 * This service provides a method for mapping templates to their
78 * appropriate Screens or Navigations. It also allows templates to
79 * define a layout/navigations/screen modularization within the
80 * template structure. It also performs caching if turned on in the
81 * properties file.
82 *
83 * Since everything is keyed off the template variable,
84 * if data.getParameters().getString("template") returns
85 * /about_us/directions/driving.vm, the search for the
86 * Screen class is as follows (in order):
87 *
88 * 1. about_us.directions.Driving
89 * 2. about_us.directions.Default
90 * 3. about_us.Default
91 * 4. Default
92 * 5. VelocityScreen
93 *
94 * If the template variable does not exist, then VelocityScreen will be
95 * executed and templates/screens/index.vm will be executed.
96 * If index.vm is not found or if the template is invalid or Velocity
97 * execution throws an exception of any reason, then
98 * templates/screens/error.vm will be executed.
99 *
100 * For the Layouts and Navigations, the following paths will be
101 * searched in the layouts and navigations template
102 * subdirectories (in order):
103 *
104 * 1./about_us/directions/driving.vm
105 * 2./about_us/directions/default.vm
106 * 3./about_us/default.vm
107 * 4./default.vm
108 *
109 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
110 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
111 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
112 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
113 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
114 * @version $Id: TurbineTemplateService.java,v 1.4 2002/04/16 22:07:09 kschrader Exp $
115 */
116 public class TurbineTemplateService extends TurbineBaseService
117 implements TemplateService
118 {
119 /***
120 * The default file extension used as a registry key when a
121 * template's file extension cannot be determined.
122 */
123 protected static final String NO_FILE_EXT = "";
124
125 /***
126 * The keys of template objects provided by the service.
127 */
128 protected static final int PAGE_KEY = 0;
129 protected static final int SCREEN_KEY = 1;
130 protected static final int LAYOUT_KEY = 2;
131 protected static final int NAVIGATION_KEY = 3;
132 protected static final int LAYOUT_TEMPLATE_KEY = 4;
133 protected static final int SCREEN_TEMPLATE_KEY = 5;
134
135 /***
136 * The properties for default template object names.
137 */
138 private String[] defaultNameProperties = new String[]
139 {
140 TemplateEngineService.DEFAULT_PAGE,
141 TemplateEngineService.DEFAULT_SCREEN,
142 TemplateEngineService.DEFAULT_LAYOUT,
143 TemplateEngineService.DEFAULT_NAVIGATION,
144 TemplateEngineService.DEFAULT_LAYOUT_TEMPLATE
145 };
146
147 /***
148 * The hashtables used to cache template object names.
149 */
150 private Hashtable[] templateNameCache = new Hashtable[6];
151
152 /***
153 * Flag set if cache is to be used.
154 */
155 private boolean useCache = false;
156
157 /***
158 * Default extension for templates.
159 */
160 private String defaultExtension;
161
162 /***
163 * Default template with the default extension.
164 */
165 private String defaultTemplate;
166
167 /***
168 * The mappings of template file extensions to {@link
169 * org.apache.turbine.services.template.TemplateEngineService}
170 * implementations. Implementing template engines can locate
171 * templates within the capability of any resource loaders they
172 * may posses, and other template engines are stuck with file
173 * based template hierarchy only.
174 */
175 private HashMap templateEngineRegistry;
176
177 public TurbineTemplateService()
178 {
179 }
180
181 /***
182 * Called the first time the Service is used.
183 *
184 * @exception InitializationException.
185 */
186 public void init() throws InitializationException
187 {
188 initTemplate();
189 setInit(true);
190 }
191
192 /***
193 * Get the default template name extension specified
194 * in the template service properties.
195 *
196 * @return The default the extension.
197 */
198 public String getDefaultExtension()
199 {
200 return defaultExtension;
201 }
202
203 /***
204 * Get the default page module name of the template engine
205 * service corresponding to the default template name extension.
206 *
207 * @return The default page module name.
208 */
209 public String getDefaultPage()
210 {
211 return getDefaultPageName(defaultTemplate);
212 }
213
214 /***
215 * Get the default screen module name of the template engine
216 * service corresponding to the default template name extension.
217 *
218 * @return The default screen module name.
219 */
220 public String getDefaultScreen()
221 {
222 return getDefaultScreenName(defaultTemplate);
223 }
224
225 /***
226 * Get the default layout module name of the template engine
227 * service corresponding to the default template name extension.
228 *
229 * @return The default layout module name.
230 */
231 public String getDefaultLayout()
232 {
233 return getDefaultLayoutName(defaultTemplate);
234 }
235
236 /***
237 * Get the default navigation module name of the template engine
238 * service corresponding to the default template name extension.
239 *
240 * @return The default navigation module name.
241 */
242 public String getDefaultNavigation()
243 {
244 return getDefaultNavigationName(defaultTemplate);
245 }
246
247 /***
248 * Get the default layout template name of the template engine
249 * service corresponding to the default template name extension.
250 *
251 * @return The default layout template name.
252 */
253 public String getDefaultLayoutTemplate()
254 {
255 return getDefaultLayoutTemplateName(defaultTemplate);
256 }
257
258 /***
259 * Get the default page module name of the template engine
260 * service corresponding to the template name extension of
261 * the named template.
262 *
263 * @param template The template name.
264 * @return The default page module name.
265 */
266 public String getDefaultPageName(String template)
267 {
268 return getDefaultModuleName(template,PAGE_KEY);
269 }
270
271 /***
272 * Get the default screen module name of the template engine
273 * service corresponding to the template name extension of
274 * the named template.
275 *
276 * @param template The template name.
277 * @return The default screen module name.
278 */
279 public String getDefaultScreenName(String template)
280 {
281 return getDefaultModuleName(template,SCREEN_KEY);
282 }
283
284 /***
285 * Get the default layout module name of the template engine
286 * service corresponding to the template name extension of
287 * the named template.
288 *
289 * @param template The template name.
290 * @return The default layout module name.
291 */
292 public String getDefaultLayoutName(String template)
293 {
294 return getDefaultModuleName(template,LAYOUT_KEY);
295 }
296
297 /***
298 * Get the default navigation module name of the template engine
299 * service corresponding to the template name extension of
300 * the named template.
301 *
302 * @param template The template name.
303 * @return The default navigation module name.
304 */
305 public String getDefaultNavigationName(String template)
306 {
307 return getDefaultModuleName(template,NAVIGATION_KEY);
308 }
309
310 /***
311 * Get the default layout template name of the template engine
312 * service corresponding to the template name extension of
313 * the named template.
314 *
315 * @param template The template name.
316 * @return The default layout template name.
317 */
318 public String getDefaultLayoutTemplateName(String template)
319 {
320 String layoutTemplate =
321 getDefaultModuleName(template,LAYOUT_TEMPLATE_KEY);
322 if ((layoutTemplate != null) &&
323 (layoutTemplate.indexOf('.') < 0))
324 {
325 int dotIndex = template.lastIndexOf('.');
326 layoutTemplate += dotIndex >= 0 ?
327 template.substring(dotIndex) : '.' + defaultExtension;
328 }
329 return layoutTemplate;
330 }
331
332 /***
333 * Find the default page module name for the given request.
334 *
335 * @param data The encapsulation of the request to retrieve the
336 * default page for.
337 * @return The default page module name.
338 */
339 public String getDefaultPageName(RunData data)
340 {
341 String template = data.getParameters().get("template");
342 return template != null ?
343 getDefaultPageName(template) : getDefaultPage();
344 }
345
346 /***
347 * Find the default layout module name for the given request.
348 *
349 * @param data The encapsulation of the request to retrieve the
350 * default layout for.
351 * @return The default layout module name.
352 */
353 public String getDefaultLayoutName(RunData data)
354 {
355 String template = data.getParameters().get("template");
356 return template != null ?
357 getDefaultLayoutName(template) : getDefaultLayout();
358 }
359
360 /***
361 * Locate and return the name of the screen module to be used
362 * with the named screen template.
363 *
364 * @param template The screen template name.
365 * @return The found screen module name.
366 * @exception Exception, a generic exception.
367 */
368 public String getScreenName(String template)
369 throws Exception
370 {
371 return getCachedName(template,SCREEN_KEY);
372 }
373
374 /***
375 * Locate and return the name of the layout module to be used
376 * with the named layout template.
377 *
378 * @param template The layout template name.
379 * @return The found layout module name.
380 * @exception Exception, a generic exception.
381 */
382 public String getLayoutName(String template)
383 throws Exception
384 {
385 return getCachedName(template,LAYOUT_KEY);
386 }
387
388 /***
389 * Locate and return the name of the navigation module to be used
390 * with the named navigation template.
391 *
392 * @param template The navigation template name.
393 * @return The found navigation module name.
394 * @exception Exception, a generic exception.
395 */
396 public String getNavigationName(String template)
397 throws Exception
398 {
399 return getCachedName(template,NAVIGATION_KEY);
400 }
401
402 /***
403 * Locate and return the name of the screen template corresponding
404 * to the given template name parameter.
405 *
406 * @param template The template name parameter.
407 * @return The found screen template name.
408 * @exception Exception, a generic exception.
409 */
410 public String getScreenTemplateName(String template)
411 throws Exception
412 {
413 return getCachedName(template,SCREEN_TEMPLATE_KEY);
414 }
415
416 /***
417 * Locate and return the name of the layout template corresponding
418 * to the given screen template name parameter.
419 *
420 * @param template The template name parameter.
421 * @return The found screen template name.
422 * @exception Exception, a generic exception.
423 */
424 public String getLayoutTemplateName(String template)
425 throws Exception
426 {
427 return getCachedName(template,LAYOUT_TEMPLATE_KEY);
428 }
429
430 /***
431 * Translates the supplied template paths into their Turbine-canonical
432 * equivalent (probably absolute paths).
433 *
434 * @param templatePaths An array of template paths.
435 * @return An array of translated template paths.
436 */
437 public String[] translateTemplatePaths(String[] templatePaths)
438 {
439 for (int i = 0; i < templatePaths.length; i++)
440 {
441 templatePaths[i] = TurbineServlet.getRealPath(templatePaths[i]);
442 }
443 return templatePaths;
444 }
445
446 /***
447 * Delegates to the appropriate {@link
448 * org.apache.turbine.services.template.TemplateEngineService} to
449 * check the existance of the specified template.
450 *
451 * @param template The template to check for the existance of.
452 * @param templatePaths The paths to check for the template.
453 */
454 public boolean templateExists(String template,
455 String[] templatePaths)
456 {
457 for (int i = 0; i < templatePaths.length; i++)
458 {
459 if (new File(templatePaths[i],template).exists())
460 {
461 return true;
462 }
463 }
464 return false;
465 }
466
467 /***
468 * Registers the provided template engine for use by the
469 * <code>TemplateService</code>.
470 *
471 * @param service The <code>TemplateEngineService</code> to register.
472 */
473 public synchronized void registerTemplateEngineService(TemplateEngineService service)
474 {
475 /*
476 * Clone the registry to write to non-sync'd
477 * Map implementations.
478 */
479 HashMap registry = templateEngineRegistry != null ?
480 (HashMap) templateEngineRegistry.clone() : new HashMap();
481
482 String[] exts = service.getAssociatedFileExtensions();
483
484 for (int i = 0; i < exts.length; i++)
485 {
486 registry.put(exts[i], service);
487 }
488 templateEngineRegistry = registry;
489 }
490
491 /***
492 * The {@link org.apache.turbine.services.template.TemplateEngineService}
493 * associated with the specified template's file extension.
494 *
495 * @param template The template name.
496 * @return The template engine service.
497 */
498 protected TemplateEngineService getTemplateEngineService(String template)
499 {
500 HashMap registry = templateEngineRegistry;
501 if (registry != null && template != null)
502 {
503 int dotIndex = template.lastIndexOf('.');
504 String ext = dotIndex == -1 ?
505 defaultExtension : template.substring(dotIndex + 1);
506 return (TemplateEngineService) registry.get(ext);
507 }
508 else
509 {
510 return null;
511 }
512 }
513
514 /***
515 * Get the default module name of the template engine
516 * service corresponding to the template name extension of
517 * the named template.
518 *
519 * @param template The template name.
520 * @param key The module type key.
521 * @return The default page module name.
522 */
523 protected String getDefaultModuleName(String template,
524 int key)
525 {
526 TemplateEngineService tes = getTemplateEngineService(template);
527 return tes != null ?
528 (String) tes.getTemplateEngineServiceConfiguration().
529 get(defaultNameProperties[key]) : null;
530 }
531
532 /***
533 * Get the cached template object name.
534 * If caching is not in use or the name is not in the cache,
535 * try to find the name from the template directories.
536 *
537 * @param template The template name.
538 * @param key The object type key.
539 * @return The cached name.
540 * @exception Exception, a generic exception.
541 */
542 protected String getCachedName(String template,
543 int key)
544 throws Exception
545 {
546 /*
547 * Add a default extension if missing.
548 */
549 if (template.indexOf('.') < 0)
550 {
551 template += '.' + defaultExtension;
552 }
553
554 /*
555 * Check the cache first.
556 */
557 String found;
558 if (useCache)
559 {
560 found = (String) templateNameCache[key].get(template);
561 if (found != null)
562 {
563 return found;
564 }
565 }
566
567 /*
568 * Not in the cache, try to find it.
569 */
570 switch (key)
571 {
572 case SCREEN_TEMPLATE_KEY:
573 found = getParsedScreenTemplateName(template);
574 break;
575
576 case LAYOUT_TEMPLATE_KEY:
577 found = getParsedLayoutTemplateName(template);
578 break;
579
580 default:
581 found = getParsedModuleName(template,key);
582 }
583
584 /*
585 * Put the found name to the cache.
586 */
587 if (useCache)
588 {
589 templateNameCache[key].put(template,found);
590 }
591
592 return found;
593 }
594
595 /***
596 * Get the parsed module name for the specified template.
597 *
598 * @param template The template name.
599 * @param key The module type key.
600 * @return The parsed module name.
601 * @exception Exception, a generaic exception.
602 */
603 protected String getParsedModuleName(String template,
604 int key)
605 throws Exception
606 {
607 /*
608 * Parse the template name and change it into a package.
609 */
610 StringBuffer pckage = new StringBuffer();
611 int i = parseTemplatePath(template,pckage);
612 if (pckage.charAt(0) == '/')
613 {
614 pckage.deleteCharAt(0);
615 i--;
616 }
617 if (i >= 0)
618 {
619 for (int j = 0; j <= i; j++)
620 {
621 if (pckage.charAt(j) == '/')
622 {
623 pckage.setCharAt(j,'.');
624 }
625 }
626 }
627
628 /*
629 * Remove a possible file extension.
630 */
631 for (int j = i + 1; j < pckage.length(); j++)
632 {
633 if (pckage.charAt(j) == '.')
634 {
635 pckage.delete(j,pckage.length());
636 break;
637 }
638 }
639
640 /*
641 * Try first an exact match for a module having the same
642 * name as the input template, traverse then upper level
643 * packages to find a default module named Default.
644 */
645 int j = 9999;
646 String module;
647 while (j-- > 0)
648 {
649 module = pckage.toString();
650 try
651 {
652 switch (key)
653 {
654 case SCREEN_KEY:
655 ScreenLoader.getInstance().getInstance(module);
656 return module;
657
658 case LAYOUT_KEY:
659 LayoutLoader.getInstance().getInstance(module);
660 return module;
661
662 case NAVIGATION_KEY:
663 NavigationLoader.getInstance().getInstance(module);
664 return module;
665 }
666 }
667 catch (Exception x)
668 {
669 }
670
671 pckage.setLength(i + 1);
672 if (i > 0)
673 {
674 /*
675 * We have still packages to traverse.
676 */
677 for (i = pckage.length() - 2; i >= 0; i--)
678 {
679 if (pckage.charAt(i) == '.')
680 {
681 break;
682 }
683 }
684 }
685 else if (j > 0)
686 {
687 /*
688 * Only the main level left.
689 */
690 j = 1;
691 }
692 pckage.append("Default");
693 }
694
695 /*
696 * Not found, return the default module name.
697 */
698 return getDefaultModuleName(template,key);
699 }
700
701 /***
702 * Get the parsed screen template name for the specified template.
703 *
704 * @param template The template name.
705 * @return The parsed screen template name.
706 * @exception Exception, a generic exception.
707 */
708 protected String getParsedScreenTemplateName(String template)
709 throws Exception
710 {
711 /*
712 * Parse the template name.
713 */
714 StringBuffer path = new StringBuffer();
715 parseTemplatePath(template,path);
716 if (path.charAt(0) != '/')
717 {
718 path.insert(0,'/');
719 }
720 path.insert(0,"screens");
721
722 /* Let the template engine service to check its existance. */
723 TemplateEngineService tes = getTemplateEngineService(template);
724 if ((tes == null) || !tes.templateExists(path.toString()))
725 {
726 throw new Exception(
727 "Screen template '" + template + "' not found");
728 }
729 return path.substring(7);
730 }
731
732 /***
733 * Get the parsed layout template name for the specified template.
734 *
735 * @param template The template name.
736 * @return The parsed layout template name.
737 * @exception Exception, a generic exception.
738 */
739 protected String getParsedLayoutTemplateName(String template)
740 throws Exception
741 {
742 /*
743 * Parse the template name.
744 */
745 StringBuffer path = new StringBuffer();
746 int i = parseTemplatePath(template,path);
747 if (path.charAt(0) != '/')
748 {
749 path.insert(0,'/');
750 i++;
751 }
752 path.insert(0,"layouts");
753 i += 7;
754
755 /*
756 * Try first an exact match for a layout template having the same
757 * name as the input template, traverse then upper level
758 * directories to find the default layout template.
759 */
760 TemplateEngineService tes = getTemplateEngineService(template);
761 if (tes == null)
762 {
763 throw new Exception(
764 "Layout template '" + template + "' not found");
765 }
766
767 String defaultLayout = getDefaultLayoutTemplateName(template);
768 if (defaultLayout != null)
769 {
770 if (defaultLayout.length() == 0)
771 {
772 defaultLayout = null;
773 }
774 else if (defaultLayout.charAt(0) != '/')
775 {
776 defaultLayout = '/' + defaultLayout;
777 }
778 }
779
780 int j = 9999;
781 String layoutTemplate;
782 while (j-- > 0)
783 {
784 layoutTemplate = path.toString();
785
786 if (tes.templateExists(layoutTemplate))
787 {
788 return layoutTemplate.substring(7);
789 }
790
791 if (defaultLayout == null)
792 {
793 throw new Exception(
794 "Layout template '" + template + "' not found");
795 }
796
797 path.setLength(i);
798 if (i > 8)
799 {
800 /*
801 * We have still directories to traverse.
802 */
803 for (i = path.length() - 2; i >= 8; i--)
804 {
805 if (path.charAt(i) == '/')
806 {
807 break;
808 }
809 }
810 }
811 else if (j > 0)
812 {
813 /*
814 * Only the main level left.
815 */
816 j = 1;
817 }
818 path.append(defaultLayout);
819 }
820
821 /*
822 * Not found, return the default layout
823 * template as such.
824 */
825 return defaultLayout;
826 }
827
828 /***
829 * Parse the template name collected from URL parameters or
830 * template context to a path name. Double slashes are changed
831 * into single ones and commas used as path delemiters in
832 * URL parameters are changed into slashes. Empty names or
833 * names without a file part are not accepted.
834 *
835 * @param template The template name.
836 * @param buffer A buffer for the result.
837 * @return The index of the separator between the path and the name.
838 * @exception Exception Malformed template name.
839 */
840 private int parseTemplatePath(String template,
841 StringBuffer buffer)
842 throws Exception
843 {
844 char c;
845 int j = 0;
846 int ind = -1;
847 buffer.setLength(0);
848 buffer.append(template);
849 int len = buffer.length();
850 while (j < len)
851 {
852 c = buffer.charAt(j);
853 if (c == ',')
854 {
855 c = '/';
856 buffer.setCharAt(j,c);
857 }
858 if (c == '/')
859 {
860 ind = j;
861 if (j < (len - 1))
862 {
863 c = buffer.charAt(j + 1);
864 if ((c == '/') ||
865 (c == ','))
866 {
867 buffer.deleteCharAt(j);
868 len--;
869 continue;
870 }
871 }
872 }
873 j++;
874 }
875 if ((len == 0) ||
876 (ind >= (len - 1)))
877 {
878 throw new Exception(
879 "Syntax error in template name '" + template + '\'');
880 }
881 return ind;
882 }
883
884 /***
885 * Initialize the template service.
886 */
887 private void initTemplate()
888 {
889 /*
890 * Get the configuration for the template service.
891 */
892 Configuration config = getConfiguration();
893
894 /*
895 * Get the default extension to use if nothing else is applicable.
896 */
897 defaultExtension = config.getString("default.extension",NO_FILE_EXT);
898 defaultTemplate = "Default." + defaultExtension;
899
900 /*
901 * Check to see if we are going to be caching modules.
902 */
903 useCache = TurbineResources.getBoolean("module.cache",true);
904
905 if (useCache)
906 {
907 int screenSize = config.getInt("screen.cache.size",5);
908 int screenTemplateSize = config.getInt("screen.cache.size",50);
909 int layoutSize = config.getInt("layout.cache.size",5);
910 int layoutTemplateSize = config.getInt("layout.cache.size",5);
911 int navigationSize = config.getInt("navigation.cache.size",10);
912
913 /*
914 * Create hashtables for each object type,
915 * the first one for pages is not used.
916 */
917 templateNameCache[PAGE_KEY] = null;
918 templateNameCache[SCREEN_KEY] =
919 new Hashtable((int) (1.25 * screenSize) + 1);
920 templateNameCache[SCREEN_TEMPLATE_KEY] =
921 new Hashtable((int) (1.25 * screenTemplateSize) + 1);
922 templateNameCache[LAYOUT_KEY] =
923 new Hashtable((int) (1.25 * layoutSize) + 1);
924 templateNameCache[LAYOUT_TEMPLATE_KEY] =
925 new Hashtable((int) (1.25 * layoutTemplateSize) + 1);
926 templateNameCache[NAVIGATION_KEY] =
927 new Hashtable((int) (1.25 * navigationSize) + 1);
928 }
929 }
930 }
This page was automatically generated by Maven