From 0b6a2bdf420c6fa90eaefade65690a1ab0319a0d Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Tue, 03 Apr 2018 10:17:47 +0000 Subject: [PATCH] JNDI-Methoden in FeedServlet umgestellt --- src/de/uhilger/wbx/web/FeedServlet.java | 62 +++++++----------------------- 1 files changed, 15 insertions(+), 47 deletions(-) diff --git a/src/de/uhilger/wbx/web/FeedServlet.java b/src/de/uhilger/wbx/web/FeedServlet.java index c23e6cd..16a3ef7 100644 --- a/src/de/uhilger/wbx/web/FeedServlet.java +++ b/src/de/uhilger/wbx/web/FeedServlet.java @@ -1,6 +1,7 @@ package de.uhilger.wbx.web; +import de.uhilger.wbx.WbxUtils; import de.vogella.rss.model.Feed; import de.vogella.rss.model.FeedMessage; import java.io.File; @@ -19,9 +20,6 @@ import java.util.Locale; 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.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; @@ -84,10 +82,7 @@ public static final int WBX_DEF_MAX_FEED_DEPTH = 3; public static final int WBX_DEF_MAX_FEED_ENTRIES = 5; - - public static final String NOT_FOUND = " nicht gefunden"; - public static final String NO_STRING = " ist kein String"; - + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ServletOutputStream out = response.getOutputStream(); @@ -98,28 +93,29 @@ logger.fine("contextPath: " + contextPath); String zielPfad = url.substring(url.indexOf(contextPath)); logger.fine(zielPfad); - String basis = getJNDIParameter(WBX_FILE_BASE); + WbxUtils wu = new WbxUtils(); + String basis = wu.getJNDIParameter(WBX_FILE_BASE, WbxUtils.EMPTY_STRING); logger.fine("basis: " + basis); StringBuffer pfad = new StringBuffer(); pfad.append(basis); - pfad.append(zielPfad.replace(contextPath, getJNDIParameter(WBX_PUB_DIR))); + pfad.append(zielPfad.replace(contextPath, wu.getJNDIParameter(WBX_PUB_DIR, WbxUtils.EMPTY_STRING))); logger.fine("pfad: " + pfad); String dirStr = pfad.toString().substring(0, pfad.lastIndexOf("/")); logger.fine("dirStr: " + dirStr); File dir = new File(dirStr); if (dir.isDirectory()) { List beitraege = new ArrayList(); - int maxBeitraege = getJNDIInt(WBX_MAX_FEED_ENTRIES, WBX_DEF_MAX_FEED_ENTRIES); - int maxTiefe = getJNDIInt(WBX_MAX_FEED_DEPTH, WBX_DEF_MAX_FEED_DEPTH); + int maxBeitraege = wu.getJNDIInt(WBX_MAX_FEED_ENTRIES, WBX_DEF_MAX_FEED_ENTRIES); + int maxTiefe = wu.getJNDIInt(WBX_MAX_FEED_DEPTH, WBX_DEF_MAX_FEED_DEPTH); collectFiles(dir, 0, beitraege, maxTiefe, maxBeitraege); Iterator i = beitraege.iterator(); while (i.hasNext()) { File f = (File) i.next(); logger.fine(f.getAbsolutePath() + " " + f.lastModified()); } - writeFeed(getJNDIParameter(WBX_FEED_TITLE), - getJNDIParameter(WBX_FEED_SUBTITLE), out, beitraege, - basis, pfad.toString(), contextPath); + writeFeed(wu.getJNDIParameter(WBX_FEED_TITLE, WbxUtils.EMPTY_STRING), + wu.getJNDIParameter(WBX_FEED_SUBTITLE, WbxUtils.EMPTY_STRING), out, beitraege, + basis, pfad.toString(), contextPath, wu); } else { logger.fine(dir.getAbsolutePath() + " ist kein Ordner."); } @@ -211,11 +207,11 @@ } public void writeFeed(String feedTitel, String beschr, ServletOutputStream s, - List beitraege, String basis, String pfad, String contextPath) { + List beitraege, String basis, String pfad, String contextPath, WbxUtils wu) { long newest = -1; - String copyright = getJNDIParameter(WBX_FEED_COPYRIGHT); - String domain = getJNDIParameter(WBX_FEED_DOMAIN); + String copyright = wu.getJNDIParameter(WBX_FEED_COPYRIGHT, WbxUtils.EMPTY_STRING); + String domain = wu.getJNDIParameter(WBX_FEED_DOMAIN, WbxUtils.EMPTY_STRING); String title = feedTitel; String description = beschr; String language = "de"; @@ -238,11 +234,11 @@ FeedMessage feedEintrag = new FeedMessage(); feedEintrag.setTitle(f.getName()); //feedEintrag.setDescription("Beschreibung hier"); - feedEintrag.setAuthor(getJNDIParameter(WBX_FEED_AUTHOR)); + feedEintrag.setAuthor(wu.getJNDIParameter(WBX_FEED_AUTHOR, WbxUtils.EMPTY_STRING)); String urlStr = f.getAbsolutePath(); urlStr = urlStr.replace(basis, domain); - urlStr = urlStr.replace(getJNDIParameter(WBX_PUB_DIR), contextPath); + urlStr = urlStr.replace(wu.getJNDIParameter(WBX_PUB_DIR, WbxUtils.EMPTY_STRING), contextPath); logger.fine(urlStr); @@ -297,33 +293,5 @@ return buf.toString(); } } - - private int getJNDIInt(String paramName, int defaultVal) { - String jndiStr = getJNDIParameter(paramName); - try { - return Integer.parseInt(jndiStr); - } catch(NumberFormatException ex) { - return defaultVal; - } - } - - private String getJNDIParameter(String pname) { - 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 NO_STRING; - } - } catch (NamingException ex) { - logger.log(Level.SEVERE, ex.getMessage()); - return NOT_FOUND; - } - } } -- Gitblit v1.9.3