From 082145004cfa7eecde4b1b7d82c521614fbddbed Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 28 Aug 2015 22:33:49 +0200 Subject: [PATCH] No, better put it here. Signed-off-by:Roland Haeder --- .../mxchange/jsfcore/BaseServletSystem.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/org/mxchange/jsfcore/BaseServletSystem.java 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 . + */ +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 + } +} -- 2.39.5