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 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.Map;
  22. import org.apache.xmlgraphics.util.QName;
  23. /**
  24. * Abstract base class for all area tree objects.
  25. */
  26. public abstract class AreaTreeObject {
  27. /** Foreign attributes */
  28. protected Map foreignAttributes = null;
  29. /**
  30. * Sets a foreign attribute.
  31. * @param name the qualified name of the attribute
  32. * @param value the attribute value
  33. */
  34. public void setForeignAttribute(QName name, String value) {
  35. if (this.foreignAttributes == null) {
  36. this.foreignAttributes = new java.util.HashMap();
  37. }
  38. this.foreignAttributes.put(name, value);
  39. }
  40. /**
  41. * Set foreign attributes from a Map.
  42. * @param atts a Map with attributes (keys: QName, values: String)
  43. */
  44. public void setForeignAttributes(Map atts) {
  45. if (atts.size() == 0) {
  46. return;
  47. }
  48. Iterator iter = atts.entrySet().iterator();
  49. while (iter.hasNext()) {
  50. Map.Entry entry = (Map.Entry)iter.next();
  51. String value = (String)entry.getValue();
  52. //The casting is only to ensure type safety (too bad we can't use generics, yet)
  53. setForeignAttribute((QName)entry.getKey(), value);
  54. }
  55. }
  56. /**
  57. * Returns the value of a foreign attribute on the area.
  58. * @param name the qualified name of the attribute
  59. * @return the attribute value or null if it isn't set
  60. */
  61. public String getForeignAttributeValue(QName name) {
  62. if (this.foreignAttributes != null) {
  63. return (String)this.foreignAttributes.get(name);
  64. } else {
  65. return null;
  66. }
  67. }
  68. /** @return the foreign attributes associated with this area */
  69. public Map getForeignAttributes() {
  70. if (this.foreignAttributes != null) {
  71. return Collections.unmodifiableMap(this.foreignAttributes);
  72. } else {
  73. return Collections.EMPTY_MAP;
  74. }
  75. }
  76. }