1 package com.nwalsh.xalan; 2 3 import org.xml.sax.SAXException ; 4 import org.xml.sax.helpers.AttributesImpl ; 5 import org.w3c.dom.*; 6 import org.apache.xml.utils.DOMBuilder; 7 import com.nwalsh.xalan.Callout; 8 9 29 30 public abstract class FormatCallout { 31 protected static final String foURI = "http://www.w3.org/1999/XSL/Format"; 32 protected static final String xhURI = "http://www.w3.org/1999/xhtml"; 33 protected boolean stylesheetFO = false; 34 35 public FormatCallout() { 36 } 38 39 public String areaLabel(Element area) { 40 String label = null; 41 42 if (area.getAttribute("label") != null) { 43 label = area.getAttribute("label"); 45 } else { 46 Element parent = (Element) area.getParentNode(); 48 if (parent != null 49 && parent.getNodeName().equals("areaset") 50 && parent.getAttribute("label") != null) { 51 label = parent.getAttribute("label"); 52 } 53 } 54 55 return label; 56 } 57 58 public void startSpan(DOMBuilder rtf) 59 throws SAXException { 60 if (!stylesheetFO) { 62 AttributesImpl spanAttr = new AttributesImpl (); 63 spanAttr.addAttribute("", "class", "class", "CDATA", "co"); 64 rtf.startElement("", "span", "span", spanAttr); 65 } 66 } 67 68 public void endSpan(DOMBuilder rtf) 69 throws SAXException { 70 if (!stylesheetFO) { 72 rtf.endElement("", "span", "span"); 73 } 74 } 75 76 public void formatTextCallout(DOMBuilder rtf, 77 Callout callout) { 78 Element area = callout.getArea(); 79 int num = callout.getCallout(); 80 String userLabel = areaLabel(area); 81 String label = "(" + num + ")"; 82 83 if (userLabel != null) { 84 label = userLabel; 85 } 86 87 char chars[] = label.toCharArray(); 88 89 try { 90 startSpan(rtf); 91 rtf.characters(chars, 0, label.length()); 92 endSpan(rtf); 93 } catch (SAXException e) { 94 System.out.println("SAX Exception in text formatCallout"); 95 } 96 } 97 98 public abstract void formatCallout(DOMBuilder rtf, 99 Callout callout); 100 } 101 102 | Popular Tags |