Mercurial > hg > digilib-old
comparison servlet/src/digilib/servlet/Scaler.java @ 153:4980c969be4c
Servlet version 1.16a1
- cleanup of DigilibConfig class
- now uses new Parameter and ParameterMap classes
- new parameter default-quality
author | robcast |
---|---|
date | Wed, 03 Sep 2003 00:56:16 +0200 |
parents | bc8df0133c04 |
children | 688ad0b8b0fa |
comparison
equal
deleted
inserted
replaced
152:f4a5cfe37469 | 153:4980c969be4c |
---|---|
56 */ | 56 */ |
57 //public class Scaler extends HttpServlet implements SingleThreadModel { | 57 //public class Scaler extends HttpServlet implements SingleThreadModel { |
58 public class Scaler extends HttpServlet { | 58 public class Scaler extends HttpServlet { |
59 | 59 |
60 // digilib servlet version (for all components) | 60 // digilib servlet version (for all components) |
61 public static final String dlVersion = "1.15b1"; | 61 public static final String dlVersion = "1.16a1"; |
62 | 62 |
63 // Utils instance with debuglevel | 63 // Utils instance with debuglevel |
64 Utils util; | 64 Utils util; |
65 // FileOps instance | 65 // FileOps instance |
66 FileOps fileOp; | 66 FileOps fileOp; |
68 AuthOps authOp; | 68 AuthOps authOp; |
69 // ServletOps instance | 69 // ServletOps instance |
70 ServletOps servletOp; | 70 ServletOps servletOp; |
71 // DocuDirCache instance | 71 // DocuDirCache instance |
72 DocuDirCache dirCache; | 72 DocuDirCache dirCache; |
73 | |
74 // deny image file | |
75 File denyImgFile; | |
76 // error image file | |
77 File errorImgFile; | |
78 // subsampling before scaling | |
79 float minSubsample = 2f; | |
80 // send files as is? | |
81 boolean sendFileAllowed = true; | |
82 // default scaling quality | |
83 int defaultQuality = 1; | |
73 | 84 |
74 // DigilibConfiguration instance | 85 // DigilibConfiguration instance |
75 DigilibConfiguration dlConfig; | 86 DigilibConfiguration dlConfig; |
76 | 87 |
77 // use authorization database | 88 // use authorization database |
88 public void init(ServletConfig config) throws ServletException { | 99 public void init(ServletConfig config) throws ServletException { |
89 super.init(config); | 100 super.init(config); |
90 | 101 |
91 // Debuggin! | 102 // Debuggin! |
92 //TCTool tctool = new TCTool(); | 103 //TCTool tctool = new TCTool(); |
104 | |
93 System.out.println( | 105 System.out.println( |
94 "***** Digital Image Library Servlet (version " | 106 "***** Digital Image Library Servlet (version " |
95 + dlVersion | 107 + dlVersion |
96 + ") *****"); | 108 + ") *****"); |
97 | 109 |
108 context.setAttribute("digilib.servlet.configuration", dlConfig); | 120 context.setAttribute("digilib.servlet.configuration", dlConfig); |
109 } catch (Exception e) { | 121 } catch (Exception e) { |
110 throw new ServletException(e); | 122 throw new ServletException(e); |
111 } | 123 } |
112 } | 124 } |
113 // set the servlet version | |
114 dlConfig.setServletVersion(dlVersion); | |
115 // first we need an Utils | 125 // first we need an Utils |
116 util = dlConfig.getUtil(); | 126 util = dlConfig.getUtil(); |
117 // set our AuthOps | 127 // set our AuthOps |
118 useAuthentication = dlConfig.isUseAuthentication(); | 128 useAuthentication = dlConfig.getAsBoolean("use-authorization"); |
119 authOp = dlConfig.getAuthOp(); | 129 authOp = (AuthOps) dlConfig.getValue("servlet.auth.op"); |
120 // FileOps instance | 130 // FileOps instance |
121 fileOp = new FileOps(util); | 131 fileOp = new FileOps(util); |
122 // AuthOps instance | 132 // AuthOps instance |
123 servletOp = new ServletOps(util); | 133 servletOp = new ServletOps(util); |
124 // DocuDirCache instance | 134 // DocuDirCache instance |
125 dirCache = dlConfig.getDirCache(); | 135 dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); |
136 denyImgFile = new File(dlConfig.getAsString("denied-image")); | |
137 errorImgFile = new File(dlConfig.getAsString("error-image")); | |
138 sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed"); | |
139 minSubsample = dlConfig.getAsFloat("subsample-minimum"); | |
140 defaultQuality = dlConfig.getAsInt("default-quality"); | |
126 } | 141 } |
127 | 142 |
128 /** Process the HTTP Get request*/ | 143 /** Process the HTTP Get request*/ |
129 public void doGet(HttpServletRequest request, HttpServletResponse response) | 144 public void doGet(HttpServletRequest request, HttpServletResponse response) |
130 throws ServletException, IOException { | 145 throws ServletException, IOException { |
181 // use low resolution images only | 196 // use low resolution images only |
182 boolean loresOnly = false; | 197 boolean loresOnly = false; |
183 // use hires images only | 198 // use hires images only |
184 boolean hiresOnly = false; | 199 boolean hiresOnly = false; |
185 // interpolation to use for scaling | 200 // interpolation to use for scaling |
186 int scaleQual = 1; | 201 int scaleQual = defaultQuality; |
187 // send html error message (or image file) | 202 // send html error message (or image file) |
188 boolean errorMsgHtml = false; | 203 boolean errorMsgHtml = false; |
189 // mirror the image | 204 // mirror the image |
190 boolean doMirror = false; | 205 boolean doMirror = false; |
191 // angle of mirror axis | 206 // angle of mirror axis |
263 sendFile = false; | 278 sendFile = false; |
264 hiresOnly = true; | 279 hiresOnly = true; |
265 } else if (dlRequest.isOption("file")) { | 280 } else if (dlRequest.isOption("file")) { |
266 scaleToFit = false; | 281 scaleToFit = false; |
267 absoluteScale = false; | 282 absoluteScale = false; |
268 if (dlConfig.isSendFileAllowed()) { | 283 if (sendFileAllowed) { |
269 cropToFit = false; | 284 cropToFit = false; |
270 sendFile = true; | 285 sendFile = true; |
271 } else { | 286 } else { |
272 // crop to fit if send file not allowed | 287 // crop to fit if send file not allowed |
273 cropToFit = true; | 288 cropToFit = true; |
334 if (errorMsgHtml) { | 349 if (errorMsgHtml) { |
335 ServletOps.htmlMessage( | 350 ServletOps.htmlMessage( |
336 "ERROR: Unauthorized access!", | 351 "ERROR: Unauthorized access!", |
337 response); | 352 response); |
338 } else { | 353 } else { |
339 servletOp.sendFile( | 354 servletOp.sendFile(denyImgFile, response); |
340 new File(dlConfig.getDenyImgFileName()), | |
341 response); | |
342 } | 355 } |
343 return; | 356 return; |
344 } | 357 } |
345 } | 358 } |
346 } | 359 } |
443 * then send as is (mo=file) | 456 * then send as is (mo=file) |
444 */ | 457 */ |
445 if ((loresOnly | 458 if ((loresOnly |
446 && imageSendable | 459 && imageSendable |
447 && fileToLoad.getSize().isSmallerThan(expectedSourceSize)) | 460 && fileToLoad.getSize().isSmallerThan(expectedSourceSize)) |
448 || (!(loresOnly || hiresOnly) && fileToLoad.getSize().fitsIn(expectedSourceSize)) | 461 || (!(loresOnly || hiresOnly) |
462 && fileToLoad.getSize().fitsIn(expectedSourceSize)) | |
449 || sendFile) { | 463 || sendFile) { |
450 | 464 |
451 util.dprintln(1, "Sending File as is."); | 465 util.dprintln(1, "Sending File as is."); |
452 | 466 |
453 servletOp.sendFile(fileToLoad.getFile(), response); | 467 servletOp.sendFile(fileToLoad.getFile(), response); |
628 subf = 1 / scaleXY; | 642 subf = 1 / scaleXY; |
629 // for higher quality reduce subsample factor by minSubsample | 643 // for higher quality reduce subsample factor by minSubsample |
630 if (scaleQual > 0) { | 644 if (scaleQual > 0) { |
631 subsamp = | 645 subsamp = |
632 Math.max( | 646 Math.max( |
633 Math.floor(subf / dlConfig.getMinSubsample()), | 647 Math.floor(subf / minSubsample), |
634 1d); | 648 1d); |
635 } else { | 649 } else { |
636 subsamp = Math.floor(subf); | 650 subsamp = Math.floor(subf); |
637 } | 651 } |
638 scaleXY = subsamp / subf; | 652 scaleXY = subsamp / subf; |
760 if (errorMsgHtml) { | 774 if (errorMsgHtml) { |
761 ServletOps.htmlMessage( | 775 ServletOps.htmlMessage( |
762 "ERROR: File IO Error: " + e, | 776 "ERROR: File IO Error: " + e, |
763 response); | 777 response); |
764 } else { | 778 } else { |
765 servletOp.sendFile( | 779 servletOp.sendFile(errorImgFile, response); |
766 new File(dlConfig.getErrorImgFileName()), | |
767 response); | |
768 } | 780 } |
769 } catch (FileOpException ex) { | 781 } catch (FileOpException ex) { |
770 } // so we don't get a loop | 782 } // so we don't get a loop |
771 } catch (AuthOpException e) { | 783 } catch (AuthOpException e) { |
772 util.dprintln(1, "ERROR: Authorization error: " + e); | 784 util.dprintln(1, "ERROR: Authorization error: " + e); |
774 if (errorMsgHtml) { | 786 if (errorMsgHtml) { |
775 ServletOps.htmlMessage( | 787 ServletOps.htmlMessage( |
776 "ERROR: Authorization error: " + e, | 788 "ERROR: Authorization error: " + e, |
777 response); | 789 response); |
778 } else { | 790 } else { |
779 servletOp.sendFile( | 791 servletOp.sendFile(errorImgFile, response); |
780 new File(dlConfig.getErrorImgFileName()), | |
781 response); | |
782 } | 792 } |
783 } catch (FileOpException ex) { | 793 } catch (FileOpException ex) { |
784 } // so we don't get a loop | 794 } // so we don't get a loop |
785 } catch (ImageOpException e) { | 795 } catch (ImageOpException e) { |
786 util.dprintln(1, "ERROR: Image Error: " + e); | 796 util.dprintln(1, "ERROR: Image Error: " + e); |
788 if (errorMsgHtml) { | 798 if (errorMsgHtml) { |
789 ServletOps.htmlMessage( | 799 ServletOps.htmlMessage( |
790 "ERROR: Image Operation Error: " + e, | 800 "ERROR: Image Operation Error: " + e, |
791 response); | 801 response); |
792 } else { | 802 } else { |
793 servletOp.sendFile( | 803 servletOp.sendFile(errorImgFile, response); |
794 new File(dlConfig.getErrorImgFileName()), | |
795 response); | |
796 } | 804 } |
797 } catch (FileOpException ex) { | 805 } catch (FileOpException ex) { |
798 } // so we don't get a loop | 806 } // so we don't get a loop |
799 } catch (RuntimeException e) { | 807 } catch (RuntimeException e) { |
800 // JAI likes to throw RuntimeExceptions ;-( | 808 // JAI likes to throw RuntimeExceptions ;-( |
803 if (errorMsgHtml) { | 811 if (errorMsgHtml) { |
804 ServletOps.htmlMessage( | 812 ServletOps.htmlMessage( |
805 "ERROR: Other Image Operation Error: " + e, | 813 "ERROR: Other Image Operation Error: " + e, |
806 response); | 814 response); |
807 } else { | 815 } else { |
808 servletOp.sendFile( | 816 servletOp.sendFile(errorImgFile, response); |
809 new File(dlConfig.getErrorImgFileName()), | |
810 response); | |
811 } | 817 } |
812 } catch (FileOpException ex) { | 818 } catch (FileOpException ex) { |
813 } // so we don't get a loop | 819 } // so we don't get a loop |
814 | 820 |
815 } | 821 } |