]> granicus.if.org Git - docbook-dsssl/commitdiff
Working towards Xalan 2.2 support (this code is BROKEN)
authorNorman Walsh <ndw@nwalsh.com>
Sat, 7 Jul 2001 22:11:12 +0000 (22:11 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Sat, 7 Jul 2001 22:11:12 +0000 (22:11 +0000)
xsl/extensions/xalan2/com/nwalsh/xalan/FormatDingbatCallout.java [new file with mode: 0644]
xsl/extensions/xalan2/com/nwalsh/xalan/Table.java
xsl/extensions/xalan2/com/nwalsh/xalan/Verbatim.java

diff --git a/xsl/extensions/xalan2/com/nwalsh/xalan/FormatDingbatCallout.java b/xsl/extensions/xalan2/com/nwalsh/xalan/FormatDingbatCallout.java
new file mode 100644 (file)
index 0000000..e78d3cc
--- /dev/null
@@ -0,0 +1,82 @@
+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");
+    }
+  }
+}
index 6b365a9e944bbfb97a2293b5b407483328ac3838..6b5fddb3246ff281217560921e4b294236a27c80 100644 (file)
@@ -280,10 +280,6 @@ public class Table {
   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");
@@ -328,22 +324,20 @@ public class Table {
              || (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");
          }
        }
 
@@ -481,11 +475,10 @@ public class Table {
       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++) {
@@ -534,4 +527,20 @@ public class Table {
 
     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;
+  }
 }
index 63e952e561365276c39e7bed4b5a63c655e114c4..a5986a11f11cfca5320de8f0e71e0f21e374a89f 100644 (file)
@@ -108,8 +108,6 @@ public class Verbatim {
   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>
    *
@@ -160,10 +158,6 @@ public class Verbatim {
   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");
@@ -264,10 +258,10 @@ public class Verbatim {
        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();
@@ -449,10 +443,6 @@ public class Verbatim {
                                          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");
@@ -468,6 +458,10 @@ public class Verbatim {
       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);
     }
@@ -494,6 +488,15 @@ public class Verbatim {
     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,
@@ -609,10 +612,10 @@ public class Verbatim {
        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();
@@ -730,12 +733,9 @@ public class Verbatim {
                           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;
 
@@ -908,4 +908,20 @@ public class Verbatim {
 
     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;
+  }
 }