KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nwalsh > xalan > FormatCallout


1 package com.nwalsh.xalan;
2
3 import org.xml.sax.SAXException JavaDoc;
4 import org.xml.sax.helpers.AttributesImpl JavaDoc;
5 import org.w3c.dom.*;
6 import org.apache.xml.utils.DOMBuilder;
7 import com.nwalsh.xalan.Callout;
8
9 /**
10  * <p>Utility class for the Verbatim extension (ignore this).</p>
11  *
12  * <p>$Id: FormatCallout.java,v 1.4 2004/09/01 20:55:38 bobstayton 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.4 2004/09/01 20:55:38 bobstayton Exp $
28  **/

29
30 public abstract class FormatCallout {
31   protected static final String JavaDoc foURI = "http://www.w3.org/1999/XSL/Format";
32   protected static final String JavaDoc xhURI = "http://www.w3.org/1999/xhtml";
33   protected boolean stylesheetFO = false;
34
35   public FormatCallout() {
36     //nop;
37
}
38
39   public String JavaDoc areaLabel(Element area) {
40     String JavaDoc 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)
59     throws SAXException JavaDoc {
60     // no point in doing this for FO, right?
61
if (!stylesheetFO) {
62       AttributesImpl JavaDoc spanAttr = new AttributesImpl JavaDoc();
63       spanAttr.addAttribute("", "class", "class", "CDATA", "co");
64       rtf.startElement("", "span", "span", spanAttr);
65     }
66   }
67
68   public void endSpan(DOMBuilder rtf)
69     throws SAXException JavaDoc {
70     // no point in doing this for FO, right?
71
if (!stylesheetFO) {
72       rtf.endElement("", "span", "span");
73     }
74   }
75
76   public void formatTextCallout(DOMBuilder rtf,
77                 Callout callout) {
78     Element area = callout.getArea();
79     int num = callout.getCallout();
80     String JavaDoc userLabel = areaLabel(area);
81     String JavaDoc label = "(" + num + ")";
82
83     if (userLabel != null) {
84       label = userLabel;
85     }
86
87     char chars[] = label.toCharArray();
88
89     try {
90       startSpan(rtf);
91       rtf.characters(chars, 0, label.length());
92       endSpan(rtf);
93     } catch (SAXException JavaDoc e) {
94       System.out.println("SAX Exception in text formatCallout");
95     }
96   }
97
98   public abstract void formatCallout(DOMBuilder rtf,
99                      Callout callout);
100 }
101
102
Popular Tags