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.4 2005-08-30 08:14:58 draganr 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.4 2005-08-30 08:14:58 draganr 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 a width array with exactly the right number of columns
062: String rWidth[] = new String[numColumns];
063: for (int count = 0; count < numColumns; count++) {
064: rWidth[count] = width[count];
065: }
066: return rWidth;
067: }
068:
069: /** Discarded. */
070: public void characters(char[] chars, int start, int len)
071: throws TransformerException {
072: // nop
073: }
074:
075: /** Discarded. */
076: public void comment(char[] chars, int start, int length)
077: throws TransformerException {
078: // nop
079: }
080:
081: /** Discarded. */
082: public void endDocument() throws TransformerException {
083: // nop
084: }
085:
086: /** Discarded. */
087: public void endElement(int nameCode) throws TransformerException {
088: // nop
089: }
090:
091: /** Discarded. */
092: public void processingInstruction(java.lang.String name,
093: java.lang.String data) throws TransformerException {
094: // nop
095: }
096:
097: /** Discarded. */
098: public void setDocumentLocator(org.xml.sax.Locator locator) {
099: // nop
100: }
101:
102: /** Discarded. */
103: public void setEscaping(boolean escaping)
104: throws TransformerException {
105: // nop
106: }
107:
108: /** Discarded. */
109: public void setNamePool(NamePool namePool) {
110: // nop
111: }
112:
113: /** Discarded. */
114: public void setUnparsedEntity(java.lang.String name,
115: java.lang.String uri) throws TransformerException {
116: // nop
117: }
118:
119: /** Discarded. */
120: public void setWriter(java.io.Writer writer) {
121: // nop
122: }
123:
124: /** Discarded. */
125: public void startDocument() throws TransformerException {
126: // nop
127: }
128:
129: /** Examine for column info. */
130: public void startElement(int nameCode,
131: org.xml.sax.Attributes attributes, int[] namespaces,
132: int nscount) throws TransformerException {
133:
134: int this Fingerprint = namePool.getFingerprint(nameCode);
135: int colFingerprint = namePool.getFingerprint("", "col");
136: int foColFingerprint = namePool.getFingerprint(foURI,
137: "table-column");
138:
139: if (this Fingerprint == colFingerprint
140: || this Fingerprint == foColFingerprint) {
141: if (numColumns >= width.length) {
142: String newWidth[] = new String[width.length + 10];
143: for (int count = 0; count < width.length; count++) {
144: newWidth[count] = width[count];
145: }
146: width = newWidth;
147: }
148:
149: if (this Fingerprint == colFingerprint) {
150: if (attributes.getValue("width") == null) {
151: width[numColumns++] = "1*";
152: } else {
153: width[numColumns++] = attributes.getValue("width");
154: }
155: } else {
156: if (attributes.getValue("column-width") == null) {
157: width[numColumns++] = "1*";
158: } else {
159: width[numColumns++] = attributes
160: .getValue("column-width");
161: }
162: }
163: }
164: }
165: }
|