Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/nwalsh/saxon/ColumnScanEmitter.java


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 widthsin a result tree fragment.</p>
11   *
12   *
13   * <p>Copyright (C) 2000 Norman Walsh.</p>
14   *
15   * <p>This class provides a
16   * <a href="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
17   * implementation to scan the column widths in a result tree
18   * fragment.</p>
19   *
20   * <p>The general design is this: the stylesheets construct a result tree
21   * fragment for some colgroup environment. That result tree fragment
22   * is "replayed" through the ColumnScanEmitter; the ColumnScanEmitter watches
23   * the cols go by and extracts the column widths that it sees. These
24   * widths are then made available.</p>
25   *
26   * <p><b>Change Log:</b></p>
27   * <dl>
28   * <dt>1.0</dt>
29   * <dd><p>Initial release.</p></dd>
30   * </dl>
31   *
32   * @author Norman Walsh
33   * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
34   *
35   *
36   */
37  public class ColumnScanEmitter extends com.icl.saxon.output.Emitter {
38    /** The number of columns seen. */
39    protected int numColumns = 0;
40    protected String width[] = new String[5];
41    protected NamePool namePool = null;
42  
43    /** The FO namespace name. */
44    protected static String foURI = "http://www.w3.org/1999/XSL/Format";
45  
46    /** Construct a new ColumnScanEmitter. */
47    public ColumnScanEmitter(NamePool namePool) {
48      numColumns = 0;
49      this.namePool = namePool;
50    }
51  
52    /** Return the number of columns. */
53    public int columnCount() {
54      return numColumns;
55    }
56  
57    /** Return the number of columns. */
58    public String[] columnWidths() {
59      return width;
60    }
61  
62    /** Discarded. */
63    public void characters(char[] chars, int start, int len)
64      throws TransformerException {
65      // nop
66    }
67  
68    /** Discarded. */
69    public void comment(char[] chars, int start, int length)
70      throws TransformerException {
71      // nop
72    }
73  
74    /** Discarded. */
75    public void endDocument()
76      throws TransformerException {
77      // nop
78    }
79  
80    /** Discarded. */
81    public void endElement(int nameCode)
82      throws TransformerException {
83      // nop
84    }
85  
86    /** Discarded. */
87    public void processingInstruction(java.lang.String name,
88              java.lang.String data)
89      throws TransformerException {
90      // nop
91    }
92  
93    /** Discarded. */
94    public void setDocumentLocator(org.xml.sax.Locator locator) {
95      // nop
96    }
97  
98    /** Discarded. */
99    public void setEscaping(boolean escaping)
100     throws TransformerException {
101     // nop
102   }
103 
104   /** Discarded. */
105   public void setNamePool(NamePool namePool) {
106     // nop
107   }
108 
109   /** Discarded. */
110   public void setUnparsedEntity(java.lang.String name, java.lang.String uri)
111     throws TransformerException {
112     // nop
113   }
114 
115   /** Discarded. */
116   public void setWriter(java.io.Writer writer) {
117     // nop
118   }
119 
120   /** Discarded. */
121   public void startDocument()
122     throws TransformerException {
123     // nop
124   }
125 
126   /** Examine for column info. */
127   public void startElement(int nameCode,
128         org.xml.sax.Attributes attributes,
129         int[] namespaces, int nscount)
130     throws TransformerException {
131 
132     int thisFingerprint = namePool.getFingerprint(nameCode);
133     int colFingerprint = namePool.getFingerprint("", "col");
134     int foColFingerprint = namePool.getFingerprint(foURI, "table-column");
135 
136     if (thisFingerprint == colFingerprint
137   || thisFingerprint == foColFingerprint) {
138       if (numColumns >= width.length) {
139   String newWidth[] = new String[width.length+10];
140   for (int count = 0; count < width.length; count++) {
141     newWidth[count] = width[count];
142   }
143   width = newWidth;
144       }
145 
146       if (thisFingerprint == colFingerprint) {
147   if (attributes.getValue("width") == null) {
148     width[numColumns++] = "1*";
149   } else {
150     width[numColumns++] = attributes.getValue("width");
151   }
152       } else {
153   if (attributes.getValue("column-width") == null) {
154     width[numColumns++] = "1*";
155   } else {
156     width[numColumns++] = attributes.getValue("column-width");
157   }
158       }
159     }
160   }
161 }
162 
163