ulrich@undisclosed
2020-03-30 3ae5ee41be958e59be174a6e68e05446e8baf355
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;
871896 23 import de.uhilger.transit.Access;
70a614 24 import de.uhilger.transit.web.RequestKontext;
U 25 import de.uhilger.transit.web.WebKontext;
26 import static de.uhilger.um.api.UserMgr.UM_DB;
27 import java.util.Properties;
28 import javax.servlet.ServletContext;
29 import javax.servlet.http.HttpServletRequest;
30
31 /**
32  *
33  */
34 public abstract class Api implements WebKontext, RequestKontext {
35   
36   /** Zeiger zum Servlet-Kontext dieser Anwendung */
37   private ServletContext ctx;
38   
39   private HttpServletRequest request;  
40   
41   protected PersistenceManager getDb() {
42     return (PersistenceManager) ctx.getAttribute(UM_DB);
43   }
44   
45   protected String getSql(String id) {
46     Properties sql = (Properties) ctx.getAttribute(UserMgr.UM_SQL_PROPERTIES);
47     return sql.getProperty(id);
48   }
49   
50   protected Record getMapper(String mapperName) {
51     Record record = null;
52     Object o = getServletContext().getAttribute(mapperName);
53     if(o instanceof Record) {
54       record = (Record) o;
55     }
56     return record;
57   }
58   
59   /* ------------- Implementierung WebKontext ------------- */
60
61   @Override
871896 62   @Access(type = Access.Type.RESTRICT)
70a614 63   public ServletContext getServletContext() {
U 64     return ctx;
65   }
66
67   @Override
871896 68   @Access(type = Access.Type.RESTRICT)
70a614 69   public void setServletContext(ServletContext servletContext) {
U 70     this.ctx = servletContext;
71   }
72   
73   /* ------------- Implementierung RequestKontext ------------- */
74
75   @Override
871896 76   @Access(type = Access.Type.RESTRICT)
70a614 77   public HttpServletRequest getRequest() {
U 78     return request;
79   }
80
81   @Override
871896 82   @Access(type = Access.Type.RESTRICT)
70a614 83   public void setRequest(HttpServletRequest r) {
U 84     this.request = r;
85   }
86   
87 }