| | |
| | | import com.sun.net.httpserver.Filter; |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.neon.FileServer; |
| | | import de.uhilger.neon.HttpHelper; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | |
| | | String pattern = (String) exchange.getHttpContext().getAttributes() |
| | | .getOrDefault("imageFilterPattern", ".+\\.jpg|.+\\.jpeg|.+\\.png"); |
| | | String uriStr = exchange.getRequestURI().toString(); |
| | | if(uriStr.toLowerCase().matches(pattern)) { |
| | | String fileBase = (String) exchange.getHttpContext().getAttributes() |
| | | .get(FileServer.ATTR_FILE_BASE); |
| | | String fileName = exchange |
| | | .getRequestURI() |
| | | .getPath() |
| | | .substring(exchange |
| | | .getHttpContext() |
| | | .getPath() |
| | | .length()); |
| | | new ImageWorker().createImages(fileBase, fileName, uriStr); |
| | | try { |
| | | String fName = new HttpHelper().getFileName(exchange); |
| | | if(uriStr.toLowerCase().matches(pattern)) { |
| | | String fileBase = (String) exchange.getHttpContext().getAttributes() |
| | | .get(FileServer.ATTR_FILE_BASE); |
| | | String fileName = exchange |
| | | .getRequestURI() |
| | | .getPath() |
| | | .substring(exchange |
| | | .getHttpContext() |
| | | .getPath() |
| | | .length()); |
| | | new ImageWorker().createImages(fileBase, fileName, uriStr); |
| | | } |
| | | } catch(IllegalArgumentException ex) { |
| | | // ungueltiger Dateiname, keine Transformation noetig, tue nichts |
| | | } finally { |
| | | chain.doFilter(exchange); |
| | | } |
| | | chain.doFilter(exchange); |
| | | } |
| | | |
| | | @Override |