Source code: com/nwalsh/xalan/FormatGraphicCallout.java
1 package com.nwalsh.xalan;
2
3 import org.xml.sax.helpers.AttributesImpl;
4 import org.xml.sax.SAXException;
5 import org.w3c.dom.*;
6 import org.apache.xml.utils.DOMBuilder;
7 import com.nwalsh.xalan.Callout;
8 import org.apache.xml.utils.AttList;
9
10 /**
11 * <p>Utility class for the Verbatim extension (ignore this).</p>
12 *
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 **/
28
29 public class FormatGraphicCallout extends FormatCallout {
30 String graphicsPath = "";
31 String graphicsExt = "";
32 int graphicsMax = 0;
33
34 public FormatGraphicCallout(String path, String ext, int max, boolean fo) {
35 graphicsPath = path;
36 graphicsExt = ext;
37 graphicsMax = max;
38 stylesheetFO = fo;
39 }
40
41 public void formatCallout(DOMBuilder rtf,
42 Callout callout) {
43 Element area = callout.getArea();
44 int num = callout.getCallout();
45 String label = areaLabel(area);
46
47 try {
48 if (label == null && num <= graphicsMax) {
49 AttributesImpl imgAttr = new AttributesImpl();
50 String ns = "";
51 String prefix = "";
52 String imgName = "";
53
54 if (stylesheetFO) {
55 ns = foURI;
56 prefix = "fo:"; // FIXME: this could be a problem...
57 imgName = "external-graphic";
58 imgAttr.addAttribute("", "src", "src", "CDATA",
59 graphicsPath + num + graphicsExt);
60 imgAttr.addAttribute("", "alt", "alt", "CDATA", label);
61 } else {
62 ns = "";
63 prefix = "";
64 imgName = "img";
65 imgAttr.addAttribute("", "src", "src", "CDATA",
66 graphicsPath + num + graphicsExt);
67 imgAttr.addAttribute("", "alt", "alt", "CDATA", label);
68 }
69
70 startSpan(rtf);
71 rtf.startElement(ns, imgName, prefix+imgName, imgAttr);
72 rtf.endElement(ns, imgName, prefix+imgName);
73 endSpan(rtf);
74 } else {
75 formatTextCallout(rtf, callout);
76 }
77 } catch (SAXException e) {
78 System.out.println("SAX Exception in graphics formatCallout");
79 }
80 }
81 }