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 |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/de/uhilger/httpserver/base/HttpHelper.java b/src/de/uhilger/httpserver/base/HttpHelper.java
index 56275b1..d9985a6 100644
--- a/src/de/uhilger/httpserver/base/HttpHelper.java
+++ b/src/de/uhilger/httpserver/base/HttpHelper.java
@@ -18,10 +18,13 @@
 package de.uhilger.httpserver.base;
 
 import com.sun.net.httpserver.HttpExchange;
+import de.uhilger.httpserver.base.handler.FileHandler;
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Map;
 
 /**
  * Helfer fuer HTTP-Methoden
@@ -68,5 +71,34 @@
     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) {
+    boolean notFound = true;
+    File file = null;
+    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) {
+      file = new File(fileBase, fName + FileHandler.WELCOME_FILE);
+    }
+    return file;
+  }
   
 }

--
Gitblit v1.9.3