001: package com.nwalsh.xalan;
002:
003: import org.xml.sax.SAXException;
004: import org.xml.sax.helpers.AttributesImpl;
005: import org.w3c.dom.*;
006: import org.apache.xml.utils.DOMHelper;
007: import org.apache.xml.utils.DOMBuilder;
008: import org.apache.xml.utils.AttList;
009: import com.nwalsh.xalan.Callout;
010:
011: /**
012: * <p>Utility class for the Verbatim extension (ignore this).</p>
013: *
014: * <p>$Id: FormatCallout.java,v 1.4 2005-08-30 08:14:58 draganr Exp $</p>
015: *
016: * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
017: *
018: * <p><b>Change Log:</b></p>
019: * <dl>
020: * <dt>1.0</dt>
021: * <dd><p>Initial release.</p></dd>
022: * </dl>
023: *
024: * @author Norman Walsh
025: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
026: *
027: * @see Verbatim
028: *
029: * @version $Id: FormatCallout.java,v 1.4 2005-08-30 08:14:58 draganr Exp $
030: **/
031:
032: public abstract class FormatCallout {
033: protected static final String foURI = "http://www.w3.org/1999/XSL/Format";
034: protected static final String xhURI = "http://www.w3.org/1999/xhtml";
035: protected boolean stylesheetFO = false;
036: protected DOMHelper dh = null;
037:
038: public FormatCallout() {
039: //nop;
040: }
041:
042: public String areaLabel(Element area) {
043: NamedNodeMap domAttr = area.getAttributes();
044: AttList attr = new AttList(domAttr, dh);
045: String label = null;
046:
047: if (attr.getValue("label") != null) {
048: // If this area has a label, use it
049: label = attr.getValue("label");
050: } else {
051: // Otherwise, if its parent is an areaset and it has a label, use that
052: Element parent = (Element) area.getParentNode();
053: NamedNodeMap pdomAttr = parent.getAttributes();
054: AttList pAttr = new AttList(pdomAttr, dh);
055: if (parent != null
056: && parent.getNodeName().equals("areaset")
057: && pAttr.getValue("label") != null) {
058: label = pAttr.getValue("label");
059: }
060: }
061:
062: return label;
063: }
064:
065: public void startSpan(DOMBuilder rtf) throws SAXException {
066: // no point in doing this for FO, right?
067: if (!stylesheetFO) {
068: AttributesImpl spanAttr = new AttributesImpl();
069: spanAttr.addAttribute("", "class", "class", "CDATA", "co");
070: rtf.startElement("", "span", "span", spanAttr);
071: }
072: }
073:
074: public void endSpan(DOMBuilder rtf) throws SAXException {
075: // no point in doing this for FO, right?
076: if (!stylesheetFO) {
077: rtf.endElement("", "span", "span");
078: }
079: }
080:
081: public void formatTextCallout(DOMBuilder rtf, Callout callout) {
082: Element area = callout.getArea();
083: int num = callout.getCallout();
084: String userLabel = areaLabel(area);
085: String label = "(" + num + ")";
086:
087: if (userLabel != null) {
088: label = userLabel;
089: }
090:
091: char chars[] = label.toCharArray();
092:
093: try {
094: startSpan(rtf);
095: rtf.characters(chars, 0, label.length());
096: endSpan(rtf);
097: } catch (SAXException e) {
098: System.out.println("SAX Exception in text formatCallout");
099: }
100: }
101:
102: public abstract void formatCallout(DOMBuilder rtf, Callout callout);
103: }
|