Source code: com/nwalsh/xalan/FormatCallout.java
1 package com.nwalsh.xalan;
2
3 import org.xml.sax.SAXException;
4 import org.xml.sax.helpers.AttributesImpl;
5 import org.w3c.dom.*;
6 import org.apache.xpath.DOMHelper;
7 import org.apache.xml.utils.DOMBuilder;
8 import org.apache.xml.utils.AttList;
9 import com.nwalsh.xalan.Callout;
10
11 /**
12 * <p>Utility class for the Verbatim extension (ignore this).</p>
13 *
14 *
15 * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
16 *
17 * <p><b>Change Log:</b></p>
18 * <dl>
19 * <dt>1.0</dt>
20 * <dd><p>Initial release.</p></dd>
21 * </dl>
22 *
23 * @author Norman Walsh
24 * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
25 *
26 * @see Verbatim
27 *
28 **/
29
30 public abstract class FormatCallout {
31 protected static final String foURI = "http://www.w3.org/1999/XSL/Format";
32 protected static final String xhURI = "http://www.w3.org/1999/xhtml";
33 protected boolean stylesheetFO = false;
34 protected DOMHelper dh = null;
35
36 public FormatCallout() {
37 //nop;
38 }
39
40 public String areaLabel(Element area) {
41 NamedNodeMap domAttr = area.getAttributes();
42 AttList attr = new AttList(domAttr, dh);
43 String label = null;
44
45 if (attr.getValue("label") != null) {
46 // If this area has a label, use it
47 label = attr.getValue("label");
48 } else {
49 // Otherwise, if its parent is an areaset and it has a label, use that
50 Element parent = (Element) area.getParentNode();
51 NamedNodeMap pdomAttr = parent.getAttributes();
52 AttList pAttr = new AttList(pdomAttr, dh);
53 if (parent != null
54 && parent.getNodeName().equals("areaset")
55 && pAttr.getValue("label") != null) {
56 label = pAttr.getValue("label");
57 }
58 }
59
60 return label;
61 }
62
63 public void startSpan(DOMBuilder rtf)
64 throws SAXException {
65 // no point in doing this for FO, right?
66 if (!stylesheetFO) {
67 AttributesImpl spanAttr = new AttributesImpl();
68 spanAttr.addAttribute("", "class", "class", "CDATA", "co");
69 rtf.startElement("", "span", "span", spanAttr);
70 }
71 }
72
73 public void endSpan(DOMBuilder rtf)
74 throws SAXException {
75 // no point in doing this for FO, right?
76 if (!stylesheetFO) {
77 rtf.endElement("", "span", "span");
78 }
79 }
80
81 public void formatTextCallout(DOMBuilder rtf,
82 Callout callout) {
83 Element area = callout.getArea();
84 int num = callout.getCallout();
85 String userLabel = areaLabel(area);
86 String label = "(" + num + ")";
87
88 if (userLabel != null) {
89 label = userLabel;
90 }
91
92 char chars[] = label.toCharArray();
93
94 try {
95 startSpan(rtf);
96 rtf.characters(chars, 0, label.length());
97 endSpan(rtf);
98 } catch (SAXException e) {
99 System.out.println("SAX Exception in text formatCallout");
100 }
101 }
102
103 public abstract void formatCallout(DOMBuilder rtf,
104 Callout callout);
105 }
106