You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SVGImage.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.image;
  8. // Java
  9. import java.net.URL;
  10. import org.w3c.dom.svg.SVGDocument;
  11. // FOP
  12. import org.apache.fop.apps.Driver;
  13. import org.apache.fop.image.analyser.ImageReader;
  14. import org.apache.fop.image.analyser.SVGReader;
  15. import org.apache.fop.fo.FOUserAgent;
  16. import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  17. /**
  18. * @see AbstractFopImage
  19. * @see FopImage
  20. */
  21. public class SVGImage extends AbstractFopImage {
  22. SVGDocument doc;
  23. public SVGImage(URL href, ImageReader imgReader) {
  24. super(href, imgReader);
  25. if(imgReader instanceof SVGReader) {
  26. doc = ((SVGReader)imgReader).getDocument();
  27. }
  28. }
  29. /**
  30. * creates a SAX parser, using the value of org.xml.sax.parser
  31. * defaulting to org.apache.xerces.parsers.SAXParser
  32. *
  33. * @return the created SAX parser
  34. */
  35. public static String getParserName() {
  36. String parserClassName = Driver.getParserClassName();
  37. return parserClassName;
  38. }
  39. protected boolean loadData(FOUserAgent ua) {
  40. try {
  41. SAXSVGDocumentFactory factory =
  42. new SAXSVGDocumentFactory(SVGImage.getParserName());
  43. doc = factory.createDocument(this.m_href.toExternalForm());
  44. } catch (Exception e) {
  45. ua.getLogger().error("Could not load external SVG: "
  46. + e.getMessage(), e);
  47. return false;
  48. }
  49. return true;
  50. }
  51. public SVGDocument getSVGDocument() {
  52. return doc;
  53. }
  54. }