| | |
| | | */ |
| | | package de.uhilger.wbx.web; |
| | | |
| | | import de.uhilger.wbx.Bild; |
| | | import java.awt.Container; |
| | | import java.awt.Image; |
| | | import java.awt.MediaTracker; |
| | | import java.awt.Toolkit; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | throws ServletException, IOException { |
| | | |
| | | String uriStr = request.getRequestURI(); |
| | | File imgfile = new File(uriStr); |
| | | String relname = uriStr.substring(request.getContextPath().length()); |
| | | |
| | | logger.fine("realpath of /: " + request.getServletContext().getRealPath("/")); |
| | | /* |
| | | File urifile = new File(uriStr); |
| | | uriStr = uriStr.substring(request.getContextPath().length()); |
| | | File dir = new File(request.getServletContext().getRealPath("/")); |
| | | File imgfile = new File(dir, uriStr); |
| | | |
| | | logger.fine("imgfile: " + imgfile.getAbsolutePath()); |
| | | StringBuffer buf = new StringBuffer(); |
| | | buf.append("contextPath: "); |
| | | buf.append(request.getContextPath()); |
| | | buf.append("\n"); |
| | | buf.append("realpath of /: "); |
| | | buf.append(request.getServletContext().getRealPath("/")); |
| | | buf.append("\n"); |
| | | buf.append("urifile: "); |
| | | buf.append(urifile.getAbsolutePath()); |
| | | buf.append("\n"); |
| | | buf.append("imgfile: "); |
| | | buf.append(imgfile.getAbsolutePath()); |
| | | logger.fine(buf.toString()); |
| | | */ |
| | | |
| | | if(uriStr.contains(TN) && (uriStr.endsWith(JPG) || uriStr.endsWith(JPEG) || uriStr.endsWith(PNG))) { |
| | | /* |
| | | TODO: hier mit Hilfe der Klasse Bild eine Miniaturansicht erzeugen |
| | | und in die Antwort schreiben |
| | | */ |
| | | //writeImageStream(Image image, int gr, String mimeType, response.getOutputStream()); |
| | | */ |
| | | File dir = new File(request.getServletContext().getRealPath("/")); |
| | | relname = relname.replace(TN, ""); |
| | | File imgfile = new File(dir, relname); |
| | | Image image = Toolkit.getDefaultToolkit().getImage(imgfile.getAbsolutePath()); |
| | | MediaTracker mediaTracker = new MediaTracker(new Container()); |
| | | mediaTracker.addImage(image, 0); |
| | | try { |
| | | mediaTracker.waitForID(0); |
| | | |
| | | if (!mediaTracker.isErrorAny()) { |
| | | Bild bild = new Bild(); |
| | | bild.writeImageStream(image, bild.getVariantenGroesse(Bild.WINZIG), bild.getMimeType(imgfile), response.getOutputStream()); |
| | | } |
| | | } catch (InterruptedException ex) { |
| | | logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); |
| | | } |
| | | |
| | | } else { |
| | | super.doGet(request, response); |
| | | } |