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.

FOPSAXSVGDocumentFactory.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.svg;
  19. import java.io.IOException;
  20. import org.w3c.dom.Document;
  21. import org.xml.sax.EntityResolver;
  22. import org.xml.sax.InputSource;
  23. import org.xml.sax.SAXException;
  24. import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
  25. /**
  26. * This is a special subclass to allow setting a special EntityResolver.
  27. */
  28. public class FOPSAXSVGDocumentFactory extends SAXSVGDocumentFactory {
  29. private EntityResolver additionalResolver;
  30. /**
  31. * Creates a new DocumentFactory object.
  32. * @param parser The SAX2 parser classname.
  33. */
  34. public FOPSAXSVGDocumentFactory(String parser) {
  35. super(parser);
  36. }
  37. /**
  38. * Sets an additional entity resolver. It will be used before the default
  39. * entity resolving.
  40. * @param resolver Additional resolver
  41. */
  42. public void setAdditionalEntityResolver(EntityResolver resolver) {
  43. this.additionalResolver = resolver;
  44. }
  45. /**
  46. * {@inheritDoc}
  47. */
  48. public InputSource resolveEntity(String publicId, String systemId)
  49. throws SAXException {
  50. if (this.additionalResolver != null) {
  51. try {
  52. InputSource result = this.additionalResolver.resolveEntity(publicId, systemId);
  53. if (result != null) {
  54. return result;
  55. }
  56. } catch (IOException ioe) {
  57. /**@todo Batik's SAXSVGDocumentFactory should throw IOException,
  58. * so we don't have to handle it here. */
  59. throw new SAXException(ioe);
  60. }
  61. }
  62. return super.resolveEntity(publicId, systemId);
  63. }
  64. /**
  65. * Returns the document built up by handling the incoming SAX events. This method will not
  66. * return any instance for the first SAX events have been received.
  67. * @return the DOM document
  68. */
  69. public Document getDocument() {
  70. return this.document;
  71. }
  72. }