From e2808f9cb42bec32955e7f960bb289f56714d5c1 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Fri, 17 Jan 2020 16:32:38 +0000 Subject: [PATCH] Thumbnails werden nun im jeweiligen Bildordner mit abgelegt und nicht jedesmal 'on the fly' erzeugt. --- src/logging.properties | 136 +++++++++++++++++----------------- src/de/uhilger/wbx/web/TNServlet.java | 55 ++++++++----- 2 files changed, 103 insertions(+), 88 deletions(-) diff --git a/src/de/uhilger/wbx/web/TNServlet.java b/src/de/uhilger/wbx/web/TNServlet.java index 98fd667..c2c4c27 100644 --- a/src/de/uhilger/wbx/web/TNServlet.java +++ b/src/de/uhilger/wbx/web/TNServlet.java @@ -44,11 +44,12 @@ * 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"; @@ -69,10 +70,11 @@ 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()); @@ -84,40 +86,53 @@ 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); + } } } diff --git a/src/logging.properties b/src/logging.properties index fd8857a..6af23d2 100644 --- a/src/logging.properties +++ b/src/logging.properties @@ -1,68 +1,68 @@ -############################################################ -# Default Logging Configuration File -# -# You can use a different file by specifying a filename -# with the java.util.logging.config.file system property. -# For example java -Djava.util.logging.config.file=myfile -############################################################ - -############################################################ -# Global properties -############################################################ - -# "handlers" specifies a comma separated list of log Handler -# classes. These handlers will be installed during VM startup. -# Note that these classes must be on the system classpath. -# By default we only configure a ConsoleHandler, which will only -# show messages at the INFO and above levels. -# handlers= java.util.logging.ConsoleHandler - -# To also add the FileHandler, use the following line instead. -handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler - -# Default global logging level. -# This specifies which kinds of events are logged across -# all loggers. For any given facility this global level -# can be overriden by a facility specific level -# Note that the ConsoleHandler also has a separate level -# setting to limit messages printed to the console. -# .level= FINE -.level = NONE - -############################################################ -# Handler specific properties. -# Describes specific configuration info for Handlers. -############################################################ - -# default file output is in user's home directory. -# java.util.logging.FileHandler.pattern = %h/java%u.log -# java.util.logging.FileHandler.pattern = /media/extmirror/tomcat747/logs/tv_%u.log -# java.util.logging.FileHandler.pattern = ${catalina.base}/logs/file-cms_%u.log -java.util.logging.FileHandler.limit = 50000 -# java.util.logging.FileHandler.count = 1 -java.util.logging.FileHandler.count = 2 -# java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter -java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter -java.util.logging.FileHandler.level = FINER - -# Limit the message that are printed on the console to INFO and above. -# java.util.logging.ConsoleHandler.level = INFO -java.util.logging.ConsoleHandler.level = FINER -java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter - -# Example to customize the SimpleFormatter output format -# to print one-line log message like this: -# <level>: <log message> [<date/time>] -# -# java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n - -############################################################ -# Facility specific properties. -# Provides extra control for each logger. -############################################################ - -# For example, set the com.xyz.foo logger to only log SEVERE -# messages: -# com.xyz.foo.level = SEVERE -de.uhilger.wbx.handlers = java.util.logging.ConsoleHandler -de.uhilger.wbx.level = INFO \ No newline at end of file +############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ + +############################################################ +# Global properties +############################################################ + +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the INFO and above levels. +# handlers= java.util.logging.ConsoleHandler + +# To also add the FileHandler, use the following line instead. +handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler + +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overriden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +# .level= FINE +.level = NONE + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ + +# default file output is in user's home directory. +# java.util.logging.FileHandler.pattern = %h/java%u.log +# java.util.logging.FileHandler.pattern = /media/extmirror/tomcat747/logs/tv_%u.log +java.util.logging.FileHandler.pattern = ${catalina.base}/logs/file-cms_%u.log +java.util.logging.FileHandler.limit = 50000 +# java.util.logging.FileHandler.count = 1 +java.util.logging.FileHandler.count = 2 +# java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter +java.util.logging.FileHandler.level = FINER + +# Limit the message that are printed on the console to INFO and above. +# java.util.logging.ConsoleHandler.level = INFO +java.util.logging.ConsoleHandler.level = FINER +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Example to customize the SimpleFormatter output format +# to print one-line log message like this: +# <level>: <log message> [<date/time>] +# +# java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n + +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ + +# For example, set the com.xyz.foo logger to only log SEVERE +# messages: +# com.xyz.foo.level = SEVERE +de.uhilger.wbx.handlers = java.util.logging.ConsoleHandler +de.uhilger.wbx.level = FINEST \ No newline at end of file -- Gitblit v1.9.3