1 package com.icl.saxon; 2 import com.icl.saxon.om.NamePool; 3 import com.icl.saxon.tree.TreeBuilder; 4 import com.icl.saxon.tree.DocumentImpl; 5 import com.icl.saxon.style.StyleNodeFactory; 6 7 import javax.xml.transform.*; 8 import javax.xml.transform.sax.TemplatesHandler ; 9 10 import org.xml.sax.*; 11 12 13 20 21 public class TemplatesHandlerImpl extends ContentEmitter implements TemplatesHandler { 22 23 TransformerFactoryImpl factory; 24 TreeBuilder builder; 25 Templates templates; 26 String systemId; 27 28 33 34 protected TemplatesHandlerImpl(TransformerFactoryImpl factory) { 35 NamePool pool = NamePool.getDefaultNamePool(); 36 setNamePool(pool); 37 this.factory = factory; 38 builder = new TreeBuilder(); 39 builder.setNamePool(pool); 40 StyleNodeFactory nodeFactory = new StyleNodeFactory(pool); 41 43 StylesheetStripper styleStripper = new StylesheetStripper(); 44 styleStripper.setStylesheetRules(pool); 45 46 builder = new TreeBuilder(); 47 builder.setNamePool(pool); 48 builder.setStripper(styleStripper); 49 builder.setNodeFactory(nodeFactory); 50 builder.setDiscardCommentsAndPIs(true); 51 builder.setLineNumbering(true); 52 53 this.setEmitter(styleStripper); 54 styleStripper.setUnderlyingEmitter(builder); 55 56 } 57 58 61 62 public Templates getTemplates() { 63 if (templates==null) { 64 DocumentImpl doc = (DocumentImpl)builder.getCurrentDocument(); 65 if (doc==null) { 66 return null; 67 } 68 PreparedStyleSheet sheet = new PreparedStyleSheet(factory); 69 try { 70 sheet.setStyleSheetDocument(doc); 71 templates = sheet; 72 } catch (TransformerConfigurationException tce) { 73 System.err.println(tce.getMessage()); 75 return null; 76 } 77 } 78 79 return templates; 80 } 81 82 85 86 public void setSystemId(String url) { 87 systemId = url; 88 builder.setSystemId(url); 89 } 90 91 94 95 public String getSystemId() { 96 return systemId; 97 } 98 99 } 100 101 | Popular Tags |