commit | author | age
|
a0ec7b
|
1 |
/* |
U |
2 |
* Radiozentrale - Webradio App |
|
3 |
* Copyright (C) 2018 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 General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (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 General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see http://www.gnu.org/licenses/ |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.radiozentrale.api; |
|
20 |
|
|
21 |
import de.uhilger.baselink.PersistenceManager; |
|
22 |
import de.uhilger.baselink.Record; |
|
23 |
import de.uhilger.radiozentrale.web.Initialiser; |
|
24 |
import de.uhilger.transit.web.RequestKontext; |
|
25 |
import de.uhilger.transit.web.WebKontext; |
|
26 |
import java.util.Properties; |
|
27 |
import javax.servlet.ServletContext; |
|
28 |
import javax.servlet.http.HttpServletRequest; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
*/ |
|
33 |
public abstract class Api implements WebKontext, RequestKontext { |
|
34 |
|
|
35 |
/** Zeiger zum Servlet-Kontext dieser Anwendung */ |
|
36 |
private ServletContext ctx; |
|
37 |
|
|
38 |
private HttpServletRequest request; |
|
39 |
|
|
40 |
protected PersistenceManager getDb() { |
|
41 |
return (PersistenceManager) ctx.getAttribute(Initialiser.RZ_DB); |
|
42 |
} |
|
43 |
|
|
44 |
protected String getSql(String id) { |
|
45 |
Properties sql = (Properties) ctx.getAttribute(Initialiser.RZ_SQL_PROPERTIES); |
|
46 |
return sql.getProperty(id); |
|
47 |
} |
|
48 |
|
|
49 |
protected Record getMapper(String mapperName) { |
|
50 |
Record record = null; |
|
51 |
Object o = getServletContext().getAttribute(mapperName); |
|
52 |
if(o instanceof Record) { |
|
53 |
record = (Record) o; |
|
54 |
} |
|
55 |
return record; |
|
56 |
} |
|
57 |
|
|
58 |
/* ------------- Implementierung WebKontext ------------- */ |
|
59 |
|
|
60 |
@Override |
|
61 |
public ServletContext getServletContext() { |
|
62 |
return ctx; |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public void setServletContext(ServletContext servletContext) { |
|
67 |
this.ctx = servletContext; |
|
68 |
} |
|
69 |
|
|
70 |
/* ------------- Implementierung RequestKontext ------------- */ |
|
71 |
|
|
72 |
@Override |
|
73 |
public HttpServletRequest getRequest() { |
|
74 |
return request; |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public void setRequest(HttpServletRequest r) { |
|
79 |
this.request = r; |
|
80 |
} |
|
81 |
|
|
82 |
} |