]> git.mxchange.org Git - jcoreee.git/blob - src/org/mxchange/jsfcore/BaseServletSystem.java
Some improvements
[jcoreee.git] / src / org / mxchange / jsfcore / BaseServletSystem.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jsfcore;
18
19 import java.text.MessageFormat;
20 import javax.servlet.ServletContext;
21 import org.mxchange.jcore.BaseFrameworkSystem;
22
23 /**
24  * A general shop class
25  * @author Roland Haeder
26  */
27 public class BaseServletSystem extends BaseFrameworkSystem {
28         /**
29          * Initializes properties from given servlet configuration
30          * @param context Servlet context instance
31          */
32         protected void initProperties (final ServletContext context) {
33                 // Trace message
34                 this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N
35
36                 // context shall not be null
37                 if (null == context) {
38                         // Abort here
39                         throw new NullPointerException("context is null"); //NOI18N
40                 }
41
42                 // We need some properties that needs to be set
43                 for (final String name : this.getPropertyNames()) {
44                         // Debug log
45                         this.getLogger().debug(MessageFormat.format("name={0}", name)); //NOI18N
46
47                         // Get value
48                         String value = context.getInitParameter(name);
49
50                         // Debug message
51                         this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
52
53                         // Is it null?
54                         if (null == value) {
55                                 // Value is null
56                                 throw new NullPointerException(MessageFormat.format("value for {0} is null, maybe invalid context parameter?", name)); //NOI18N
57                         } else if (name.equals("database.backend.storagepath")) { //NOI18N
58                                 // Need to expand this path
59                                 value = context.getRealPath(String.format("../../%s", value.trim())); //NOI18N
60                         }
61
62                         // Debug log
63                         this.getLogger().debug(MessageFormat.format("{0}={1}", name, value)); //NOI18N
64
65                         // Set property
66                         this.setProperty(name, value);
67                 }
68
69                 // Trace message
70                 this.getLogger().trace("EXIT!"); //NOI18N
71         }
72 }