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.3KB

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