選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AFPDataObjectInfoFactory.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.render.afp;
  19. import java.util.Iterator;
  20. import java.util.Map;
  21. import org.apache.xmlgraphics.image.loader.Image;
  22. import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
  23. import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
  24. import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
  25. /**
  26. * AFP image configurator
  27. */
  28. public class AFPDataObjectInfoFactory {
  29. private final Map dataObjectInfoFactoryMap = new java.util.HashMap();
  30. private final AFPState state;
  31. /**
  32. * Main constructor
  33. *
  34. * @param state the AFP state
  35. */
  36. public AFPDataObjectInfoFactory(AFPState state) {
  37. this.state = state;
  38. init();
  39. }
  40. /**
  41. * Initialises the configurators
  42. */
  43. private void init() {
  44. dataObjectInfoFactoryMap.put(
  45. ImageRendered.class, new AFPImageRenderedFactory(state));
  46. dataObjectInfoFactoryMap.put(
  47. ImageRawCCITTFax.class, new AFPRawCCITTFaxFactory(state));
  48. dataObjectInfoFactoryMap.put(
  49. ImageRawStream.class, new AFPImageRawStreamFactory(state));
  50. };
  51. /**
  52. * Returns the configurator for a given image
  53. *
  54. * @param img the image
  55. * @return the image configurator for the image
  56. */
  57. public AFPAbstractImageFactory getFactory(Image img) {
  58. Class clazz = img.getClass();
  59. AFPAbstractImageFactory configurator
  60. = (AFPAbstractImageFactory)dataObjectInfoFactoryMap.get(clazz);
  61. // not directly matched so try to map ancestor
  62. if (configurator == null) {
  63. Iterator it = dataObjectInfoFactoryMap.keySet().iterator();
  64. while (it.hasNext()) {
  65. Class imageClass = (Class)it.next();
  66. if (imageClass.isInstance(img)) {
  67. return (AFPAbstractImageFactory)dataObjectInfoFactoryMap.get(imageClass);
  68. }
  69. }
  70. }
  71. return configurator;
  72. }
  73. }