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.

AFPResourceLevelDefaults.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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;
  19. import java.util.Iterator;
  20. import java.util.Map;
  21. import org.apache.fop.afp.AFPResourceLevel.ResourceType;
  22. import org.apache.fop.afp.modca.ResourceObject;
  23. /**
  24. * This class holds resource levels defaults for the various resource types.
  25. */
  26. public class AFPResourceLevelDefaults {
  27. private static final Map RESOURCE_TYPE_NAMES = new java.util.HashMap();
  28. static {
  29. //Map to be extended as need arises:
  30. registerResourceTypeName("goca", ResourceObject.TYPE_GRAPHIC);
  31. registerResourceTypeName("bitmap", ResourceObject.TYPE_IMAGE);
  32. }
  33. private static void registerResourceTypeName(String name, byte type) {
  34. RESOURCE_TYPE_NAMES.put(name.toLowerCase(), new Byte(type));
  35. }
  36. private static byte getResourceType(String resourceTypeName) {
  37. Byte result = (Byte)RESOURCE_TYPE_NAMES.get(resourceTypeName.toLowerCase());
  38. if (result == null) {
  39. throw new IllegalArgumentException("Unknown resource type name: " + resourceTypeName);
  40. }
  41. return result.byteValue();
  42. }
  43. private Map defaultResourceLevels = new java.util.HashMap();
  44. /**
  45. * Creates a new instance with default values.
  46. */
  47. public AFPResourceLevelDefaults() {
  48. // level not explicitly set/changed so default to inline for GOCA graphic objects
  49. // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
  50. setDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC,
  51. new AFPResourceLevel(ResourceType.INLINE));
  52. }
  53. /**
  54. * Sets the default resource level for a particular resource type.
  55. * @param type the resource type name
  56. * @param level the resource level
  57. */
  58. public void setDefaultResourceLevel(String type, AFPResourceLevel level) {
  59. setDefaultResourceLevel(getResourceType(type), level);
  60. }
  61. /**
  62. * Sets the default resource level for a particular resource type.
  63. * @param type the resource type ({@link ResourceObject}.TYPE_*)
  64. * @param level the resource level
  65. */
  66. public void setDefaultResourceLevel(byte type, AFPResourceLevel level) {
  67. this.defaultResourceLevels.put(new Byte(type), level);
  68. }
  69. /**
  70. * Returns the default resource level for a particular resource type.
  71. * @param type the resource type ({@link ResourceObject}.TYPE_*)
  72. * @return the default resource level
  73. */
  74. public AFPResourceLevel getDefaultResourceLevel(byte type) {
  75. AFPResourceLevel result = (AFPResourceLevel)this.defaultResourceLevels.get(new Byte(type));
  76. if (result == null) {
  77. result = AFPResourceInfo.DEFAULT_LEVEL;
  78. }
  79. return result;
  80. }
  81. /**
  82. * Allows to merge the values from one instance into another. Values from the instance passed
  83. * in as a parameter override values of this instance.
  84. * @param other the other instance to get the defaults from
  85. */
  86. public void mergeFrom(AFPResourceLevelDefaults other) {
  87. Iterator iter = other.defaultResourceLevels.entrySet().iterator();
  88. while (iter.hasNext()) {
  89. Map.Entry entry = (Map.Entry)iter.next();
  90. Byte type = (Byte)entry.getKey();
  91. AFPResourceLevel level = (AFPResourceLevel)entry.getValue();
  92. this.defaultResourceLevels.put(type, level);
  93. }
  94. }
  95. }