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 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 label = area.getAttribute("label"); 52 } else { 53 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 public void startSpan(Emitter rtf) 66 throws TransformerException { 67 if (!foStylesheet && namePool != null) { 69 int spanName = namePool.allocate("", "", "span"); 70 AttributeCollection spanAttr = new AttributeCollection(namePool); 71 int namespaces[] = new int[1]; 72 spanAttr.addAttribute("", "", "class", "CDATA", "co"); 73 rtf.startElement(spanName, spanAttr, namespaces, 0); 74 } 75 } 76 77 public void endSpan(Emitter rtf) 78 throws TransformerException { 79 if (!foStylesheet && namePool != null) { 81 int spanName = namePool.allocate("", "", "span"); 82 rtf.endElement(spanName); 83 } 84 } 85 86 public void formatTextCallout(Emitter rtfEmitter, 87 Callout callout) { 88 Element area = callout.getArea(); 89 int num = callout.getCallout(); 90 String userLabel = areaLabel(area); 91 String label = "(" + num + ")"; 92 93 if (userLabel != null) { 94 label = userLabel; 95 } 96 97 char chars[] = label.toCharArray(); 98 99 try { 100 startSpan(rtfEmitter); 101 rtfEmitter.characters(chars, 0, label.length()); 102 endSpan(rtfEmitter); 103 } catch (TransformerException e) { 104 System.out.println("Transformer Exception in formatTextCallout"); 105 } 106 } 107 108 public abstract void formatCallout(Emitter rtfEmitter, 109 Callout callout); 110 } 111 112 | Popular Tags |