| | |
| | | * Diese String-Konstanten noetigenfalls in eine |
| | | * Konfigurationsdatei auslagern |
| | | */ |
| | | public static final String TN = "_tn"; |
| | | public static final String KL = "_kl"; |
| | | public static final String SM = "_sm"; |
| | | public static final String MT = "_mt"; |
| | | public static final String GR = "_gr"; |
| | | public static final String TN = "_tn"; // 120 |
| | | public static final String KL = "_kl"; // 240 |
| | | public static final String SM = "_sm"; // 500 |
| | | public static final String MT = "_mt"; // 700 |
| | | public static final String GR = "_gr"; // 1200 |
| | | |
| | | public static final String JPG = ".jpg"; |
| | | public static final String JPEG = ".jpeg"; |
| | | public static final String PNG = ".png"; |
| | |
| | | String relname = uriStr.substring(request.getContextPath().length()); |
| | | |
| | | // --- Logausgabe Start |
| | | /* |
| | | File logurifile = new File(uriStr); |
| | | String loguriStr = uriStr.substring(request.getContextPath().length()); |
| | | File logdir = new File(request.getServletContext().getRealPath("/")); |
| | | File logimgfile = new File(logdir, loguriStr); |
| | | File imgfile = new File(logdir, loguriStr); |
| | | StringBuffer buf = new StringBuffer(); |
| | | buf.append("contextPath: "); |
| | | buf.append(request.getContextPath()); |
| | |
| | | buf.append(logurifile.getAbsolutePath()); |
| | | buf.append("\n"); |
| | | buf.append("imgfile: "); |
| | | buf.append(logimgfile.getAbsolutePath()); |
| | | buf.append(imgfile.getAbsolutePath()); |
| | | logger.fine(buf.toString()); |
| | | //System.out.println("TNServlet uri parts " + buf.toString()); |
| | | */ |
| | | // --- Logausgabe Ende |
| | | |
| | | if(uriStr.endsWith(JPG) || uriStr.endsWith(JPEG) || uriStr.endsWith(PNG)) { |
| | | File dir = new File(request.getServletContext().getRealPath("/")); |
| | | String suburiStr = uriStr.substring(request.getContextPath().length()); |
| | | File imgfile = new File(dir, suburiStr); |
| | | if(uriStr.contains(TN)) { |
| | | bildAusgeben(request, response, relname, TN, 120); |
| | | bildErzeugen(dir, relname, TN, 120, imgfile); |
| | | } else if(uriStr.contains(KL)) { |
| | | bildAusgeben(request, response, relname, KL, 240); |
| | | bildErzeugen(dir, relname, KL, 240, imgfile); |
| | | } else if(uriStr.contains(SM)) { |
| | | bildAusgeben(request, response, relname, SM, 500); |
| | | bildErzeugen(dir, relname, SM, 500, imgfile); |
| | | } else if(uriStr.contains(MT)) { |
| | | bildAusgeben(request, response, relname, MT, 700); |
| | | bildErzeugen(dir, relname, MT, 700, imgfile); |
| | | } else if(uriStr.contains(GR)) { |
| | | bildAusgeben(request, response, relname, GR, 1200); |
| | | } else { |
| | | super.doGet(request, response); |
| | | bildErzeugen(dir, relname, GR, 1200, imgfile); |
| | | } |
| | | } else { |
| | | super.doGet(request, response); |
| | | } |
| | | super.doGet(request, response); |
| | | } |
| | | |
| | | private void bildAusgeben(HttpServletRequest request, HttpServletResponse response, String relname, String indicator, int gr) throws UnsupportedEncodingException, IOException { |
| | | File dir = new File(request.getServletContext().getRealPath("/")); |
| | | private void bildErzeugen(File dir, String relname, String indicator, int gr, File tnfile) |
| | | throws UnsupportedEncodingException, IOException { |
| | | //File dir = new File(request.getServletContext().getRealPath("/")); |
| | | // System.out.println("TNServlet dir: " + dir); |
| | | relname = relname.replace(indicator, ""); |
| | | // System.out.println("TNServlet bildAusgeben relname: " + relname); |
| | | // relname: /test/img/IMG_0524.png |
| | | File imgfile = new File(dir, URLDecoder.decode(relname, "utf-8")); |
| | | |
| | | // 120, 240, 500, 700, 1200 |
| | | |
| | | Thumbnails.of(imgfile) |
| | | /*Thumbnails.of(imgfile) |
| | | .size(gr, gr) |
| | | .keepAspectRatio(true) |
| | | .outputQuality(0.7) |
| | | .toOutputStream(response.getOutputStream()); |
| | | .toOutputStream(response.getOutputStream());*/ |
| | | if(!tnfile.exists()) { |
| | | Thumbnails.of(imgfile) |
| | | .size(gr, gr) |
| | | .keepAspectRatio(true) |
| | | .outputQuality(0.7) |
| | | .toFile(tnfile); |
| | | } |
| | | } |
| | | } |