ulrich
2017-02-28 c16501f52fb61dd7c2c6e7977f486828d53918fc
commit | author | age
e28ac1 1 /*
U 2  *  Nutzerverwaltung - User and role management in your browser
3  *  Copyright (C) 2011-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 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
70a614 19 package de.uhilger.um.api;
U 20
21 import de.uhilger.baselink.PersistenceManager;
22 import de.uhilger.baselink.Record;
23 import de.uhilger.transit.web.RequestKontext;
24 import de.uhilger.transit.web.WebKontext;
25 import static de.uhilger.um.api.UserMgr.UM_DB;
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(UM_DB);
42   }
43   
44   protected String getSql(String id) {
45     Properties sql = (Properties) ctx.getAttribute(UserMgr.UM_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 }