Debian Codegraph @

src/com/nwalsh/saxon/FormatCallout.java

raw symbols SCIP
1 package com.nwalsh.saxon;
2
3 import org.xml.sax.SAXException;
4 import org.w3c.dom.*;
5
6 import javax.xml.transform.TransformerException;
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 7007 2007-07-11 07:09:12Z mzjn $</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:[email protected]">[email protected]</a>
29 *
30 * @see Verbatim
31 *
32 * @version $Id: FormatCallout.java 7007 2007-07-11 07:09:12Z mzjn $
33 **/
34
35 public abstract class FormatCallout {
36 protected static final String foURI = "http://www.w3.org/1999/XSL/Format";
37 protected static final String 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 areaLabel(Element area) {
47 String 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 // Get ID (used for xrefs)
66 public String areaID(Element area) {
67 String id = null;
68
69 if (area.hasAttribute("id")) {
70 id = area.getAttribute("id");
71 }
72
73 else {
74 if (area.hasAttribute("xml:id")) {
75 id = area.getAttribute("xml:id");
76 }
77
78 else {
79 id = "";
80 }
81 }
82 //System.out.println(id);
83 return id;
84 }
85
86
87 public void startSpan(Emitter rtf, String id)
88 throws TransformerException {
89
90 if (!foStylesheet && namePool != null) {
91 int spanName = namePool.allocate("", "", "span");
92 AttributeCollection spanAttr = new AttributeCollection(namePool);
93 int namespaces[] = new int[1];
94 spanAttr.addAttribute("", "", "class", "CDATA", "co");
95 spanAttr.addAttribute("", "", "id", "CDATA", id);
96 rtf.startElement(spanName, spanAttr, namespaces, 0);
97 }
98
99 }
100
101 public void endSpan(Emitter rtf)
102 throws TransformerException {
103
104 if (!foStylesheet && namePool != null) {
105 int spanName = namePool.allocate("", "", "span");
106 rtf.endElement(spanName);
107 }
108 }
109
110 public void formatTextCallout(Emitter rtfEmitter,
111 Callout callout) {
112 Element area = callout.getArea();
113 int num = callout.getCallout();
114 String userLabel = areaLabel(area);
115 String id = areaID(area);
116 String label = "(" + num + ")";
117
118 if (userLabel != null) {
119 label = userLabel;
120 }
121
122 char chars[] = label.toCharArray();
123
124 try {
125 startSpan(rtfEmitter, id);
126
127 if (foStylesheet) {
128 int inlineName = namePool.allocate("fo", foURI, "inline");
129 AttributeCollection inlineAttr = new AttributeCollection(namePool);
130 int namespaces[] = new int[1];
131 inlineAttr.addAttribute("", "", "id", "CDATA", id);
132 rtfEmitter.startElement(inlineName, inlineAttr, namespaces, 0);
133 }
134 rtfEmitter.characters(chars, 0, label.length());
135 endSpan(rtfEmitter);
136
137 if (foStylesheet) {
138 int inlineName = namePool.allocate("fo", foURI, "inline");
139 rtfEmitter.endElement(inlineName);
140 }
141
142 } catch (TransformerException e) {
143 System.out.println("Transformer Exception in formatTextCallout");
144 }
145 }
146
147 public abstract void formatCallout(Emitter rtfEmitter,
148 Callout callout);
149 }
150