001: package com.nwalsh.saxon;
002:
003: import org.xml.sax.*;
004: import com.icl.saxon.output.*;
005: import com.icl.saxon.Controller;
006: import com.icl.saxon.om.*;
007: import javax.xml.transform.TransformerException;
008: import com.icl.saxon.expr.FragmentValue;
009: import com.icl.saxon.tree.AttributeCollection;
010:
011: /**
012: * <p>Saxon extension to scan the column widthsin a result tree fragment.</p>
013: *
014: * <p>$Id: ColumnUpdateEmitter.java,v 1.4 2005-08-30 08:14:58 draganr Exp $</p>
015: *
016: * <p>Copyright (C) 2000 Norman Walsh.</p>
017: *
018: * <p>This class provides a
019: * <a href="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
020: * implementation to scan the column widths in a result tree
021: * fragment.</p>
022: *
023: * <p>The general design is this: the stylesheets construct a result tree
024: * fragment for some colgroup environment. That result tree fragment
025: * is "replayed" through the ColumnUpdateEmitter; the ColumnUpdateEmitter watches
026: * the cols go by and extracts the column widths that it sees. These
027: * widths are then made available.</p>
028: *
029: * <p><b>Change Log:</b></p>
030: * <dl>
031: * <dt>1.0</dt>
032: * <dd><p>Initial release.</p></dd>
033: * </dl>
034: *
035: * @author Norman Walsh
036: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
037: *
038: * @version $Id: ColumnUpdateEmitter.java,v 1.4 2005-08-30 08:14:58 draganr Exp $
039: *
040: */
041: public class ColumnUpdateEmitter extends CopyEmitter {
042: /** The number of columns seen. */
043: protected int numColumns = 0;
044: protected String width[] = null;
045: protected NamePool namePool = null;
046:
047: /** The FO namespace name. */
048: protected static String foURI = "http://www.w3.org/1999/XSL/Format";
049:
050: /** Construct a new ColumnUpdateEmitter. */
051: public ColumnUpdateEmitter(Controller controller,
052: NamePool namePool, String width[]) {
053: super (controller, namePool);
054: numColumns = 0;
055: this .width = width;
056: this .namePool = namePool;
057: }
058:
059: /** Examine for column info. */
060: public void startElement(int nameCode,
061: org.xml.sax.Attributes attributes, int[] namespaces,
062: int nscount) throws TransformerException {
063:
064: int this Fingerprint = namePool.getFingerprint(nameCode);
065: int colFingerprint = namePool.getFingerprint("", "col");
066: int foColFingerprint = namePool.getFingerprint(foURI,
067: "table-column");
068:
069: if (this Fingerprint == colFingerprint) {
070: AttributeCollection attr = new AttributeCollection(
071: namePool, attributes);
072: int widthFingerprint = namePool.getFingerprint("", "width");
073:
074: if (attr.getValueByFingerprint(widthFingerprint) == null) {
075: attr.addAttribute(widthFingerprint, "CDATA",
076: width[numColumns++]);
077: } else {
078: attr.setAttribute(widthFingerprint, "CDATA",
079: width[numColumns++]);
080: }
081: attributes = attr;
082: } else if (this Fingerprint == foColFingerprint) {
083: AttributeCollection attr = new AttributeCollection(
084: namePool, attributes);
085: int widthFingerprint = namePool.getFingerprint("",
086: "column-width");
087:
088: if (attr.getValueByFingerprint(widthFingerprint) == null) {
089: attr.addAttribute(widthFingerprint, "CDATA",
090: width[numColumns++]);
091: } else {
092: attr.setAttribute(widthFingerprint, "CDATA",
093: width[numColumns++]);
094: }
095: attributes = attr;
096: }
097:
098: rtfEmitter.startElement(nameCode, attributes, namespaces,
099: nscount);
100: }
101: }
|