Debian Codegraph @

src/com/nwalsh/saxon/ColumnScanEmitter.java

raw symbols SCIP
1 package com.nwalsh.saxon;
2
3 import org.xml.sax.*;
4 import javax.xml.transform.TransformerException;
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 widths in a result tree fragment.</p>
11 *
12 * <p>$Id: ColumnScanEmitter.java 5907 2006-04-27 08:26:47Z xmldoc $</p>
13 *
14 * <p>Copyright (C) 2000 Norman Walsh.</p>
15 *
16 * <p>This class provides a
17 * <a href="http://saxon.sourceforge.net/">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:[email protected]">[email protected]</a>
35 *
36 * @version $Id: ColumnScanEmitter.java 5907 2006-04-27 08:26:47Z xmldoc $
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 width[] = new String[5];
43 protected NamePool namePool = null;
44
45 /** The FO namespace name. */
46 protected static String 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[] columnWidths() {
61 // Return a width array with exactly the right number of columns
62 String rWidth[] = new String[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 {
72 // nop
73 }
74
75 /** Discarded. */
76 public void comment(char[] chars, int start, int length)
77 throws TransformerException {
78 // nop
79 }
80
81 /** Discarded. */
82 public void endDocument()
83 throws TransformerException {
84 // nop
85 }
86
87 /** Discarded. */
88 public void endElement(int nameCode)
89 throws TransformerException {
90 // nop
91 }
92
93 /** Discarded. */
94 public void processingInstruction(java.lang.String name,
95 java.lang.String data)
96 throws TransformerException {
97 // nop
98 }
99
100 /** Discarded. */
101 public void setDocumentLocator(org.xml.sax.Locator locator) {
102 // nop
103 }
104
105 /** Discarded. */
106 public void setEscaping(boolean escaping)
107 throws TransformerException {
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 name, java.lang.String uri)
118 throws TransformerException {
119 // nop
120 }
121
122 /** Discarded. */
123 public void setWriter(java.io.Writer writer) {
124 // nop
125 }
126
127 /** Discarded. */
128 public void startDocument()
129 throws TransformerException {
130 // nop
131 }
132
133 /** Examine for column info. */
134 public void startElement(int nameCode,
135 org.xml.sax.Attributes attributes,
136 int[] namespaces, int nscount)
137 throws TransformerException {
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 newWidth[] = new String[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