1package com.nwalsh.saxon; 2 3import org.xml.sax.*; 4import com.icl.saxon.output.*; 5import com.icl.saxon.Controller; 6import com.icl.saxon.om.*; 7import javax.xml.transform.TransformerException; 8import com.icl.saxon.expr.FragmentValue; 9import com.icl.saxon.tree.AttributeCollection; 10 11/** 12 * <p>Saxon extension to scan the column widths in a result tree fragment.</p> 13 * 14 * <p>$Id: ColumnUpdateEmitter.java,v 1.2 2006/04/27 08:26:47 xmldoc Exp $</p> 15 * 16 * <p>Copyright (C) 2000 Norman Walsh.</p> 17 * 18 * <p>This class provides a 19 * <a href="http://saxon.sourceforge.net/">Saxon 6.*</a> 20 * implementation to scan the column widths in a result tree 21 * fragment.</p> 22 * 23 * <p>The general design is this: the stylesheets construct a result tree 24 * fragment for some colgroup environment. That result tree fragment 25 * is "replayed" through the ColumnUpdateEmitter; the ColumnUpdateEmitter watches 26 * the cols go by and extracts the column widths that it sees. These 27 * widths are then made available.</p> 28 * 29 * <p><b>Change Log:</b></p> 30 * <dl> 31 * <dt>1.0</dt> 32 * <dd><p>Initial release.</p></dd> 33 * </dl> 34 * 35 * @author Norman Walsh 36 * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a> 37 * 38 * @version $Id: ColumnUpdateEmitter.java,v 1.2 2006/04/27 08:26:47 xmldoc Exp $ 39 * 40 */ 41public class ColumnUpdateEmitter extends CopyEmitter { 42 /** The number of columns seen. */ 43 protected int numColumns = 0; 44 protected String width[] = null; 45 protected NamePool namePool = null; 46 47 /** The FO namespace name. */ 48 protected static String foURI = "http://www.w3.org/1999/XSL/Format"; 49 50 /** Construct a new ColumnUpdateEmitter. */ 51 public ColumnUpdateEmitter(Controller controller, 52 NamePool namePool, 53 String width[]) { 54 super(controller, namePool); 55 numColumns = 0; 56 this.width = width; 57 this.namePool = namePool; 58 } 59 60 /** Examine for column info. */ 61 public void startElement(int nameCode, 62 org.xml.sax.Attributes attributes, 63 int[] namespaces, int nscount) 64 throws TransformerException { 65 66 int thisFingerprint = namePool.getFingerprint(nameCode); 67 int colFingerprint = namePool.getFingerprint("", "col"); 68 int foColFingerprint = namePool.getFingerprint(foURI, "table-column"); 69 70 if (thisFingerprint == colFingerprint) { 71 AttributeCollection attr = new AttributeCollection(namePool, attributes); 72 int widthFingerprint = namePool.getFingerprint("", "width"); 73 74 if (attr.getValueByFingerprint(widthFingerprint) == null) { 75 attr.addAttribute(widthFingerprint, "CDATA", width[numColumns++]); 76 } else { 77 attr.setAttribute(widthFingerprint, "CDATA", width[numColumns++]); 78 } 79 attributes = attr; 80 } else if (thisFingerprint == foColFingerprint) { 81 AttributeCollection attr = new AttributeCollection(namePool, attributes); 82 int widthFingerprint = namePool.getFingerprint("", "column-width"); 83 84 if (attr.getValueByFingerprint(widthFingerprint) == null) { 85 attr.addAttribute(widthFingerprint, "CDATA", width[numColumns++]); 86 } else { 87 attr.setAttribute(widthFingerprint, "CDATA", width[numColumns++]); 88 } 89 attributes = attr; 90 } 91 92 rtfEmitter.startElement(nameCode, attributes, namespaces, nscount); 93 } 94} 95 96 97