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.

ElementMapping.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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;
  19. import java.util.HashMap;
  20. import javax.xml.parsers.DocumentBuilderFactory;
  21. import javax.xml.parsers.ParserConfigurationException;
  22. import org.w3c.dom.DOMImplementation;
  23. import org.apache.xmlgraphics.util.QName;
  24. /**
  25. * Abstract base class for Element Mappings (including FO Element Mappings)
  26. * which provide the framework of valid elements and attributes for a given
  27. * namespace.
  28. */
  29. public abstract class ElementMapping {
  30. /** constant for defining the default value */
  31. public static final String DEFAULT = "<default>";
  32. /** The HashMap table of formatting objects defined by the ElementMapping */
  33. protected HashMap<String, Maker> foObjs;
  34. //Please don't change that to java.util.Map as that can break extensions.
  35. /** The namespace for the ElementMapping */
  36. protected String namespaceURI;
  37. /**
  38. * Returns a HashMap of maker objects for this element mapping
  39. *
  40. * @return Table of Maker objects for this ElementMapping
  41. */
  42. public HashMap<String, Maker> getTable() {
  43. if (foObjs == null) {
  44. initialize();
  45. }
  46. return foObjs;
  47. }
  48. /**
  49. * Returns the namespace URI for this element mapping
  50. *
  51. * @return Namespace URI for this element mapping
  52. */
  53. public String getNamespaceURI() {
  54. return namespaceURI;
  55. }
  56. /**
  57. * Returns the DOMImplementation used by this ElementMapping. The value returned may be null
  58. * for cases where no DOM is used to represent the element tree (XSL-FO, for example). This
  59. * method is used by the intermediate format to instantiate the right kind of DOM document
  60. * for foreign objects. For example, SVG handled through Apache Batik has to use a special
  61. * DOMImplementation.
  62. * @return the DOMImplementation used by this ElementMapping, may be null
  63. */
  64. public DOMImplementation getDOMImplementation() {
  65. return null; //For namespaces not used in foreign objects
  66. }
  67. /**
  68. * @return the default DOMImplementation when no specialized DOM is necessary.
  69. */
  70. public static DOMImplementation getDefaultDOMImplementation() {
  71. DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
  72. fact.setNamespaceAware(true);
  73. fact.setValidating(false);
  74. try {
  75. return fact.newDocumentBuilder().getDOMImplementation();
  76. } catch (ParserConfigurationException e) {
  77. throw new RuntimeException(
  78. "Cannot return default DOM implementation: " + e.getMessage());
  79. }
  80. }
  81. /** @return the standard namespace prefix for this namespace or null if it is not known. */
  82. public String getStandardPrefix() {
  83. return null;
  84. }
  85. /**
  86. * Indicates whether a particular attribute of the namespace is a property, i.e. the attribute
  87. * value should be converted to a property value.
  88. * @param attributeName the attribute name
  89. * @return true if the attribute should be converted to a property
  90. */
  91. public boolean isAttributeProperty(QName attributeName) {
  92. return false;
  93. }
  94. /**
  95. * Initializes the set of maker objects associated with this ElementMapping
  96. */
  97. protected abstract void initialize();
  98. /**
  99. * Base class for all Makers. It is responsible to return the right kind of FONode for a
  100. * particular element.
  101. */
  102. public static class Maker {
  103. /**
  104. * Creates a new FONode (or rather a specialized subclass of it).
  105. * @param parent the parent FONode
  106. * @return the newly created FONode instance
  107. */
  108. public FONode make(FONode parent) {
  109. return null;
  110. }
  111. }
  112. }