
com.nwalsh.saxon.ColumnScanEmitter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docbook-xsl-saxon Show documentation
Show all versions of docbook-xsl-saxon Show documentation
These are Java extensions for use with the DocBook XML stylesheets and the Saxon XSLT engine.
The newest version!
package com.nwalsh.saxon;
import javax.xml.transform.TransformerException;
import com.icl.saxon.om.NamePool;
/**
* Saxon extension to scan the column widths in a result tree fragment.
*
* $Id: ColumnScanEmitter.java 8483 2009-07-13 20:33:56Z mzjn $
*
* Copyright (C) 2000 Norman Walsh.
*
* This class provides a
* Saxon 6.*
* implementation to scan the column widths in a result tree
* fragment.
*
* The general design is this: the stylesheets construct a result tree
* fragment for some colgroup environment. That result tree fragment
* is "replayed" through the ColumnScanEmitter; the ColumnScanEmitter watches
* the cols go by and extracts the column widths that it sees. These
* widths are then made available.
*
* Change Log:
*
* - 1.0
* Initial release.
*
*
* @author Norman Walsh
* [email protected]
*
* @version $Id: ColumnScanEmitter.java 8483 2009-07-13 20:33:56Z mzjn $
*
*/
public class ColumnScanEmitter extends com.icl.saxon.output.Emitter {
/** The number of columns seen. */
protected int numColumns = 0;
protected String width[] = new String[5];
protected NamePool namePool = null;
/** The FO namespace name. */
protected static String foURI = "http://www.w3.org/1999/XSL/Format";
/** The XHTML namespace name. */
protected static String xhtmlURI = "http://www.w3.org/1999/xhtml";
/** Construct a new ColumnScanEmitter. */
public ColumnScanEmitter(NamePool namePool) {
numColumns = 0;
this.namePool = namePool;
}
/** Return the number of columns. */
public int columnCount() {
return numColumns;
}
/** Return the number of columns. */
public String[] columnWidths() {
// Return a width array with exactly the right number of columns
String rWidth[] = new String[numColumns];
for (int count = 0; count < numColumns; count++) {
rWidth[count] = width[count];
}
return rWidth;
}
/** Discarded. */
public void characters(char[] chars, int start, int len)
throws TransformerException {
// nop
}
/** Discarded. */
public void comment(char[] chars, int start, int length)
throws TransformerException {
// nop
}
/** Discarded. */
public void endDocument()
throws TransformerException {
// nop
}
/** Discarded. */
public void endElement(int nameCode)
throws TransformerException {
// nop
}
/** Discarded. */
public void processingInstruction(java.lang.String name,
java.lang.String data)
throws TransformerException {
// nop
}
/** Discarded. */
public void setDocumentLocator(org.xml.sax.Locator locator) {
// nop
}
/** Discarded. */
public void setEscaping(boolean escaping)
throws TransformerException {
// nop
}
/** Discarded. */
public void setNamePool(NamePool namePool) {
// nop
}
/** Discarded. */
public void setUnparsedEntity(java.lang.String name, java.lang.String uri)
throws TransformerException {
// nop
}
/** Discarded. */
public void setWriter(java.io.Writer writer) {
// nop
}
/** Discarded. */
public void startDocument()
throws TransformerException {
// nop
}
/** Examine for column info. */
public void startElement(int nameCode,
org.xml.sax.Attributes attributes,
int[] namespaces, int nscount)
throws TransformerException {
int thisFingerprint = namePool.getFingerprint(nameCode);
int colFingerprint = namePool.getFingerprint("", "col");
int XHTMLcolFingerprint = namePool.getFingerprint(xhtmlURI, "col");
int foColFingerprint = namePool.getFingerprint(foURI, "table-column");
if (thisFingerprint == colFingerprint
|| thisFingerprint == foColFingerprint || thisFingerprint == XHTMLcolFingerprint) {
if (numColumns >= width.length) {
String newWidth[] = new String[width.length+10];
for (int count = 0; count < width.length; count++) {
newWidth[count] = width[count];
}
width = newWidth;
}
if (thisFingerprint == colFingerprint || thisFingerprint == XHTMLcolFingerprint) {
if (attributes.getValue("width") == null) {
width[numColumns++] = "1*";
} else {
width[numColumns++] = attributes.getValue("width");
}
} else {
if (attributes.getValue("column-width") == null) {
width[numColumns++] = "1*";
} else {
width[numColumns++] = attributes.getValue("column-width");
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy