comparison servlet/src/digilib/image/DocuImageImpl.java @ 73:3b8797fc3e90

New servlet version 1.5b. Mostly cleanup. Global parameters for digilib now in DigilibConfiguration, per request parameters are now all in DigilibRequest. The DocuImage implementation can be selected by the configuration docuimage-class. Pixel-by-pixel view implemented with "mo=clip".
author robcast
date Fri, 24 Jan 2003 21:40:59 +0100
parents 0ff3ede32060
children 63c8186455c1
comparison
equal deleted inserted replaced
72:300d5ba8b33b 73:3b8797fc3e90
12 Please read license.txt for the full details. A copy of the GPL 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 13 may be found at http://www.gnu.org/copyleft/lgpl.html
14 14
15 You should have received a copy of the GNU General Public License 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 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 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19 */ 19 */
20 20
21 package digilib.image; 21 package digilib.image;
22 22
24 import javax.servlet.ServletResponse; 24 import javax.servlet.ServletResponse;
25 25
26 import digilib.*; 26 import digilib.*;
27 import digilib.io.*; 27 import digilib.io.*;
28 28
29 /** Simple abstract implementation of the <code>DocuImage</code> interface.
30 *
31 * This implementation provides basic functionality for the utility methods like
32 * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like
33 * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>,
34 * <code>getHeight</code> and <code>cropAndScale</code> must be implemented by
35 * derived classes.
36 */
29 public abstract class DocuImageImpl implements DocuImage { 37 public abstract class DocuImageImpl implements DocuImage {
30 38
39 /** Internal utils object. */
31 protected Utils util = null; 40 protected Utils util = null;
32 41
42 /** Default constructor. */
33 public DocuImageImpl() { 43 public DocuImageImpl() {
34 util = new Utils(); 44 util = new Utils();
35 } 45 }
36 46
47 /** Contructor taking an utils object.
48 *
49 * @param u Utils object.
50 */
37 public DocuImageImpl(Utils u) { 51 public DocuImageImpl(Utils u) {
38 util = u; 52 util = u;
39 } 53 }
40 54
55 /** Set local Utils object.
56 *
57 * @param u Utils object.
58 */
41 public void setUtils(Utils u) { 59 public void setUtils(Utils u) {
42 util = u; 60 util = u;
43 } 61 }
44 62
63 /** Internal knownFileTypes. */
45 protected String[] knownFileTypes = {"jpg", "png", "gif", "tiff"}; 64 protected String[] knownFileTypes = {"jpg", "png", "gif", "tiff"};
46 65
66 /** Returns the list of image file types known to the DocuImage implementation.
67 *
68 * @return List of image file types. Strings are standard file extensions.
69 */
47 public String[] getKnownFileTypes() { 70 public String[] getKnownFileTypes() {
48 return knownFileTypes; 71 return knownFileTypes;
49 } 72 }
50 73
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 74
79 public abstract void loadImage(File f) throws FileOpException; 75 public abstract void loadImage(File f) throws FileOpException;
80 public abstract void writeImage(String mt, ServletResponse res) throws FileOpException; 76 public abstract void writeImage(String mt, ServletResponse res) throws FileOpException;
81 public abstract int getWidth(); 77 public abstract int getWidth();
82 public abstract int getHeight(); 78 public abstract int getHeight();