Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ImageReaderFactory.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.image.analyser;
  19. // Java
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import org.apache.commons.logging.Log;
  25. import org.apache.commons.logging.LogFactory;
  26. import org.apache.fop.apps.FOUserAgent;
  27. import org.apache.fop.image.FopImage;
  28. import org.apache.xmlgraphics.util.Service;
  29. /**
  30. * Factory for ImageReader objects.
  31. *
  32. * @author Pankaj Narula
  33. * @version $Id$
  34. */
  35. public class ImageReaderFactory {
  36. private static List formats = new java.util.ArrayList();
  37. /** logger */
  38. protected static Log log = LogFactory.getLog(ImageReaderFactory.class);
  39. static {
  40. registerFormat(new JPEGReader());
  41. registerFormat(new BMPReader());
  42. registerFormat(new GIFReader());
  43. registerFormat(new PNGReader());
  44. registerFormat(new TIFFReader());
  45. registerFormat(new EPSReader());
  46. registerFormat(new EMFReader());
  47. //Dynamic registration of ImageReaders
  48. Iterator iter = Service.providers(ImageReader.class, true);
  49. while (iter.hasNext()) {
  50. registerFormat((ImageReader)iter.next());
  51. }
  52. // the xml parser through batik closes the stream when finished
  53. // so there is a workaround in the SVGReader
  54. registerFormat(new SVGReader());
  55. registerFormat(new SVGZReader());
  56. registerFormat(new XMLReader());
  57. }
  58. /**
  59. * Registers a new ImageReader.
  60. *
  61. * @param reader An ImageReader instance
  62. */
  63. public static void registerFormat(ImageReader reader) {
  64. formats.add(reader);
  65. }
  66. /**
  67. * ImageReader maker.
  68. *
  69. * @param uri URI to the image
  70. * @param in image input stream
  71. * @param ua user agent
  72. * @return An ImageInfo object describing the image
  73. */
  74. public static FopImage.ImageInfo make(String uri, InputStream in,
  75. FOUserAgent ua) {
  76. ImageReader reader;
  77. try {
  78. for (int count = 0; count < formats.size(); count++) {
  79. reader = (ImageReader) formats.get(count);
  80. FopImage.ImageInfo info = reader.verifySignature(uri, in, ua);
  81. if (info != null) {
  82. return info;
  83. }
  84. }
  85. log.warn("No ImageReader found for " + uri);
  86. in.close();
  87. } catch (IOException ex) {
  88. log.error("Error while recovering Image Informations ("
  89. + uri + ")", ex);
  90. }
  91. return null;
  92. }
  93. }