001: package com.nwalsh.saxon;
002:
003: import org.xml.sax.*;
004: import javax.xml.transform.TransformerException;
005: import com.icl.saxon.output.*;
006: import com.icl.saxon.om.*;
007: import com.icl.saxon.expr.FragmentValue;
008:
009: /**
010: * <p>Saxon extension to scan the column widthsin a result tree fragment.</p>
011: *
012: * <p>$Id: ColumnScanEmitter.java,v 1.1 2001/07/16 21:23:57 nwalsh Exp $</p>
013: *
014: * <p>Copyright (C) 2000 Norman Walsh.</p>
015: *
016: * <p>This class provides a
017: * <a href="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
018: * implementation to scan the column widths in a result tree
019: * fragment.</p>
020: *
021: * <p>The general design is this: the stylesheets construct a result tree
022: * fragment for some colgroup environment. That result tree fragment
023: * is "replayed" through the ColumnScanEmitter; the ColumnScanEmitter watches
024: * the cols go by and extracts the column widths that it sees. These
025: * widths are then made available.</p>
026: *
027: * <p><b>Change Log:</b></p>
028: * <dl>
029: * <dt>1.0</dt>
030: * <dd><p>Initial release.</p></dd>
031: * </dl>
032: *
033: * @author Norman Walsh
034: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
035: *
036: * @version $Id: ColumnScanEmitter.java,v 1.1 2001/07/16 21:23:57 nwalsh Exp $
037: *
038: */
039: public class ColumnScanEmitter extends com.icl.saxon.output.Emitter {
040: /** The number of columns seen. */
041: protected int numColumns = 0;
042: protected String width[] = new String[5];
043: protected NamePool namePool = null;
044:
045: /** The FO namespace name. */
046: protected static String foURI = "http://www.w3.org/1999/XSL/Format";
047:
048: /** Construct a new ColumnScanEmitter. */
049: public ColumnScanEmitter(NamePool namePool) {
050: numColumns = 0;
051: this .namePool = namePool;
052: }
053:
054: /** Return the number of columns. */
055: public int columnCount() {
056: return numColumns;
057: }
058:
059: /** Return the number of columns. */
060: public String[] columnWidths() {
061: return width;
062: }
063:
064: /** Discarded. */
065: public void characters(char[] chars, int start, int len)
066: throws TransformerException {
067: // nop
068: }
069:
070: /** Discarded. */
071: public void comment(char[] chars, int start, int length)
072: throws TransformerException {
073: // nop
074: }
075:
076: /** Discarded. */
077: public void endDocument() throws TransformerException {
078: // nop
079: }
080:
081: /** Discarded. */
082: public void endElement(int nameCode) throws TransformerException {
083: // nop
084: }
085:
086: /** Discarded. */
087: public void processingInstruction(java.lang.String name,
088: java.lang.String data) throws TransformerException {
089: // nop
090: }
091:
092: /** Discarded. */
093: public void setDocumentLocator(org.xml.sax.Locator locator) {
094: // nop
095: }
096:
097: /** Discarded. */
098: public void setEscaping(boolean escaping)
099: throws TransformerException {
100: // nop
101: }
102:
103: /** Discarded. */
104: public void setNamePool(NamePool namePool) {
105: // nop
106: }
107:
108: /** Discarded. */
109: public void setUnparsedEntity(java.lang.String name,
110: java.lang.String uri) throws TransformerException {
111: // nop
112: }
113:
114: /** Discarded. */
115: public void setWriter(java.io.Writer writer) {
116: // nop
117: }
118:
119: /** Discarded. */
120: public void startDocument() throws TransformerException {
121: // nop
122: }
123:
124: /** Examine for column info. */
125: public void startElement(int nameCode,
126: org.xml.sax.Attributes attributes, int[] namespaces,
127: int nscount) throws TransformerException {
128:
129: int this Fingerprint = namePool.getFingerprint(nameCode);
130: int colFingerprint = namePool.getFingerprint("", "col");
131: int foColFingerprint = namePool.getFingerprint(foURI,
132: "table-column");
133:
134: if (this Fingerprint == colFingerprint
135: || this Fingerprint == foColFingerprint) {
136: if (numColumns >= width.length) {
137: String newWidth[] = new String[width.length + 10];
138: for (int count = 0; count < width.length; count++) {
139: newWidth[count] = width[count];
140: }
141: width = newWidth;
142: }
143:
144: if (this Fingerprint == colFingerprint) {
145: if (attributes.getValue("width") == null) {
146: width[numColumns++] = "1*";
147: } else {
148: width[numColumns++] = attributes.getValue("width");
149: }
150: } else {
151: if (attributes.getValue("column-width") == null) {
152: width[numColumns++] = "1*";
153: } else {
154: width[numColumns++] = attributes
155: .getValue("column-width");
156: }
157: }
158: }
159: }
160: }
|