Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/nwalsh/saxon/FormatGraphicCallout.java


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   *
18   * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
19   *
20   * <p><b>Change Log:</b></p>
21   * <dl>
22   * <dt>1.0</dt>
23   * <dd><p>Initial release.</p></dd>
24   * </dl>
25   *
26   * @author Norman Walsh
27   * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
28   *
29   * @see Verbatim
30   *
31   **/
32  
33  public class FormatGraphicCallout extends FormatCallout {
34    String graphicsPath = "";
35    String graphicsExt = "";
36    int graphicsMax = 0;
37  
38    public FormatGraphicCallout(NamePool nPool, String path, String ext, int max, boolean fo) {
39      super(nPool, fo);
40      graphicsPath = path;
41      graphicsExt = ext;
42      graphicsMax = max;
43    }
44  
45    public void formatCallout(Emitter rtfEmitter,
46            Callout callout) {
47      Element area = callout.getArea();
48      int num = callout.getCallout();
49      String userLabel = areaLabel(area);
50      String label = "(" + num + ")";
51  
52      if (userLabel != null) {
53        label = userLabel;
54      }
55  
56      try {
57        if (userLabel == null && num <= graphicsMax) {
58    int imgName = 0;
59    AttributeCollection imgAttr = null;
60    int namespaces[] = new int[1];
61  
62    if (foStylesheet) {
63      imgName = namePool.allocate("fo", foURI, "external-graphic");
64      imgAttr = new AttributeCollection(namePool);
65      imgAttr.addAttribute("", "", "src", "CDATA",
66               graphicsPath + num + graphicsExt);
67    } else {
68      imgName = namePool.allocate("", "", "img");
69      imgAttr = new AttributeCollection(namePool);
70      imgAttr.addAttribute("", "", "src", "CDATA",
71               graphicsPath + num + graphicsExt);
72      imgAttr.addAttribute("", "", "alt", "CDATA", label);
73    }
74  
75    startSpan(rtfEmitter);
76    rtfEmitter.startElement(imgName, imgAttr, namespaces, 0);
77    rtfEmitter.endElement(imgName);
78    endSpan(rtfEmitter);
79        } else {
80    formatTextCallout(rtfEmitter, callout);
81        }
82      } catch (TransformerException e) {
83        System.out.println("Transformer Exception in graphic formatCallout");
84      }
85    }
86  }