01: package com.nwalsh.xalan;
02:
03: import org.xml.sax.SAXException;
04: import org.xml.sax.helpers.AttributesImpl;
05: import org.w3c.dom.*;
06: import org.apache.xml.utils.DOMBuilder;
07: import com.nwalsh.xalan.Callout;
08:
09: /**
10: * <p>Utility class for the Verbatim extension (ignore this).</p>
11: *
12: * <p>$Id: FormatCallout.java,v 1.1 2006/05/31 17:21:20 mbatchelor Exp $</p>
13: *
14: * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
15: *
16: * <p><b>Change Log:</b></p>
17: * <dl>
18: * <dt>1.0</dt>
19: * <dd><p>Initial release.</p></dd>
20: * </dl>
21: *
22: * @author Norman Walsh
23: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
24: *
25: * @see Verbatim
26: *
27: * @version $Id: FormatCallout.java,v 1.1 2006/05/31 17:21:20 mbatchelor Exp $
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:
35: public FormatCallout() {
36: //nop;
37: }
38:
39: public String areaLabel(Element area) {
40: String label = null;
41:
42: if (area.getAttribute("label") != null) {
43: // If this area has a label, use it
44: label = area.getAttribute("label");
45: } else {
46: // Otherwise, if its parent is an areaset and it has a label, use that
47: Element parent = (Element) area.getParentNode();
48: if (parent != null
49: && parent.getNodeName().equals("areaset")
50: && parent.getAttribute("label") != null) {
51: label = parent.getAttribute("label");
52: }
53: }
54:
55: return label;
56: }
57:
58: public void startSpan(DOMBuilder rtf) throws SAXException {
59: // no point in doing this for FO, right?
60: if (!stylesheetFO) {
61: AttributesImpl spanAttr = new AttributesImpl();
62: spanAttr.addAttribute("", "class", "class", "CDATA", "co");
63: rtf.startElement("", "span", "span", spanAttr);
64: }
65: }
66:
67: public void endSpan(DOMBuilder rtf) throws SAXException {
68: // no point in doing this for FO, right?
69: if (!stylesheetFO) {
70: rtf.endElement("", "span", "span");
71: }
72: }
73:
74: public void formatTextCallout(DOMBuilder rtf, Callout callout) {
75: Element area = callout.getArea();
76: int num = callout.getCallout();
77: String userLabel = areaLabel(area);
78: String label = "(" + num + ")";
79:
80: if (userLabel != null) {
81: label = userLabel;
82: }
83:
84: char chars[] = label.toCharArray();
85:
86: try {
87: startSpan(rtf);
88: rtf.characters(chars, 0, label.length());
89: endSpan(rtf);
90: } catch (SAXException e) {
91: System.out.println("SAX Exception in text formatCallout");
92: }
93: }
94:
95: public abstract void formatCallout(DOMBuilder rtf, Callout callout);
96: }
|