1 18 package org.apache.batik.dom.svg12; 19 20 import java.net.URL ; 21 22 import org.apache.batik.css.engine.CSSContext; 23 import org.apache.batik.css.engine.CSSEngine; 24 import org.apache.batik.css.engine.SVG12CSSEngine; 25 import org.apache.batik.css.engine.value.ShorthandManager; 26 import org.apache.batik.css.engine.value.ValueManager; 27 import org.apache.batik.css.parser.ExtendedParser; 28 import org.apache.batik.dom.AbstractDocument; 29 import org.apache.batik.dom.AbstractStylableDocument; 30 import org.apache.batik.dom.GenericElement; 31 import org.apache.batik.dom.GenericElementNS; 32 import org.apache.batik.dom.svg.SVGDOMImplementation; 33 import org.apache.batik.dom.svg.SVGOMDocument; 34 import org.apache.batik.dom.util.HashTable; 35 import org.apache.batik.dom.util.DOMUtilities; 36 import org.apache.batik.util.SVG12Constants; 37 38 39 import org.w3c.css.sac.InputSource; 40 import org.w3c.dom.Document ; 41 import org.w3c.dom.DocumentType ; 42 import org.w3c.dom.DOMImplementation ; 43 import org.w3c.dom.DOMException ; 44 import org.w3c.dom.Element ; 45 46 53 public class SVG12DOMImplementation 54 extends SVGDOMImplementation { 55 56 59 public SVG12DOMImplementation() { 60 factories = svg12Factories; 61 registerFeature("CSS", "2.0"); 62 registerFeature("StyleSheets", "2.0"); 63 registerFeature("SVG", new String [] {"1.0", "1.1", "1.2"}); 64 registerFeature("SVGEvents", new String [] {"1.0", "1.1", "1.2"}); 65 } 66 67 public CSSEngine createCSSEngine(AbstractStylableDocument doc, 68 CSSContext ctx, 69 ExtendedParser ep, 70 ValueManager [] vms, 71 ShorthandManager [] sms) { 72 URL durl = ((SVGOMDocument)doc).getURLObject(); 73 CSSEngine result = new SVG12CSSEngine(doc, durl, ep, vms, sms, ctx); 74 75 URL url = getClass().getResource("resources/UserAgentStyleSheet.css"); 76 if (url != null) { 77 InputSource is = new InputSource(url.toString()); 78 result.setUserAgentStyleSheet 79 (result.parseStyleSheet(is, url, "all")); 80 } 81 82 return result; 83 } 84 85 89 public Document createDocument(String namespaceURI, 90 String qualifiedName, 91 DocumentType doctype) 92 throws DOMException { 93 Document result = new SVGOMDocument(doctype, this); 94 if (qualifiedName != null) 96 result.appendChild(result.createElementNS(namespaceURI, 97 qualifiedName)); 98 return result; 99 } 100 101 105 public Element createElementNS(AbstractDocument document, 106 String namespaceURI, 107 String qualifiedName) { 108 if (namespaceURI == null) 109 return new GenericElement(qualifiedName.intern(), document); 110 111 if (SVG12Constants.SVG_NAMESPACE_URI.equals(namespaceURI)) { 112 String name = DOMUtilities.getLocalName(qualifiedName); 113 ElementFactory ef = (ElementFactory)factories.get(name); 114 if (ef != null) 115 return ef.create(DOMUtilities.getPrefix(qualifiedName), 116 document); 117 } 118 return new GenericElementNS(namespaceURI.intern(), 119 qualifiedName.intern(), 120 document); 121 } 122 123 125 128 protected static HashTable svg12Factories = new HashTable(svg11Factories); 129 130 static { 131 svg12Factories.put(SVG12Constants.SVG_FLOW_DIV_TAG, 132 new FlowDivElementFactory()); 133 134 svg12Factories.put(SVG12Constants.SVG_FLOW_LINE_TAG, 135 new FlowLineElementFactory()); 136 137 svg12Factories.put(SVG12Constants.SVG_FLOW_PARA_TAG, 138 new FlowParaElementFactory()); 139 140 svg12Factories.put(SVG12Constants.SVG_FLOW_REGION_BREAK_TAG, 141 new FlowRegionBreakElementFactory()); 142 143 svg12Factories.put(SVG12Constants.SVG_FLOW_REGION_TAG, 144 new FlowRegionElementFactory()); 145 146 svg12Factories.put(SVG12Constants.SVG_FLOW_REGION_EXCLUDE_TAG, 147 new FlowRegionExcludeElementFactory()); 148 149 svg12Factories.put(SVG12Constants.SVG_FLOW_ROOT_TAG, 150 new FlowRootElementFactory()); 151 152 svg12Factories.put(SVG12Constants.SVG_FLOW_SPAN_TAG, 153 new FlowSpanElementFactory()); 154 155 svg12Factories.put(SVG12Constants.SVG_MULTI_IMAGE_TAG, 156 new MultiImageElementFactory()); 157 158 svg12Factories.put(SVG12Constants.SVG_SOLID_COLOR_TAG, 159 new SolidColorElementFactory()); 160 161 svg12Factories.put(SVG12Constants.SVG_SUB_IMAGE_TAG, 162 new SubImageElementFactory()); 163 164 svg12Factories.put(SVG12Constants.SVG_SUB_IMAGE_REF_TAG, 165 new SubImageRefElementFactory()); 166 167 } 168 169 172 protected static class FlowDivElementFactory 173 implements ElementFactory { 174 public FlowDivElementFactory() { 175 } 176 179 public Element create(String prefix, Document doc) { 180 return new SVGOMFlowDivElement(prefix, (AbstractDocument)doc); 181 } 182 } 183 184 187 protected static class FlowLineElementFactory 188 implements ElementFactory { 189 public FlowLineElementFactory() { 190 } 191 194 public Element create(String prefix, Document doc) { 195 return new SVGOMFlowLineElement(prefix, (AbstractDocument)doc); 196 } 197 } 198 199 202 protected static class FlowParaElementFactory 203 implements ElementFactory { 204 public FlowParaElementFactory() { 205 } 206 209 public Element create(String prefix, Document doc) { 210 return new SVGOMFlowParaElement(prefix, (AbstractDocument)doc); 211 } 212 } 213 214 217 protected static class FlowRegionBreakElementFactory 218 implements ElementFactory { 219 public FlowRegionBreakElementFactory() { 220 } 221 224 public Element create(String prefix, Document doc) { 225 return new SVGOMFlowRegionBreakElement(prefix, (AbstractDocument)doc); 226 } 227 } 228 229 232 protected static class FlowRegionElementFactory 233 implements ElementFactory { 234 public FlowRegionElementFactory() { 235 } 236 239 public Element create(String prefix, Document doc) { 240 return new SVGOMFlowRegionElement(prefix, (AbstractDocument)doc); 241 } 242 } 243 244 247 protected static class FlowRegionExcludeElementFactory 248 implements ElementFactory { 249 public FlowRegionExcludeElementFactory() { 250 } 251 254 public Element create(String prefix, Document doc) { 255 return new SVGOMFlowRegionExcludeElement(prefix, (AbstractDocument)doc); 256 } 257 } 258 259 262 protected static class FlowRootElementFactory 263 implements ElementFactory { 264 public FlowRootElementFactory() { 265 } 266 269 public Element create(String prefix, Document doc) { 270 return new SVGOMFlowRootElement(prefix, (AbstractDocument)doc); 271 } 272 } 273 274 277 protected static class FlowSpanElementFactory 278 implements ElementFactory { 279 public FlowSpanElementFactory() { 280 } 281 284 public Element create(String prefix, Document doc) { 285 return new SVGOMFlowSpanElement(prefix, (AbstractDocument)doc); 286 } 287 } 288 291 protected static class MultiImageElementFactory 292 implements ElementFactory { 293 public MultiImageElementFactory() {} 294 297 public Element create(String prefix, Document doc) { 298 return new SVGOMMultiImageElement 299 (prefix, (AbstractDocument)doc); 300 } 301 } 302 303 306 protected static class SolidColorElementFactory 307 implements ElementFactory { 308 public SolidColorElementFactory() { 309 } 310 313 public Element create(String prefix, Document doc) { 314 return new SVGOMSolidColorElement(prefix, (AbstractDocument)doc); 315 } 316 } 317 318 321 protected static class SubImageElementFactory 322 implements ElementFactory { 323 public SubImageElementFactory() {} 324 327 public Element create(String prefix, Document doc) { 328 return new SVGOMSubImageElement(prefix, (AbstractDocument)doc); 329 } 330 } 331 332 335 protected static class SubImageRefElementFactory 336 implements ElementFactory { 337 public SubImageRefElementFactory() {} 338 341 public Element create(String prefix, Document doc) { 342 return new SVGOMSubImageRefElement(prefix, (AbstractDocument)doc); 343 } 344 } 345 346 349 protected final static DOMImplementation DOM_IMPLEMENTATION = 350 new SVG12DOMImplementation(); 351 352 355 public static DOMImplementation getDOMImplementation() { 356 return DOM_IMPLEMENTATION; 357 } 358 } 359 | Popular Tags |