From f5728b1d24410f076777c1a6cd409c5e65d72051 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Sat, 03 Jul 2021 08:27:56 +0000
Subject: [PATCH] FileHandler aufgeraeumt

---
 src/de/uhilger/httpserver/base/HttpHelper.java |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/de/uhilger/httpserver/base/HttpHelper.java b/src/de/uhilger/httpserver/base/HttpHelper.java
index 565cdd4..d9985a6 100644
--- a/src/de/uhilger/httpserver/base/HttpHelper.java
+++ b/src/de/uhilger/httpserver/base/HttpHelper.java
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Map;
 
 /**
  * Helfer fuer HTTP-Methoden
@@ -70,17 +71,28 @@
     return sb.toString();
   }
   
+  public String getAttrStr(Map attributes, String key, String defaultValue) {
+    Object value = attributes.get(key);
+    if(value instanceof String) {
+      return value.toString();
+    } else {
+      return defaultValue;
+    }
+  } 
+  
   public File tryWelcomeFiles(HttpExchange e, String fName) {
-    String fileBase = e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString();
-    String welcomeFiles = e.getHttpContext().getAttributes().get(FileHandler.ATTR_WELCOME_FILES).toString();
-    String[] fileNames = welcomeFiles.split(FileHandler.STR_COMMA);
     boolean notFound = true;
-    int i = -1;
     File file = null;
-    while(notFound && ++i < fileNames.length) {
-      file = new File(fileBase, fName + fileNames[i]);
-      if(file.exists()) {
-        notFound = false;
+    String fileBase = e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString();
+    Object welcomeFiles = e.getHttpContext().getAttributes().get(FileHandler.ATTR_WELCOME_FILES);
+    if(welcomeFiles instanceof String) {
+      String[] fileNames = welcomeFiles.toString().split(FileHandler.STR_COMMA);
+      int i = -1;
+      while(notFound && ++i < fileNames.length) {
+        file = new File(fileBase, fName + fileNames[i]);
+        if(file.exists()) {
+          notFound = false;
+        }
       }
     }
     if(notFound) {

--
Gitblit v1.9.3