KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.nwalsh.saxon;
2
3 import org.xml.sax.SAXException JavaDoc;
4 import org.w3c.dom.*;
5
6 import javax.xml.transform.TransformerException JavaDoc;
7
8 import com.icl.saxon.om.NamePool;
9 import com.icl.saxon.output.Emitter;
10 import com.icl.saxon.tree.AttributeCollection;
11
12 import com.nwalsh.saxon.Callout;
13
14 /**
15  * <p>Utility class for the Verbatim extension (ignore this).</p>
16  *
17  * <p>$Id: FormatCallout.java,v 1.2 2001/07/31 18:35:35 nwalsh Exp $</p>
18  *
19  * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
20  *
21  * <p><b>Change Log:</b></p>
22  * <dl>
23  * <dt>1.0</dt>
24  * <dd><p>Initial release.</p></dd>
25  * </dl>
26  *
27  * @author Norman Walsh
28  * <a HREF="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
29  *
30  * @see Verbatim
31  *
32  * @version $Id: FormatCallout.java,v 1.2 2001/07/31 18:35:35 nwalsh Exp $
33  **/

34
35 public abstract class FormatCallout {
36   protected static final String JavaDoc foURI = "http://www.w3.org/1999/XSL/Format";
37   protected static final String JavaDoc xhURI = "http://www.w3.org/1999/xhtml";
38   protected boolean foStylesheet = false;
39   protected NamePool namePool = null;
40
41   public FormatCallout(NamePool nPool, boolean fo) {
42     namePool = nPool;
43     foStylesheet = fo;
44   }
45
46   public String JavaDoc areaLabel(Element area) {
47     String JavaDoc label = null;
48
49     if (area.hasAttribute("label")) {
50       // If this area has a label, use it
51
label = area.getAttribute("label");
52     } else {
53       // Otherwise, if its parent is an areaset and it has a label, use that
54
Element parent = (Element) area.getParentNode();
55       if (parent != null
56       && parent.getLocalName().equalsIgnoreCase("areaset")
57       && parent.hasAttribute("label")) {
58     label = parent.getAttribute("label");
59       }
60     }
61
62     return label;
63   }
64
65   public void startSpan(Emitter rtf)
66     throws TransformerException JavaDoc {
67     // no point in doing this for FO, right?
68
if (!foStylesheet && namePool != null) {
69       int spanName = namePool.allocate("", "", "span");
70       AttributeCollection spanAttr = new AttributeCollection(namePool);
71       int namespaces[] = new int[1];
72       spanAttr.addAttribute("", "", "class", "CDATA", "co");
73       rtf.startElement(spanName, spanAttr, namespaces, 0);
74     }
75   }
76
77   public void endSpan(Emitter rtf)
78     throws TransformerException JavaDoc {
79     // no point in doing this for FO, right?
80
if (!foStylesheet && namePool != null) {
81       int spanName = namePool.allocate("", "", "span");
82       rtf.endElement(spanName);
83     }
84   }
85
86   public void formatTextCallout(Emitter rtfEmitter,
87                 Callout callout) {
88     Element area = callout.getArea();
89     int num = callout.getCallout();
90     String JavaDoc userLabel = areaLabel(area);
91     String JavaDoc label = "(" + num + ")";
92
93     if (userLabel != null) {
94       label = userLabel;
95     }
96
97     char chars[] = label.toCharArray();
98
99     try {
100       startSpan(rtfEmitter);
101       rtfEmitter.characters(chars, 0, label.length());
102       endSpan(rtfEmitter);
103     } catch (TransformerException JavaDoc e) {
104       System.out.println("Transformer Exception in formatTextCallout");
105     }
106   }
107
108   public abstract void formatCallout(Emitter rtfEmitter,
109                      Callout callout);
110 }
111
112
Popular Tags