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