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: * WmfImageFactoryModule.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.io.ByteArrayInputStream;
33: import java.io.IOException;
34:
35: import org.jfree.pixie.wmf.WmfFile;
36: import org.jfree.report.util.StringUtil;
37: import org.jfree.ui.Drawable;
38:
39: public class WmfImageFactoryModule implements ImageFactoryModule,
40: DrawableFactoryModule {
41: private static final String[] MIMETYPES = {
42: "application/x-msmetafile", "application/wmf",
43: "application/x-wmf", "image/wmf", "image/x-wmf",
44: "image/x-win-metafile", "zz-application/zz-winassoc-wmf" };
45:
46: public WmfImageFactoryModule() {
47: }
48:
49: public boolean canHandleResourceByContent(final byte[] content) {
50: return ((0xff & content[0]) == 0xD7 && (0xff & content[1]) == 0xCD);
51: }
52:
53: public boolean canHandleResourceByMimeType(final String name) {
54: for (int i = 0; i < MIMETYPES.length; i++) {
55: if (name.equals(MIMETYPES[i])) {
56: return true;
57: }
58: }
59: return false;
60: }
61:
62: public boolean canHandleResourceByName(final String name) {
63: return StringUtil.endsWithIgnoreCase(name, ".wmf");
64: }
65:
66: public int getHeaderFingerprintSize() {
67: return 2;
68: }
69:
70: public Image createImage(final byte[] imageData,
71: final String fileName, final String mimeType)
72: throws IOException {
73: final WmfFile wmfFile = new WmfFile(new ByteArrayInputStream(
74: imageData), -1, -1);
75: return wmfFile.replay();
76: }
77:
78: public Drawable createDrawable(final byte[] imageData,
79: final String fileName, final String mimeType)
80: throws IOException {
81: return new WmfFile(new ByteArrayInputStream(imageData), -1, -1);
82: }
83: }
|