KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nwalsh > saxon > ColumnScanEmitter


1 package com.nwalsh.saxon;
2
3 import org.xml.sax.*;
4 import javax.xml.transform.TransformerException JavaDoc;
5 import com.icl.saxon.output.*;
6 import com.icl.saxon.om.*;
7 import com.icl.saxon.expr.FragmentValue;
8
9 /**
10  * <p>Saxon extension to scan the column widthsin a result tree fragment.</p>
11  *
12  * <p>$Id: ColumnScanEmitter.java,v 1.2 2002/11/15 13:49:42 nwalsh Exp $</p>
13  *
14  * <p>Copyright (C) 2000 Norman Walsh.</p>
15  *
16  * <p>This class provides a
17  * <a HREF="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
18  * implementation to scan the column widths in a result tree
19  * fragment.</p>
20  *
21  * <p>The general design is this: the stylesheets construct a result tree
22  * fragment for some colgroup environment. That result tree fragment
23  * is "replayed" through the ColumnScanEmitter; the ColumnScanEmitter watches
24  * the cols go by and extracts the column widths that it sees. These
25  * widths are then made available.</p>
26  *
27  * <p><b>Change Log:</b></p>
28  * <dl>
29  * <dt>1.0</dt>
30  * <dd><p>Initial release.</p></dd>
31  * </dl>
32  *
33  * @author Norman Walsh
34  * <a HREF="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
35  *
36  * @version $Id: ColumnScanEmitter.java,v 1.2 2002/11/15 13:49:42 nwalsh Exp $
37  *
38  */

39 public class ColumnScanEmitter extends com.icl.saxon.output.Emitter {
40   /** The number of columns seen. */
41   protected int numColumns = 0;
42   protected String JavaDoc width[] = new String JavaDoc[5];
43   protected NamePool namePool = null;
44
45   /** The FO namespace name. */
46   protected static String JavaDoc foURI = "http://www.w3.org/1999/XSL/Format";
47
48   /** Construct a new ColumnScanEmitter. */
49   public ColumnScanEmitter(NamePool namePool) {
50     numColumns = 0;
51     this.namePool = namePool;
52   }
53
54   /** Return the number of columns. */
55   public int columnCount() {
56     return numColumns;
57   }
58
59   /** Return the number of columns. */
60   public String JavaDoc[] columnWidths() {
61     // Return a width array with exactly the right number of columns
62
String JavaDoc rWidth[] = new String JavaDoc[numColumns];
63     for (int count = 0; count < numColumns; count++) {
64       rWidth[count] = width[count];
65     }
66     return rWidth;
67   }
68
69   /** Discarded. */
70   public void characters(char[] chars, int start, int len)
71     throws TransformerException JavaDoc {
72     // nop
73
}
74
75   /** Discarded. */
76   public void comment(char[] chars, int start, int length)
77     throws TransformerException JavaDoc {
78     // nop
79
}
80
81   /** Discarded. */
82   public void endDocument()
83     throws TransformerException JavaDoc {
84     // nop
85
}
86
87   /** Discarded. */
88   public void endElement(int nameCode)
89     throws TransformerException JavaDoc {
90     // nop
91
}
92
93   /** Discarded. */
94   public void processingInstruction(java.lang.String JavaDoc name,
95                     java.lang.String JavaDoc data)
96     throws TransformerException JavaDoc {
97     // nop
98
}
99
100   /** Discarded. */
101   public void setDocumentLocator(org.xml.sax.Locator JavaDoc locator) {
102     // nop
103
}
104
105   /** Discarded. */
106   public void setEscaping(boolean escaping)
107     throws TransformerException JavaDoc {
108     // nop
109
}
110
111   /** Discarded. */
112   public void setNamePool(NamePool namePool) {
113     // nop
114
}
115
116   /** Discarded. */
117   public void setUnparsedEntity(java.lang.String JavaDoc name, java.lang.String JavaDoc uri)
118     throws TransformerException JavaDoc {
119     // nop
120
}
121
122   /** Discarded. */
123   public void setWriter(java.io.Writer JavaDoc writer) {
124     // nop
125
}
126
127   /** Discarded. */
128   public void startDocument()
129     throws TransformerException JavaDoc {
130     // nop
131
}
132
133   /** Examine for column info. */
134   public void startElement(int nameCode,
135             org.xml.sax.Attributes JavaDoc attributes,
136             int[] namespaces, int nscount)
137     throws TransformerException JavaDoc {
138
139     int thisFingerprint = namePool.getFingerprint(nameCode);
140     int colFingerprint = namePool.getFingerprint("", "col");
141     int foColFingerprint = namePool.getFingerprint(foURI, "table-column");
142
143     if (thisFingerprint == colFingerprint
144     || thisFingerprint == foColFingerprint) {
145       if (numColumns >= width.length) {
146     String JavaDoc newWidth[] = new String JavaDoc[width.length+10];
147     for (int count = 0; count < width.length; count++) {
148       newWidth[count] = width[count];
149     }
150     width = newWidth;
151       }
152
153       if (thisFingerprint == colFingerprint) {
154     if (attributes.getValue("width") == null) {
155       width[numColumns++] = "1*";
156     } else {
157       width[numColumns++] = attributes.getValue("width");
158     }
159       } else {
160     if (attributes.getValue("column-width") == null) {
161       width[numColumns++] = "1*";
162     } else {
163       width[numColumns++] = attributes.getValue("column-width");
164     }
165       }
166     }
167   }
168 }
169
170
171
Popular Tags