--- /dev/null
+package com.nwalsh.xalan;
+
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.SAXException;
+import org.w3c.dom.*;
+import org.apache.xml.utils.DOMBuilder;
+import com.nwalsh.xalan.Callout;
+import org.apache.xml.utils.AttList;
+
+/**
+ * <p>Utility class for the Verbatim extension (ignore this).</p>
+ *
+ * <p>$Id$</p>
+ *
+ * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
+ *
+ * <p><b>Change Log:</b></p>
+ * <dl>
+ * <dt>1.0</dt>
+ * <dd><p>Initial release.</p></dd>
+ * </dl>
+ *
+ * @author Norman Walsh
+ * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
+ *
+ * @see Verbatim
+ *
+ * @version $Id$
+ **/
+
+public class FormatDingbatCallout extends FormatCallout {
+ int graphicsMax = 0;
+
+ public FormatDingbatCallout(int max, boolean fo) {
+ graphicsMax = max;
+ stylesheetFO = fo;
+ }
+
+ public void formatCallout(DOMBuilder rtf,
+ Callout callout) {
+ Element area = callout.getArea();
+ int num = callout.getCallout();
+ String label = areaLabel(area);
+
+ try {
+ if (label == null && num <= graphicsMax) {
+ AttributesImpl imgAttr = new AttributesImpl();
+ String ns = "";
+ String prefix = "";
+ String imgName = "";
+
+ if (stylesheetFO) {
+ ns = foURI;
+ prefix = "fo:"; // FIXME: this could be a problem...
+ imgName = "inline";
+ imgAttr.addAttribute("", "font-family", "font-family", "CDATA",
+ "ZapfDingbats");
+ } else {
+ ns = "";
+ prefix = "";
+ imgName = "font";
+ imgAttr.addAttribute("", "face", "face", "CDATA",
+ "ZapfDingbats");
+ }
+
+ startSpan(rtf);
+ rtf.startElement(ns, imgName, prefix+imgName, imgAttr);
+
+ char chars[] = new char[1];
+ chars[0] = (char) (0x2775 + num);
+ rtf.characters(chars, 0, 1);
+
+ rtf.endElement(ns, imgName, prefix+imgName);
+ endSpan(rtf);
+ } else {
+ formatTextCallout(rtf, callout);
+ }
+ } catch (SAXException e) {
+ System.out.println("SAX Exception in graphics formatCallout");
+ }
+ }
+}
public DocumentFragment adjustColumnWidths (ExpressionContext context,
NodeIterator xalanNI) {
- // HACK!!!
- XPathContext xpcontext = (XPathContext) context;
- DOMHelper dh = xpcontext.getDOMHelper();
-
int nominalWidth = convertLength(Params.getString(context,
"nominal.table.width"));
String tableWidth = Params.getString(context, "table.width");
|| (child.getNamespaceURI().equals(foURI)
&& child.getLocalName().equals("table-column")))) {
Element col = (Element) child;
- NamedNodeMap domAttr = col.getAttributes();
- AttList attr = new AttList(domAttr,dh);
columns[colnum] = col;
if (foStylesheet) {
- if (attr.getValue("column-width") == null) {
+ if (col.getAttribute("column-width") == null) {
widths[colnum] = "1*";
} else {
- widths[colnum] = attr.getValue("column-width");
+ widths[colnum] = col.getAttribute("column-width");
}
} else {
- if (attr.getValue("width") == null) {
+ if (col.getAttribute("width") == null) {
widths[colnum] = "1*";
} else {
- widths[colnum] = attr.getValue("width");
+ widths[colnum] = col.getAttribute("width");
}
}
String ns = colgroup.getNamespaceURI();
String localName = colgroup.getLocalName();
String name = colgroup.getTagName();
- NamedNodeMap colgroupDomAttr = colgroup.getAttributes();
- AttList colgroupAttr = new AttList(colgroupDomAttr,dh);
if (colgroup.getLocalName().equals("colgroup")) {
- rtf.startElement(ns, localName, name, colgroupAttr);
+ rtf.startElement(ns, localName, name,
+ copyAttributes(colgroup));
}
for (colnum = 0; colnum < numColumns; colnum++) {
return df;
}
+
+ private Attributes copyAttributes(Element node) {
+ AttributesImpl attrs = new AttributesImpl();
+ NamedNodeMap nnm = node.getAttributes();
+ for (int count = 0; count < nnm.getLength(); count++) {
+ Attr attr = (Attr) nnm.item(count);
+ String name = attr.getName();
+ if (name.startsWith("xmlns:") || name.equals("xmlns")) {
+ // Skip it; (don't ya just love it!!)
+ } else {
+ attrs.addAttribute(attr.getNamespaceURI(), attr.getName(),
+ attr.getName(), "CDATA", attr.getValue());
+ }
+ }
+ return attrs;
+ }
}
private static final String foURI = "http://www.w3.org/1999/XSL/Format";
private static final String xhURI = "http://www.w3.org/1999/xhtml";
- protected DOMHelper dh = null;
-
/**
* <p>Constructor for Verbatim</p>
*
public DocumentFragment numberLines (ExpressionContext context,
NodeIterator xalanNI) {
- // HACK!!!
- XPathContext xpcontext = (XPathContext) context;
- dh = xpcontext.getDOMHelper();
-
int xalanMod = Params.getInt(context, "linenumbering.everyNth");
int xalanWidth = Params.getInt(context, "linenumbering.width");
String xalanSep = Params.getString(context, "linenumbering.separator");
String ns = node.getNamespaceURI();
String localName = node.getLocalName();
String name = ((Element) node).getTagName();
- NamedNodeMap domAttr = node.getAttributes();
- AttList attr = new AttList(domAttr, dh);
- rtf.startElement(ns, localName, name, attr);
+ rtf.startElement(ns, localName, name,
+ copyAttributes((Element) node));
+
elementStack.push(node);
Node child = node.getFirstChild();
NodeIterator areaspecNodeSet,
NodeIterator xalanNI) {
- // HACK!!!
- XPathContext xpcontext = (XPathContext) context;
- dh = xpcontext.getDOMHelper();
-
String type = Params.getString(context, "stylesheet.result.type");
boolean useFO = type.equals("fo");
int defaultColumn = Params.getInt(context, "callout.defaultcolumn");
int uMax = Params.getInt(context, "callout.unicode.number.limit");
return insertUnicodeCallouts(areaspecNodeSet, xalanNI, defaultColumn,
uStart, uMax, useFO);
+ } else if (Params.getBoolean(context, "callout.dingbats")) {
+ int dMax = 10;
+ return insertDingbatCallouts(areaspecNodeSet, xalanNI, defaultColumn,
+ dMax, useFO);
} else {
return insertTextCallouts(areaspecNodeSet, xalanNI, defaultColumn, useFO);
}
return insertCallouts(areaspecNodeSet, xalanNI, defaultColumn, fuc);
}
+ public DocumentFragment insertDingbatCallouts (NodeIterator areaspecNodeSet,
+ NodeIterator xalanNI,
+ int defaultColumn,
+ int gMax,
+ boolean useFO) {
+ FormatDingbatCallout fdc = new FormatDingbatCallout(gMax,useFO);
+ return insertCallouts(areaspecNodeSet, xalanNI, defaultColumn, fdc);
+ }
+
public DocumentFragment insertTextCallouts (NodeIterator areaspecNodeSet,
NodeIterator xalanNI,
int defaultColumn,
String ns = node.getNamespaceURI();
String localName = node.getLocalName();
String name = ((Element) node).getTagName();
- NamedNodeMap domAttr = node.getAttributes();
- AttList attr = new AttList(domAttr, dh);
- rtf.startElement(ns, localName, name, attr);
+ rtf.startElement(ns, localName, name,
+ copyAttributes((Element) node));
+
elementStack.push(node);
Node child = node.getFirstChild();
int defaultColumn) {
Element area = (Element) node;
- NamedNodeMap domAttr = node.getAttributes();
- AttList attr = new AttList(domAttr, dh);
-
- String units = attr.getValue("units");
- String otherUnits = attr.getValue("otherunits");
- String coords = attr.getValue("coords");
+ String units = area.getAttribute("units");
+ String otherUnits = area.getAttribute("otherunits");
+ String coords = area.getAttribute("coords");
int type = 0;
String otherType = null;
tempStack = null;
}
+
+ private Attributes copyAttributes(Element node) {
+ AttributesImpl attrs = new AttributesImpl();
+ NamedNodeMap nnm = node.getAttributes();
+ for (int count = 0; count < nnm.getLength(); count++) {
+ Attr attr = (Attr) nnm.item(count);
+ String name = attr.getName();
+ if (name.startsWith("xmlns:") || name.equals("xmlns")) {
+ // Skip it; (don't ya just love it!!)
+ } else {
+ attrs.addAttribute(attr.getNamespaceURI(), attr.getName(),
+ attr.getName(), "CDATA", attr.getValue());
+ }
+ }
+ return attrs;
+ }
}