1 17 18 19 20 package org.apache.fop.fo.extensions.svg; 21 22 import java.util.HashMap ; 23 import javax.xml.parsers.SAXParserFactory ; 24 25 import org.apache.fop.fo.FONode; 26 import org.apache.fop.fo.ElementMapping; 27 28 import org.apache.batik.util.XMLResourceDescriptor; 29 import org.apache.batik.dom.svg.SVGDOMImplementation; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.w3c.dom.DOMImplementation ; 33 34 39 public class SVGElementMapping extends ElementMapping { 40 41 42 public static final String URI = SVGDOMImplementation.SVG_NAMESPACE_URI; 43 44 45 protected Log log = LogFactory.getLog(SVGElementMapping.class); 46 47 private boolean batikAvailable = true; 48 49 50 public SVGElementMapping() { 51 namespaceURI = URI; 52 } 53 54 55 public DOMImplementation getDOMImplementation() { 56 return SVGDOMImplementation.getDOMImplementation(); 57 } 58 59 64 private String getAParserClassName() { 65 try { 66 SAXParserFactory factory = SAXParserFactory.newInstance(); 67 return factory.newSAXParser().getXMLReader().getClass().getName(); 68 } catch (Exception e) { 69 return null; 70 } 71 } 72 73 74 protected void initialize() { 75 if (foObjs == null && batikAvailable) { 76 try { 80 XMLResourceDescriptor.setXMLParserClassName( 81 getAParserClassName()); 82 83 foObjs = new HashMap (); 84 foObjs.put("svg", new SE()); 85 foObjs.put(DEFAULT, new SVGMaker()); 86 } catch (Throwable t) { 87 log.error("Error while initializing the Batik SVG extensions", t); 88 batikAvailable = false; 91 } 92 } 93 } 94 95 96 public String getStandardPrefix() { 97 return "svg"; 98 } 99 100 static class SVGMaker extends ElementMapping.Maker { 101 public FONode make(FONode parent) { 102 return new SVGObj(parent); 103 } 104 } 105 106 static class SE extends ElementMapping.Maker { 107 public FONode make(FONode parent) { 108 return new SVGElement(parent); 109 } 110 } 111 112 } 113 | Popular Tags |