1
|
1 /* DocuImage -- General image interface class implementation
|
|
2
|
|
3 Digital Image Library servlet components
|
|
4
|
|
5 Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de)
|
|
6
|
|
7 This program is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2 of the License, or (at your
|
|
10 option) any later version.
|
|
11
|
|
12 Please read license.txt for the full details. A copy of the GPL
|
|
13 may be found at http://www.gnu.org/copyleft/lgpl.html
|
|
14
|
|
15 You should have received a copy of the GNU General Public License
|
|
16 along with this program; if not, write to the Free Software
|
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
|
19 */
|
|
20
|
|
21 package digilib.image;
|
|
22
|
|
23 import java.io.*;
|
|
24 import javax.servlet.ServletResponse;
|
|
25
|
|
26 import digilib.*;
|
|
27 import digilib.io.*;
|
|
28
|
|
29 public abstract class DocuImageImpl implements DocuImage {
|
|
30
|
|
31 protected Utils util = null;
|
|
32
|
|
33 public DocuImageImpl() {
|
|
34 util = new Utils();
|
|
35 }
|
|
36
|
|
37 public DocuImageImpl(Utils u) {
|
|
38 util = u;
|
|
39 }
|
|
40
|
|
41 public void setUtils(Utils u) {
|
|
42 util = u;
|
|
43 }
|
|
44
|
|
45 protected String[] knownFileTypes = {"jpg", "png", "gif", "tiff"};
|
|
46
|
|
47 public String[] getKnownFileTypes() {
|
|
48 return knownFileTypes;
|
|
49 }
|
|
50
|
|
51 /**
|
|
52 * send an image file as-is
|
|
53 */
|
|
54 public void sendFile(File f, ServletResponse response) throws FileOpException {
|
|
55 util.dprintln(4, "sendFile("+f+")");
|
|
56 String mimeType = FileOps.mimeForFile(f);
|
|
57 if (mimeType == null) {
|
|
58 util.dprintln(2, "ERROR(sendFile): unknown file Type");
|
|
59 throw new FileOpException("Unknown file type.");
|
|
60 }
|
|
61 response.setContentType(mimeType);
|
|
62 // open file
|
|
63 try {
|
|
64 FileInputStream inFile = new FileInputStream(f);
|
|
65 OutputStream outStream = response.getOutputStream();
|
|
66 byte dataBuffer[] = new byte[1024];
|
|
67 int len;
|
|
68 while ((len = inFile.read(dataBuffer)) != -1) {
|
|
69 // copy out file
|
|
70 outStream.write(dataBuffer, 0, len);
|
|
71 }
|
|
72 inFile.close();
|
|
73 } catch (IOException e) {
|
|
74 util.dprintln(2, "ERROR(sendFile): unable to send file");
|
|
75 throw new FileOpException("Unable to send file.");
|
|
76 }
|
|
77 }
|
|
78
|
|
79 public abstract void loadImage(File f) throws FileOpException;
|
|
80 public abstract void writeImage(String mt, ServletResponse res) throws FileOpException;
|
|
81 public abstract int getWidth();
|
|
82 public abstract int getHeight();
|
|
83 public abstract void cropAndScale(int x_off, int y_off, int width, int height, float scale, int qual) throws ImageOpException;
|
|
84 }
|