01: package com.nwalsh.xalan;
02:
03: import org.xml.sax.helpers.AttributesImpl;
04: import org.xml.sax.SAXException;
05: import org.w3c.dom.*;
06: import org.apache.xml.utils.DOMBuilder;
07: import com.nwalsh.xalan.Callout;
08: import org.apache.xml.utils.AttList;
09:
10: /**
11: * <p>Utility class for the Verbatim extension (ignore this).</p>
12: *
13: * <p>$Id: FormatGraphicCallout.java,v 1.4 2005-08-30 08:14:58 draganr Exp $</p>
14: *
15: * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
16: *
17: * <p><b>Change Log:</b></p>
18: * <dl>
19: * <dt>1.0</dt>
20: * <dd><p>Initial release.</p></dd>
21: * </dl>
22: *
23: * @author Norman Walsh
24: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
25: *
26: * @see Verbatim
27: *
28: * @version $Id: FormatGraphicCallout.java,v 1.4 2005-08-30 08:14:58 draganr Exp $
29: **/
30:
31: public class FormatGraphicCallout extends FormatCallout {
32: String graphicsPath = "";
33: String graphicsExt = "";
34: int graphicsMax = 0;
35:
36: public FormatGraphicCallout(String path, String ext, int max,
37: boolean fo) {
38: graphicsPath = path;
39: graphicsExt = ext;
40: graphicsMax = max;
41: stylesheetFO = fo;
42: }
43:
44: public void formatCallout(DOMBuilder rtf, Callout callout) {
45: Element area = callout.getArea();
46: int num = callout.getCallout();
47: String label = areaLabel(area);
48:
49: try {
50: if (label == null && num <= graphicsMax) {
51: AttributesImpl imgAttr = new AttributesImpl();
52: String ns = "";
53: String prefix = "";
54: String imgName = "";
55:
56: if (stylesheetFO) {
57: ns = foURI;
58: prefix = "fo:"; // FIXME: this could be a problem...
59: imgName = "external-graphic";
60: imgAttr.addAttribute("", "src", "src", "CDATA",
61: graphicsPath + num + graphicsExt);
62: imgAttr.addAttribute("", "alt", "alt", "CDATA",
63: label);
64: } else {
65: ns = "";
66: prefix = "";
67: imgName = "img";
68: imgAttr.addAttribute("", "src", "src", "CDATA",
69: graphicsPath + num + graphicsExt);
70: imgAttr.addAttribute("", "alt", "alt", "CDATA",
71: label);
72: }
73:
74: startSpan(rtf);
75: rtf
76: .startElement(ns, imgName, prefix + imgName,
77: imgAttr);
78: rtf.endElement(ns, imgName, prefix + imgName);
79: endSpan(rtf);
80: } else {
81: formatTextCallout(rtf, callout);
82: }
83: } catch (SAXException e) {
84: System.out
85: .println("SAX Exception in graphics formatCallout");
86: }
87: }
88: }
|