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