package com.nwalsh.saxon;
import org.xml.sax.*;
import com.icl.saxon.output.*;
import com.icl.saxon.Controller;
import com.icl.saxon.om.*;
import javax.xml.transform.TransformerException;
import com.icl.saxon.expr.FragmentValue;
import com.icl.saxon.tree.AttributeCollection;
/**
*
Saxon extension to scan the column widths in a result tree fragment.
*
* $Id: ColumnUpdateEmitter.java 5907 2006-04-27 08:26:47Z xmldoc $
*
* Copyright (C) 2000 Norman Walsh.
*
* This class provides a
* Saxon 6.*
* implementation to scan the column widths in a result tree
* fragment.
*
* The general design is this: the stylesheets construct a result tree
* fragment for some colgroup environment. That result tree fragment
* is "replayed" through the ColumnUpdateEmitter; the ColumnUpdateEmitter watches
* the cols go by and extracts the column widths that it sees. These
* widths are then made available.
*
* Change Log:
*
* - 1.0
* Initial release.
*
*
* @author Norman Walsh
* ndw@nwalsh.com
*
* @version $Id: ColumnUpdateEmitter.java 5907 2006-04-27 08:26:47Z xmldoc $
*
*/
public class ColumnUpdateEmitter extends CopyEmitter {
/** The number of columns seen. */
protected int numColumns = 0;
protected String width[] = null;
protected NamePool namePool = null;
/** The FO namespace name. */
protected static String foURI = "http://www.w3.org/1999/XSL/Format";
/** Construct a new ColumnUpdateEmitter. */
public ColumnUpdateEmitter(Controller controller,
NamePool namePool,
String width[]) {
super(controller, namePool);
numColumns = 0;
this.width = width;
this.namePool = namePool;
}
/** Examine for column info. */
public void startElement(int nameCode,
org.xml.sax.Attributes attributes,
int[] namespaces, int nscount)
throws TransformerException {
int thisFingerprint = namePool.getFingerprint(nameCode);
int colFingerprint = namePool.getFingerprint("", "col");
int foColFingerprint = namePool.getFingerprint(foURI, "table-column");
if (thisFingerprint == colFingerprint) {
AttributeCollection attr = new AttributeCollection(namePool, attributes);
int widthFingerprint = namePool.getFingerprint("", "width");
if (attr.getValueByFingerprint(widthFingerprint) == null) {
attr.addAttribute(widthFingerprint, "CDATA", width[numColumns++]);
} else {
attr.setAttribute(widthFingerprint, "CDATA", width[numColumns++]);
}
attributes = attr;
} else if (thisFingerprint == foColFingerprint) {
AttributeCollection attr = new AttributeCollection(namePool, attributes);
int widthFingerprint = namePool.getFingerprint("", "column-width");
if (attr.getValueByFingerprint(widthFingerprint) == null) {
attr.addAttribute(widthFingerprint, "CDATA", width[numColumns++]);
} else {
attr.setAttribute(widthFingerprint, "CDATA", width[numColumns++]);
}
attributes = attr;
}
rtfEmitter.startElement(nameCode, attributes, namespaces, nscount);
}
}