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 |
*/
|
22f5de
|
18 |
package de.uhilger.wbx.web;
|
U |
19 |
|
|
20 |
import java.io.IOException;
|
|
21 |
import java.util.logging.Logger;
|
|
22 |
import javax.servlet.ServletException;
|
|
23 |
import javax.servlet.ServletOutputStream;
|
|
24 |
import javax.servlet.http.HttpServletRequest;
|
|
25 |
import javax.servlet.http.HttpServletResponse;
|
|
26 |
|
|
27 |
/**
|
7bcebf
|
28 |
* Das ViewServlet fügt dem DefaultServlet von Tomcat
|
U |
29 |
* Methoden hinzu, mit denen HTML-Inhalte wie sie z.B. mit
|
|
30 |
* TinyMCE erzeugt werden zu ganzen HTML-Seiten
|
|
31 |
* mit head und body tags sowie Stylesheet-Verweisen
|
|
32 |
* ergänzt werden
|
|
33 |
*
|
|
34 |
* TODO: Stylesheets dynamisch einbinden
|
22f5de
|
35 |
*/
|
5bfcdd
|
36 |
public class ViewServlet extends WbxServlet {
|
22f5de
|
37 |
|
U |
38 |
private static final Logger logger = Logger.getLogger(ViewServlet.class.getName());
|
5bfcdd
|
39 |
//private static final String HOME_CTX = "/home";
|
22f5de
|
40 |
|
94a2d9
|
41 |
protected void seiteAusgeben(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
2a7560
|
42 |
ServletOutputStream out = response.getOutputStream();
|
U |
43 |
printHeader(out);
|
|
44 |
super.doGet(request, response);
|
|
45 |
printFooter(out);
|
|
46 |
}
|
|
47 |
|
|
48 |
private void printHeader(ServletOutputStream out) throws IOException {
|
066b66
|
49 |
out.print("<!DOCTYPE html><html><head>\r\n");
|
a123ba
|
50 |
out.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>\r\n");
|
066b66
|
51 |
out.print("<link rel=\"stylesheet\" type=\"text/css\" href=\"/jslib/bootstrap/css/bootstrap.min.css\">\r\n");
|
U |
52 |
out.print("<link rel=\"stylesheet\" type=\"text/css\" href=\"/jslib/lightbox/lightbox.css\">\r\n");
|
|
53 |
out.print("<link rel=\"stylesheet\" type=\"text/css\" href=\"stile.css\">\r\n");
|
|
54 |
out.print("</head><body class=\"p-3\">\r\n");
|
2a7560
|
55 |
}
|
U |
56 |
|
|
57 |
private void printFooter(ServletOutputStream out) throws IOException {
|
066b66
|
58 |
out.print("<script src=\"/jslib/jquery/jquery.min.js\"></script>\r\n");
|
U |
59 |
out.print("<script src=\"/jslib/lightbox/lightbox.min.js\"></script>\r\n");
|
2a7560
|
60 |
out.print("</body></html>");
|
U |
61 |
}
|
|
62 |
|
5bfcdd
|
63 |
/*
|
2a7560
|
64 |
private String getUrlUser(HttpServletRequest request, String userName) throws IOException {
|
U |
65 |
String result = "";
|
|
66 |
String requestUrlStr = request.getRequestURL().toString();
|
|
67 |
String contextPath = request.getContextPath();
|
22f5de
|
68 |
if(contextPath != null && requestUrlStr != null && userName != null) {
|
U |
69 |
int start = requestUrlStr.indexOf(contextPath);
|
|
70 |
start += contextPath.length();
|
|
71 |
start++;
|
|
72 |
int end = start + userName.length();
|
|
73 |
try {
|
|
74 |
result = requestUrlStr.substring(start, end);
|
|
75 |
} catch(Exception ex) {
|
2a7560
|
76 |
logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
|
22f5de
|
77 |
}
|
U |
78 |
}
|
|
79 |
return result;
|
|
80 |
}
|
|
81 |
|
|
82 |
private String getUserName(HttpServletRequest hr) {
|
|
83 |
String userName = null;
|
|
84 |
Object p = hr.getUserPrincipal();
|
|
85 |
if (p instanceof Principal) {
|
|
86 |
userName = ((Principal) p).getName();
|
|
87 |
}
|
|
88 |
return userName;
|
|
89 |
}
|
5bfcdd
|
90 |
*/
|
22f5de
|
91 |
|
U |
92 |
/**
|
|
93 |
* Returns a short description of the servlet.
|
|
94 |
*
|
|
95 |
* @return a String containing servlet description
|
|
96 |
*/
|
|
97 |
@Override
|
|
98 |
public String getServletInfo() {
|
|
99 |
return "Short description";
|
2a7560
|
100 |
}
|
22f5de
|
101 |
|
U |
102 |
}
|