01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * JPEGImageFactoryModule.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.resourceloader;
30:
31: import java.awt.Image;
32: import java.awt.Toolkit;
33: import java.io.IOException;
34:
35: import org.jfree.report.util.StringUtil;
36:
37: public class JPEGImageFactoryModule implements ImageFactoryModule {
38: private static final byte[] JFIF_ID = { 0x4A, 0x46, 0x49, 0x46,
39: 0x00 };
40: private static final String[] MIMETYPES = { "image/jpeg",
41: "image/jpg", "image/jp_", "application/jpg",
42: "application/x-jpg", "image/pjpeg", "image/pipeg",
43: "image/vnd.swiftview-jpeg", "image/x-xbitmap" };
44:
45: public JPEGImageFactoryModule() {
46: }
47:
48: public boolean canHandleResourceByMimeType(final String name) {
49: for (int i = 0; i < MIMETYPES.length; i++) {
50: if (name.equals(MIMETYPES[i])) {
51: return true;
52: }
53: }
54: return false;
55: }
56:
57: public boolean canHandleResourceByContent(final byte[] content) {
58: if ((0xff & content[0]) != 0xFF && (0xff & content[1]) != 0xD8) {
59: return false;
60: }
61: for (int i = 0; i < JFIF_ID.length; i++) {
62: if (JFIF_ID[i] != content[6 + i]) {
63: return false;
64: }
65: }
66: return true;
67: }
68:
69: public boolean canHandleResourceByName(final String name) {
70: return (StringUtil.endsWithIgnoreCase(name, ".jpg") || StringUtil
71: .endsWithIgnoreCase(name, ".jpeg"));
72: }
73:
74: public int getHeaderFingerprintSize() {
75: return 11;
76: }
77:
78: public Image createImage(final byte[] imageData,
79: final String fileName, final String mimeType)
80: throws IOException {
81: return Toolkit.getDefaultToolkit().createImage(imageData);
82: }
83: }
|