commit | author | age
|
7bcebf
|
1 |
/* |
U |
2 |
WebBox - Dein Server. |
|
3 |
Copyright (C) 2017 Ulrich Hilger, http://uhilger.de |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.wbx.web; |
|
19 |
|
61b659
|
20 |
import java.awt.Image; |
U |
21 |
import java.io.File; |
7bcebf
|
22 |
import java.io.IOException; |
61b659
|
23 |
import java.io.OutputStream; |
U |
24 |
import java.util.logging.Logger; |
7bcebf
|
25 |
import javax.servlet.ServletException; |
U |
26 |
import javax.servlet.http.HttpServletRequest; |
|
27 |
import javax.servlet.http.HttpServletResponse; |
|
28 |
import org.apache.catalina.servlets.DefaultServlet; |
|
29 |
|
|
30 |
/** |
|
31 |
* Mit dem TNServlet kann für eine Bilddatei eine |
|
32 |
* Miniaturansicht erzeugt werden, wie sie im Dateimanager |
|
33 |
* der WebBox verwendet wird. |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class TNServlet extends DefaultServlet { |
61b659
|
37 |
|
U |
38 |
private static final Logger logger = Logger.getLogger(TNServlet.class.getName()); |
7bcebf
|
39 |
|
U |
40 |
/** |
|
41 |
* Diese String-Konstanten noetigenfalls in eine |
|
42 |
* Konfigurationsdatei auslagern |
|
43 |
*/ |
|
44 |
public static final String TN = "_tn"; |
|
45 |
public static final String JPG = ".jpg"; |
|
46 |
public static final String JPEG = ".jpeg"; |
|
47 |
public static final String PNG = ".png"; |
|
48 |
|
|
49 |
/** |
|
50 |
* Handles the HTTP <code>GET</code> method. |
|
51 |
* |
|
52 |
* @param request servlet request |
|
53 |
* @param response servlet response |
|
54 |
* @throws ServletException if a servlet-specific error occurs |
|
55 |
* @throws IOException if an I/O error occurs |
|
56 |
*/ |
|
57 |
@Override |
|
58 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) |
|
59 |
throws ServletException, IOException { |
|
60 |
|
61b659
|
61 |
String uriStr = request.getRequestURI(); |
U |
62 |
File imgfile = new File(uriStr); |
|
63 |
|
|
64 |
logger.fine("realpath of /: " + request.getServletContext().getRealPath("/")); |
|
65 |
|
|
66 |
logger.fine("imgfile: " + imgfile.getAbsolutePath()); |
|
67 |
|
|
68 |
if(uriStr.contains(TN) && (uriStr.endsWith(JPG) || uriStr.endsWith(JPEG) || uriStr.endsWith(PNG))) { |
7bcebf
|
69 |
/* |
U |
70 |
TODO: hier mit Hilfe der Klasse Bild eine Miniaturansicht erzeugen |
|
71 |
und in die Antwort schreiben |
|
72 |
*/ |
61b659
|
73 |
//writeImageStream(Image image, int gr, String mimeType, response.getOutputStream()); |
7bcebf
|
74 |
} else { |
U |
75 |
super.doGet(request, response); |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
} |