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.

BatikExtensionElementMapping.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.fo.extensions.svg;
  19. import java.util.HashMap;
  20. import javax.xml.parsers.SAXParserFactory;
  21. import org.apache.batik.util.XMLResourceDescriptor;
  22. import org.apache.fop.fo.ElementMapping;
  23. import org.apache.fop.fo.FONode;
  24. import org.w3c.dom.DOMImplementation;
  25. /**
  26. * This Element Mapping is for Batik SVG Extension elements
  27. * of the http://xml.apache.org/batik/ext namespace.
  28. */
  29. public class BatikExtensionElementMapping extends ElementMapping {
  30. /** Namespace URI for Batik extension elements */
  31. public static final String URI = "http://xml.apache.org/batik/ext";
  32. private boolean batikAvail = true;
  33. /** Main constructor. */
  34. public BatikExtensionElementMapping() {
  35. namespaceURI = URI;
  36. }
  37. /** {@inheritDoc} */
  38. public DOMImplementation getDOMImplementation() {
  39. return null; //no DOMImplementation necessary here
  40. }
  41. /**
  42. * Returns the fully qualified classname of an XML parser for
  43. * Batik classes that apparently need it (error messages, perhaps)
  44. * @return an XML parser classname
  45. */
  46. private String getAParserClassName() {
  47. try {
  48. //TODO Remove when Batik uses JAXP instead of SAX directly.
  49. SAXParserFactory factory = SAXParserFactory.newInstance();
  50. return factory.newSAXParser().getXMLReader().getClass().getName();
  51. } catch (Exception e) {
  52. return null;
  53. }
  54. }
  55. /** initialize mapping */
  56. protected void initialize() {
  57. if (foObjs == null && batikAvail) {
  58. // this sets the parser that will be used
  59. // by default (SVGBrokenLinkProvider)
  60. // normally the user agent value is used
  61. try {
  62. XMLResourceDescriptor.setXMLParserClassName(
  63. getAParserClassName());
  64. foObjs = new HashMap();
  65. foObjs.put("batik", new SE());
  66. foObjs.put(DEFAULT, new SVGMaker());
  67. } catch (Throwable t) {
  68. // if the classes are not available
  69. // the DISPLAY is not checked
  70. batikAvail = false;
  71. }
  72. }
  73. }
  74. static class SVGMaker extends ElementMapping.Maker {
  75. public FONode make(FONode parent) {
  76. return new SVGObj(parent);
  77. }
  78. }
  79. static class SE extends ElementMapping.Maker {
  80. public FONode make(FONode parent) {
  81. return new SVGElement(parent);
  82. }
  83. }
  84. }