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.

AreaTreeObject.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.area;
  19. import java.util.Collections;
  20. import java.util.Iterator;
  21. import java.util.List;
  22. import java.util.Map;
  23. import org.apache.xmlgraphics.util.QName;
  24. import org.apache.fop.fo.extensions.ExtensionAttachment;
  25. /**
  26. * Abstract base class for all area tree objects.
  27. */
  28. public abstract class AreaTreeObject {
  29. /** Foreign attributes */
  30. protected Map foreignAttributes = null;
  31. /** Extension attachments */
  32. protected List/*<ExtensionAttachment>*/ extensionAttachments = null;
  33. /**
  34. * Sets a foreign attribute.
  35. * @param name the qualified name of the attribute
  36. * @param value the attribute value
  37. */
  38. public void setForeignAttribute(QName name, String value) {
  39. if (this.foreignAttributes == null) {
  40. this.foreignAttributes = new java.util.HashMap();
  41. }
  42. this.foreignAttributes.put(name, value);
  43. }
  44. /**
  45. * Set foreign attributes from a Map.
  46. * @param atts a Map with attributes (keys: QName, values: String)
  47. */
  48. public void setForeignAttributes(Map atts) {
  49. if (atts.size() == 0) {
  50. return;
  51. }
  52. Iterator iter = atts.entrySet().iterator();
  53. while (iter.hasNext()) {
  54. Map.Entry entry = (Map.Entry)iter.next();
  55. String value = (String)entry.getValue();
  56. //The casting is only to ensure type safety (too bad we can't use generics, yet)
  57. setForeignAttribute((QName)entry.getKey(), value);
  58. }
  59. }
  60. /**
  61. * Returns the value of a foreign attribute on the area.
  62. * @param name the qualified name of the attribute
  63. * @return the attribute value or null if it isn't set
  64. */
  65. public String getForeignAttributeValue(QName name) {
  66. if (this.foreignAttributes != null) {
  67. return (String)this.foreignAttributes.get(name);
  68. } else {
  69. return null;
  70. }
  71. }
  72. /** @return the foreign attributes associated with this area */
  73. public Map getForeignAttributes() {
  74. if (this.foreignAttributes != null) {
  75. return Collections.unmodifiableMap(this.foreignAttributes);
  76. } else {
  77. return Collections.EMPTY_MAP;
  78. }
  79. }
  80. private void prepareExtensionAttachmentContainer() {
  81. if (this.extensionAttachments == null) {
  82. this.extensionAttachments = new java.util.ArrayList/*<ExtensionAttachment>*/();
  83. }
  84. }
  85. /**
  86. * Adds a new ExtensionAttachment instance to this page.
  87. * @param attachment the ExtensionAttachment
  88. */
  89. public void addExtensionAttachment(ExtensionAttachment attachment) {
  90. prepareExtensionAttachmentContainer();
  91. extensionAttachments.add(attachment);
  92. }
  93. /**
  94. * Set extension attachments from a List
  95. * @param extensionAttachments a List with extension attachments
  96. */
  97. public void setExtensionAttachments(List extensionAttachments) {
  98. prepareExtensionAttachmentContainer();
  99. this.extensionAttachments.addAll(extensionAttachments);
  100. }
  101. /** @return the extension attachments associated with this area */
  102. public List getExtensionAttachments() {
  103. if (this.extensionAttachments != null) {
  104. return Collections.unmodifiableList(this.extensionAttachments);
  105. } else {
  106. return Collections.EMPTY_LIST;
  107. }
  108. }
  109. /**
  110. * Indicates whether this area tree object has any extension attachments.
  111. * @return true if there are extension attachments
  112. */
  113. public boolean hasExtensionAttachments() {
  114. return this.extensionAttachments != null && !this.extensionAttachments.isEmpty();
  115. }
  116. }