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.

AbstractEnvironmentGroup.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.util.List;
  22. /**
  23. * A base class that encapsulates common features of
  24. * ActiveEnvironmentGroup and ResourceEnvironmentGroup
  25. */
  26. public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject {
  27. /** the collection of MapDataResource objects */
  28. protected final List mapDataResources = null;
  29. /** the collection of MapPageOverlay objects */
  30. protected List mapPageOverlays;
  31. /**
  32. * Main constructor
  33. *
  34. * @param name the object name
  35. */
  36. public AbstractEnvironmentGroup(String name) {
  37. super(name);
  38. }
  39. private List getMapPageOverlays() {
  40. if (mapPageOverlays == null) {
  41. mapPageOverlays = new java.util.ArrayList();
  42. }
  43. return mapPageOverlays;
  44. }
  45. /**
  46. * Actually creates the MPO object.
  47. * Also creates the supporting object (an IPO)
  48. *
  49. * @param name the name of the overlay to be used
  50. */
  51. public void createOverlay(String name) {
  52. MapPageOverlay mpo = getCurrentMapPageOverlay();
  53. if (mpo == null) {
  54. mpo = new MapPageOverlay();
  55. getMapPageOverlays().add(mpo);
  56. }
  57. try {
  58. mpo.addOverlay(name);
  59. } catch (MaximumSizeExceededException msee) {
  60. mpo = new MapPageOverlay();
  61. getMapPageOverlays().add(mpo);
  62. try {
  63. mpo.addOverlay(name);
  64. } catch (MaximumSizeExceededException ex) {
  65. // Should never happen (but log just in case)
  66. LOG.error("createOverlay():: resulted in a MaximumSizeExceededException");
  67. }
  68. }
  69. }
  70. /**
  71. * Getter method for the most recent MapPageOverlay added to the
  72. * Active Environment Group (returns null if no MapPageOverlay exist)
  73. *
  74. * @return the most recent Map Coded Font
  75. */
  76. private MapPageOverlay getCurrentMapPageOverlay() {
  77. return (MapPageOverlay)getLastElement(this.mapPageOverlays);
  78. }
  79. /**
  80. * Get last element.
  81. * @param list of elements
  82. * @return last element or null if none
  83. */
  84. protected Object getLastElement(List list) {
  85. if (list != null && list.size() > 0) {
  86. return list.get(list.size() - 1);
  87. } else {
  88. return null;
  89. }
  90. }
  91. /** {@inheritDoc} */
  92. protected void writeContent(OutputStream os) throws IOException {
  93. super.writeContent(os);
  94. }
  95. }