1 package de.webman.template.xslt; 2 3 import java.util.Enumeration ; 4 import java.io.*; 5 import javax.xml.parsers.DocumentBuilder ; 6 import javax.xml.parsers.DocumentBuilderFactory ; 7 import javax.xml.transform.Transformer ; 8 import javax.xml.transform.dom.DOMSource ; 9 import javax.xml.transform.stream.StreamResult ; 10 import com.teamkonzept.lib.*; 11 import com.teamkonzept.lib.templates.*; 12 import de.webman.template.jsp.*; 13 import de.webman.util.xslt.XSLTTemplateCache; 14 import org.w3c.dom.Document ; 15 import org.w3c.dom.Element ; 16 import org.apache.log4j.Category; 17 import javax.servlet.http.HttpServletRequest ; 18 19 27 public class XSLTTemplate 28 implements TemplateBasic, 29 TemplateTypes 30 31 { 32 33 36 private static Category cat = Category.getInstance(XSLTTemplate.class); 37 38 39 private String name; 40 41 42 private String text; 43 44 45 private String rootDir; 46 47 private DOMTemplateData data; 48 49 52 private String path = null; 53 54 62 public XSLTTemplate (String _docRoot, 63 String _name, 64 boolean _editor) 65 throws TKTemplateSyntaxException 66 { 67 try 68 { 69 rootDir = _docRoot; 70 name = _name; 71 this.path = rootDir + File.separator; 73 if (_editor) 74 path += TemplateUtils.getWebmanTemplateDirectory() + File.separator; 75 else 76 path += TemplateUtils.getGenerationDirectory(); 77 path += name; 78 79 data = new DOMTemplateData(); 80 } 81 catch (Exception e) 82 { 83 cat.error("XSLT constructor: " , e); 84 } 85 } 86 87 public void setOriginalRequest(HttpServletRequest request) 88 { 89 } 90 91 public String getType() 92 { 93 return JSP_TEMPLATE; 94 } 95 96 void init() throws TKTemplateSyntaxException 97 { 98 } 99 100 103 public void set( TKHashtable aSubst ) 104 { 105 data.set(aSubst); 106 } 107 108 public void set( String key, Object val ) 109 { 110 data.set(key, val); 111 } 112 113 protected void resetData() 114 { 115 try 116 { 117 data = new DOMTemplateData(); 118 } 119 catch (Exception e) 120 { 121 cat.error("Unable to reset Data", e); 122 } 123 } 124 125 public synchronized void sendData (Element node, PrintWriter out) 126 { 127 try 128 { 129 XSLTTemplateCache.getTransformer(this.path) 131 .transform(new DOMSource (node), new StreamResult (out)); 132 133 out.flush(); 135 } 136 catch (Exception e) 137 { 138 cat.error("sendData: " + e.getMessage(), e); 139 } 140 finally 141 { 142 resetData(); 143 } 144 } 145 146 153 public String getText() 154 { 155 return text; 156 } 157 158 165 public void printTemplate( PrintStream out ) 166 { 167 sendData(data.getRoot(), new PrintWriter(out)); 168 } 169 170 177 public void printTemplate( Writer writer ) throws IOException 178 { 179 sendData(data.getRoot(), new PrintWriter(writer)); 180 } 181 182 195 public void printTemplate(String file) throws IOException 196 { 197 FileWriter w = new FileWriter(file); 198 sendData(data.getRoot(), new PrintWriter(w)); 199 } 200 201 208 public void printTemplate() 209 { 210 throw new RuntimeException ("Method not implemented !"); 211 } 212 213 public DOMTemplateData getDOMData() 214 { 215 return data; 216 } 217 218 227 public void doTagSubstitution() throws TKTemplateSyntaxException 228 { 229 doMainSubstitutions(); 230 } 231 232 238 public void doMainSubstitutions() throws TKTemplateSyntaxException 239 { 240 244 } 245 246 } 247 | Popular Tags |