From: Roland Haeder <roland@mxchange.org>
Date: Fri, 28 Aug 2015 20:33:49 +0000 (+0200)
Subject: No, better put it here.
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=90c4bfdfd254a5f9d1288f6e93248130053af37b;p=jcore-utils.git

No, better put it here.
Signed-off-by:Roland Häder <roland@mxchange.org>
---

diff --git a/src/org/mxchange/jsfcore/BaseServletSystem.java b/src/org/mxchange/jsfcore/BaseServletSystem.java
new file mode 100644
index 0000000..f8bdd74
--- /dev/null
+++ b/src/org/mxchange/jsfcore/BaseServletSystem.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jsfcore;
+
+import java.text.MessageFormat;
+import javax.servlet.ServletContext;
+import org.mxchange.jcore.BaseFrameworkSystem;
+
+/**
+ * A general shop class
+ * @author Roland Haeder
+ */
+public class BaseServletSystem extends BaseFrameworkSystem {
+	/**
+	 * Initializes properties from given servlet configuration
+	 * @param context Servlet context instance
+	 */
+	protected void initProperties (final ServletContext context) {
+		// Trace message
+		this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N
+
+		// context shall not be null
+		if (null == context) {
+			// Abort here
+			throw new NullPointerException("context is null");
+		}
+
+		// We need some properties that needs to be set
+		for (final String name : this.getPropertyNames()) {
+			// Debug log
+			this.getLogger().debug(MessageFormat.format("name={0}", name)); //NOI18N
+
+			// Get value
+			String value = context.getInitParameter(name);
+
+			// Debug message
+			this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
+
+			// Is it null?
+			if (null == value) {
+				// Value is null
+				throw new NullPointerException(MessageFormat.format("value for {0} is null, maybe invalid context parameter?", name)); //NOI18N
+			} else if (name.equals("database.backend.storagepath")) { //NOI18N
+				// Need to expand this path
+				value = context.getRealPath(String.format("../../%s", value.trim())); //NOI18N
+			}
+
+			// Debug log
+			this.getLogger().debug(MessageFormat.format("{0}={1}", name, value)); //NOI18N
+
+			// Set property
+			this.setProperty(name, value);
+		}
+
+		// Trace message
+		this.getLogger().trace("EXIT!"); //NOI18N
+	}
+}