| | |
| | | */ |
| | | 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.UnsupportedEncodingException; |
| | | import java.net.URLDecoder; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.apache.catalina.servlets.DefaultServlet; |
| | | |
| | | /** |
| | |
| | | |
| | | if(uriStr.endsWith(JPG) || uriStr.endsWith(JPEG) || uriStr.endsWith(PNG)) { |
| | | if(uriStr.contains(TN)) { |
| | | bildAusgeben(request, response, relname, TN, Bild.WINZIG); |
| | | bildAusgeben(request, response, relname, TN, 120); |
| | | } else if(uriStr.contains(KL)) { |
| | | bildAusgeben(request, response, relname, KL, Bild.KLEIN); |
| | | bildAusgeben(request, response, relname, KL, 240); |
| | | } else if(uriStr.contains(SM)) { |
| | | bildAusgeben(request, response, relname, SM, Bild.SEMI); |
| | | bildAusgeben(request, response, relname, SM, 500); |
| | | } else if(uriStr.contains(MT)) { |
| | | bildAusgeben(request, response, relname, MT, Bild.MITTEL); |
| | | bildAusgeben(request, response, relname, MT, 700); |
| | | } else if(uriStr.contains(GR)) { |
| | | bildAusgeben(request, response, relname, GR, Bild.GROSS); |
| | | bildAusgeben(request, response, relname, GR, 1200); |
| | | } else { |
| | | super.doGet(request, response); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void bildAusgeben(HttpServletRequest request, HttpServletResponse response, String relname, String indicator, int bildTyp) throws UnsupportedEncodingException, IOException { |
| | | private void bildAusgeben(HttpServletRequest request, HttpServletResponse response, String relname, String indicator, int gr) throws UnsupportedEncodingException, IOException { |
| | | File dir = new File(request.getServletContext().getRealPath("/")); |
| | | relname = relname.replace(indicator, ""); |
| | | File imgfile = new File(dir, URLDecoder.decode(relname, "utf-8")); |
| | | Image image = Toolkit.getDefaultToolkit().getImage(imgfile.getAbsolutePath()); |
| | | MediaTracker mediaTracker = new MediaTracker(new Container()); |
| | | mediaTracker.addImage(image, 0); |
| | | try { |
| | | mediaTracker.waitForID(0); |
| | | |
| | | // 120, 240, 500, 700, 1200 |
| | | |
| | | if (!mediaTracker.isErrorAny()) { |
| | | Bild bild = new Bild(); |
| | | bild.writeImageStream(image, bild.getVariantenGroesse(bildTyp), bild.getMimeType(imgfile), response.getOutputStream()); |
| | | } |
| | | } catch (InterruptedException ex) { |
| | | logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); |
| | | } |
| | | } |
| | | Thumbnails.of(imgfile) |
| | | .size(gr, gr) |
| | | .keepAspectRatio(true) |
| | | .toOutputStream(response.getOutputStream()); |
| | | } |
| | | } |