KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.nwalsh.xalan;
2
3 import org.xml.sax.helpers.AttributesImpl JavaDoc;
4 import org.xml.sax.SAXException JavaDoc;
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  * <p>$Id: FormatGraphicCallout.java,v 1.1 2001/04/02 13:03:45 nwalsh 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.1 2001/04/02 13:03:45 nwalsh Exp $
29  **/

30
31 public class FormatGraphicCallout extends FormatCallout {
32   String JavaDoc graphicsPath = "";
33   String JavaDoc graphicsExt = "";
34   int graphicsMax = 0;
35
36   public FormatGraphicCallout(String JavaDoc path, String JavaDoc ext, int max, boolean fo) {
37     graphicsPath = path;
38     graphicsExt = ext;
39     graphicsMax = max;
40     stylesheetFO = fo;
41   }
42
43   public void formatCallout(DOMBuilder rtf,
44                 Callout callout) {
45     Element area = callout.getArea();
46     int num = callout.getCallout();
47     String JavaDoc label = areaLabel(area);
48
49     try {
50       if (label == null && num <= graphicsMax) {
51     AttributesImpl JavaDoc imgAttr = new AttributesImpl JavaDoc();
52     String JavaDoc ns = "";
53     String JavaDoc prefix = "";
54     String JavaDoc 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", label);
63     } else {
64       ns = "";
65       prefix = "";
66       imgName = "img";
67       imgAttr.addAttribute("", "src", "src", "CDATA",
68                    graphicsPath + num + graphicsExt);
69       imgAttr.addAttribute("", "alt", "alt", "CDATA", label);
70     }
71
72     startSpan(rtf);
73     rtf.startElement(ns, imgName, prefix+imgName, imgAttr);
74     rtf.endElement(ns, imgName, prefix+imgName);
75     endSpan(rtf);
76       } else {
77     formatTextCallout(rtf, callout);
78       }
79     } catch (SAXException JavaDoc e) {
80       System.out.println("SAX Exception in graphics formatCallout");
81     }
82   }
83 }
84
Popular Tags