1 package com.teamkonzept.lib; 2 3 import java.io.*; 4 import java.util.Hashtable ; 5 import com.teamkonzept.lib.*; 6 import com.teamkonzept.lib.templates.*; 7 import de.webman.template.jsp.*; 8 import de.webman.template.xslt.*; 9 import com.teamkonzept.web.TKHTMLTemplate; 10 11 17 public class TemplateUtils 18 implements TemplateTypes 19 { 20 21 24 private static Hashtable cache = new Hashtable (); 25 26 29 private static final String TOP_LEVEL_GENDIR = "html_templates"; 30 31 34 private static final String SECOND_LEVEL_GENDIR = "templates"; 35 36 39 private static final String WEBMAN_TEMPLATE_DIR = "templates"; 40 41 46 public static String getWebmanTemplateDirectory () 47 { 48 return WEBMAN_TEMPLATE_DIR; 49 } 50 51 56 public static String getGenerationDirectory () 57 { 58 return TOP_LEVEL_GENDIR + File.separator + SECOND_LEVEL_GENDIR + File.separator; 59 } 60 61 66 public static String getTopLevelGenDir () 67 { 68 return TOP_LEVEL_GENDIR; 69 } 70 71 76 public static String getSecondLevelGenDir () 77 { 78 return SECOND_LEVEL_GENDIR; 79 } 80 81 91 public static TemplateBasic getTemplate (String name, 92 String root, 93 boolean editor) 94 throws TKTemplateSyntaxException, FileNotFoundException 95 { 96 if (name.toUpperCase().endsWith(JSP_TEMPLATE) || name.toUpperCase().endsWith(XSLT_TEMPLATE)) 97 { 98 int index = root.indexOf(TOP_LEVEL_GENDIR); 100 if ( index != -1) 101 { 102 root = root.substring(0, index); 103 } 104 index = root.indexOf("file:"); 105 if ( index != -1) 106 { 107 root = root.substring(5, root.length()); 108 } 109 String key = name + new Boolean (editor).toString(); 110 TemplateBasic t = (TemplateBasic)cache.get(key); 111 if (t != null) 112 { 113 return t; 114 } 115 if (name.toUpperCase().endsWith(JSP_TEMPLATE) ) 116 { 117 t = new JSPTemplate(root, name, editor); 118 cache.put(key, t); 119 return t; 120 } 121 else 122 { 123 t = new XSLTTemplate(root, name, editor); 124 cache.put(key, t); 125 return t; 126 } 127 } 128 129 if (name.toUpperCase().endsWith(TK_TEMPLATE)) 130 { 131 return new TKHTMLTemplate(root + name); 132 } 133 134 return null; 135 } 136 137 } 138 | Popular Tags |