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.

XMLImage.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.image;
  19. // Java
  20. import org.w3c.dom.Document;
  21. import javax.xml.parsers.SAXParserFactory;
  22. /**
  23. * This is an implementation for XML-based images such as SVG.
  24. *
  25. * @see AbstractFopImage
  26. * @see FopImage
  27. */
  28. public class XMLImage extends AbstractFopImage {
  29. private Document doc;
  30. private String namespace = "";
  31. /**
  32. * @see org.apache.fop.image.AbstractFopImage#AbstractFopImage(FopImage.ImageInfo)
  33. */
  34. public XMLImage(FopImage.ImageInfo imgInfo) {
  35. super(imgInfo);
  36. if (imgInfo.data instanceof Document) {
  37. doc = (Document)imgInfo.data;
  38. loaded = loaded | ORIGINAL_DATA;
  39. }
  40. namespace = imgInfo.str;
  41. }
  42. /**
  43. * Returns the fully qualified classname of an XML parser for
  44. * Batik classes that apparently need it (error messages, perhaps)
  45. * @return an XML parser classname
  46. */
  47. public static String getParserName() {
  48. try {
  49. SAXParserFactory factory = SAXParserFactory.newInstance();
  50. return factory.newSAXParser().getXMLReader().getClass().getName();
  51. } catch (Exception e) {
  52. return null;
  53. }
  54. }
  55. /**
  56. * Returns the XML document as a DOM document.
  57. * @return the DOM document
  58. */
  59. public Document getDocument() {
  60. return this.doc;
  61. }
  62. /**
  63. * Returns the namespace of the XML document.
  64. * @return the namespace
  65. */
  66. public String getNameSpace() {
  67. return this.namespace;
  68. }
  69. }