Mercurial > hg > digilib-old
changeset 502:157d4c7d2343 digilibPDF
readded support for direct sending of image files
author | cmielack |
---|---|
date | Mon, 23 Feb 2009 16:03:06 +0100 |
parents | d960b7c68b08 |
children | fdb824bd57ab |
files | servlet/src/digilib/servlet/ImageJobInformation.java servlet/src/digilib/servlet/Scaler.java |
diffstat | 2 files changed, 126 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/ImageJobInformation.java Mon Feb 23 14:55:57 2009 +0100 +++ b/servlet/src/digilib/servlet/ImageJobInformation.java Mon Feb 23 16:03:06 2009 +0100 @@ -48,7 +48,7 @@ Float scaleXY = null; Rectangle2D userImgArea = null; Rectangle2D outerUserImgArea= null; - + Boolean imageSendable = null; // Integer paramDW = null; // Integer paramDH public ImageJobInformation() { @@ -170,11 +170,30 @@ * @throws IOException * */ - public String get_mimeType() throws IOException, ImageOpException{ + public String get_mimeType() { String mimeType = "image/png"; - ImageFile fileToLoad = get_fileToLoad(); - if(fileToLoad != null) - mimeType = fileToLoad.getMimetype(); + + + ImageFile fileToLoad; + try { + + fileToLoad = get_fileToLoad(); + + if(!get_fileToLoad().isChecked()){ + ImageOps.checkFile(fileToLoad); + } + + + if(fileToLoad != null) + mimeType = fileToLoad.getMimetype(); + + } catch (IOException e) { + e.printStackTrace(); + } catch (ImageOpException e) { + e.printStackTrace(); + } + + return mimeType; } @@ -343,7 +362,6 @@ Rectangle2D userImgArea = imgTrafo.createTransformedShape( relUserArea).getBounds2D(); - //########################################################################################################################## // calculate scaling factors based on inner user area if (get_scaleToFit()) { areaWidth = (float) userImgArea.getWidth(); @@ -587,7 +605,7 @@ public float[] get_paramRGBM(){ logger.debug("get_paramRGBM()"); - float[] paramRGBM = {0f,0f,0f}; + float[] paramRGBM = null;//{0f,0f,0f}; Parameter p = get("rgbm"); if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { return p.parseAsFloatArray("/"); @@ -598,7 +616,7 @@ public float[] get_paramRGBA(){ logger.debug("get_paramRGBA()"); - float[] paramRGBA = {0f,0f,0f}; + float[] paramRGBA = null;//{0f,0f,0f}; Parameter p = get("rgba"); if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { paramRGBA = p.parseAsFloatArray("/"); @@ -617,4 +635,44 @@ return hasOption("mo","vmir"); } + + public boolean checkSendAsFile(){ + return hasOption("mo", "file") + || hasOption("mo", "rawfile"); + } + + public boolean get_imageSendable(){ + if(imageSendable==null){ + String mimeType = get_mimeType(); + imageSendable = ( (mimeType.equals("image/jpeg") + || mimeType.equals("image/png") + || mimeType.equals("image/gif") ) + && + !(hasOption("mo", "hmir") + || hasOption("mo", "vmir") + || (getAsFloat("rot") != 0) + || (get_paramRGBM() != null) + || (get_paramRGBA() != null) + || (getAsFloat("cont") != 0) + || (getAsFloat("brgt") != 0))); + } + + return imageSendable; + } + + + public boolean noTransformRequired(){ + try { + return get_imageSendable() && ((get_loresOnly() && get_fileToLoad().getSize().isSmallerThan( + get_expectedSourceSize())) || (!(get_loresOnly() || get_hiresOnly()) && get_fileToLoad() + .getSize().fitsIn(expectedSourceSize))); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ImageOpException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } } \ No newline at end of file
--- a/servlet/src/digilib/servlet/Scaler.java Mon Feb 23 14:55:57 2009 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Mon Feb 23 16:03:06 2009 +0100 @@ -22,6 +22,7 @@ import digilib.image.ImageOpException; import digilib.io.DocuDirCache; import digilib.io.DocuDirent; +import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageFile; import digilib.io.ImageFileset; @@ -125,6 +126,8 @@ throw new ServletException("ERROR: No Configuration!"); } + + accountlog.debug("request: " + request.getQueryString()); logger.debug("request: " + request.getQueryString()); @@ -132,17 +135,54 @@ // define the job information ImageJobInformation jobdeclaration = new ImageJobInformation(); - jobdeclaration.setWithRequest(request); jobdeclaration.setConfig(dlConfig); - + ImageFile fileToLoad = null; + try { + fileToLoad = jobdeclaration.get_fileToLoad(); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + return; + } - // TODO check, if file can be sent without transformations - + // if requested, send image as a file + if(sendFileAllowed && jobdeclaration.checkSendAsFile()){ + String mt = null; + if (jobdeclaration.hasOption("mo", "rawfile")) { + mt = "application/octet-stream"; + } + logger.debug("Sending RAW File as is."); + try { + ServletOps.sendFile(fileToLoad.getFile(), mt, response); + } catch (FileOpException e) { + e.printStackTrace(); + } + + return; + } + + // if possible, send the image without actually having to transform it + if(jobdeclaration.noTransformRequired()){ + logger.debug("Sending File as is."); + + try { + ServletOps.sendFile(fileToLoad.getFile(), null, response); + } catch (FileOpException e) { + e.printStackTrace(); + } + + //logger.info("Done in " + // + (System.currentTimeMillis() - startTime) + "ms"); + return; + } + + + OutputStream outputstream = null; try { @@ -152,6 +192,22 @@ e1.printStackTrace(); logger.error(e1.getMessage()); } + + + + + if (! DigilibWorker.canRun()) { + logger.error("Servlet overloaded!"); + try { + response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); + } catch (IOException e) { + e.printStackTrace(); + } + return; + } + + + DigilibWorker job=null; @@ -211,7 +267,6 @@ outputstream.flush(); logger.debug("Job Processing Time: "+ (System.currentTimeMillis()-startTime) + "ms"); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); logger.error(e.getMessage()); response.sendError(1);