From 5ebac825d99fb9b6bed2edeeb4c15ba34e8b6350 Mon Sep 17 00:00:00 2001
From: ulrich <undisclosed>
Date: Tue, 03 Apr 2018 07:34:27 +0000
Subject: [PATCH] Lesen von JNDI-Parametern hinzugefuegt

---
 src/de/uhilger/wbx/WbxUtils.java |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/de/uhilger/wbx/WbxUtils.java b/src/de/uhilger/wbx/WbxUtils.java
index b5308fc..384c1ad 100644
--- a/src/de/uhilger/wbx/WbxUtils.java
+++ b/src/de/uhilger/wbx/WbxUtils.java
@@ -19,7 +19,11 @@
 package de.uhilger.wbx;
 
 import java.io.File;
+import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.servlet.ServletContext;
 
 /**
@@ -29,8 +33,43 @@
   
   private static final Logger logger = Logger.getLogger(WbxUtils.class.getName());
   
+  public static final String JNDI_CTX_NAME = "java:comp/env";
+  
+  public static final String NOT_FOUND = " nicht gefunden";
+  public static final String NO_STRING = " ist kein String";  
+  public static final String EMPTY_STRING = "";
+
   //public static final String FILE_BASE = "filebase";
   //public static final String DATENABLAGE = "datenAblage";  
+
+  public int getJNDIInt(String paramName, int defaultVal) {
+    String jndiStr = getJNDIParameter(paramName, Integer.toString(defaultVal));
+    try {
+      return Integer.parseInt(jndiStr);
+    } catch(NumberFormatException ex) {
+      logger.log(Level.FINE, ex.getMessage());
+      return defaultVal;
+    }
+  }
+  
+  public String getJNDIParameter(String pname, String defaultVal) {
+    try {
+      // unseren environment naming context ermitteln
+      Context initCtx = new InitialContext();
+      Context envCtx = (Context) initCtx.lookup(JNDI_CTX_NAME);
+      
+      // unseren Parameter lesen
+      Object o = envCtx.lookup(pname);
+      if(o instanceof String) {
+        return o.toString();      
+      } else {
+        return defaultVal;
+      }
+    } catch (NamingException ex) {
+      logger.log(Level.FINE, ex.getMessage());
+      return defaultVal;
+    }
+  }  
   
   /**
    * Bei der WebBox ist das Datenverzeichnis relativ zum Verzeichnis 

--
Gitblit v1.9.3