From 708f665037ff7d742d27504aada3c126e1764323 Mon Sep 17 00:00:00 2001
From: ulrich <undisclosed>
Date: Wed, 04 Apr 2018 05:51:10 +0000
Subject: [PATCH] collectFiles neu nach WbxUtils verlegt

---
 src/de/uhilger/wbx/WbxUtils.java        |   60 ++++++++++++++++++++
 src/de/uhilger/wbx/data/Inhalt.java     |  102 ++++++++++++++++++++++++++++++++++
 src/de/uhilger/wbx/web/FeedServlet.java |   14 ++--
 3 files changed, 169 insertions(+), 7 deletions(-)

diff --git a/src/de/uhilger/wbx/WbxUtils.java b/src/de/uhilger/wbx/WbxUtils.java
index 9705fce..963b5bf 100644
--- a/src/de/uhilger/wbx/WbxUtils.java
+++ b/src/de/uhilger/wbx/WbxUtils.java
@@ -18,6 +18,7 @@
 
 package de.uhilger.wbx;
 
+import de.uhilger.wbx.data.Inhalt;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -43,9 +44,68 @@
   public static final String NO_STRING = " ist kein String";  
   public static final String EMPTY_STRING = "";
   
+  public static final String WBX_FILE_BASE = "wbxFileBase";  
+  
   public static final String WBX_PUB_DIR_NAME = "wbxPubDirName";
   public static final String WBX_DEFAULT_PUB_DIR_NAME = "/www";
   
+  public static final String WBX_PUB_URL_NAME = "wbxPubUrlName";
+  public static final String WBX_DEFAULT_PUB_URL_NAME = "/data";
+  
+  
+  public List<Inhalt> collectFiles(String requestUrl, String contextPath, 
+          String relativePath, int maxTiefe, int maxAnzahl) {
+    Bild bild = new Bild();
+    //WbxUtils wu = new WbxUtils();
+    String basis = getJNDIParameter(WBX_FILE_BASE, WbxUtils.EMPTY_STRING);
+    String pubDirName = getJNDIParameter(WbxUtils.WBX_PUB_DIR_NAME, WbxUtils.WBX_DEFAULT_PUB_DIR_NAME);
+    String pubUrlName = getJNDIParameter(WbxUtils.WBX_PUB_URL_NAME, WbxUtils.WBX_DEFAULT_PUB_URL_NAME);
+    String relPath = relativePath.replace(pubUrlName, pubDirName);
+    String absPath = basis + relPath;
+    
+    ArrayList beitraege = new ArrayList();
+    ArrayList<Inhalt> files = new ArrayList<>();
+    collectFiles(new File(absPath), 0, beitraege, maxTiefe, maxAnzahl);
+
+    Iterator i = beitraege.iterator();
+    while(i.hasNext()) {
+      File beitrag = (File) i.next();
+      Inhalt cont = new Inhalt();
+      cont.setMimetype(bild.getMimeType(beitrag));
+      cont.setIsDirectory(beitrag.isDirectory());
+      cont.setIsHidden(beitrag.isHidden());
+      cont.setLastModified(beitrag.lastModified());
+      cont.setLength(beitrag.length());
+      
+      /*
+        den 'https://..'-Teil bis vor dem 
+        ContextPath ermitteln
+      */
+      //String requestUrl = getRequest().getRequestURL().toString();
+      //String contextPath = getRequest().getContextPath();
+      int pos = requestUrl.indexOf(contextPath);
+      
+      /*
+        den Teil des Pfades ermitteln, der zwischen dem 
+        ContextPath zum oeffentlichen Ordner und dem Dateiname 
+        steht
+      */
+      String absolutePath = beitrag.getAbsolutePath();
+      absolutePath = absolutePath.replace(beitrag.getName(), "");
+      absolutePath = absolutePath.replace(pubDirName, "");
+      String part = relativePath.replace(pubUrlName, "");
+      int pos2 = absolutePath.indexOf(part);
+      String mittelteil = absolutePath.substring(pos2);
+      mittelteil = mittelteil.replace(part, "");
+      cont.setBase(requestUrl.substring(0, pos));
+      
+      cont.setUrl(/*requestUrl.substring(0, pos) + "/data" + */ mittelteil + beitrag.getName());
+      files.add(cont);
+    }
+    return files;
+  } 
+  
+  
   /**
    * Diese Methode funktioniert nur, wenn entweder ein Ordner uebergeben 
    * wird, der keine Unterordner enthaelt wie zum Beispiel der Ordner 'neu' 
diff --git a/src/de/uhilger/wbx/data/Inhalt.java b/src/de/uhilger/wbx/data/Inhalt.java
new file mode 100644
index 0000000..f39cf31
--- /dev/null
+++ b/src/de/uhilger/wbx/data/Inhalt.java
@@ -0,0 +1,102 @@
+/*
+    WebBox - Dein Server.
+    Copyright (C) 2017, 2018 Ulrich Hilger, http://uhilger.de
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero 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 Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package de.uhilger.wbx.data;
+
+/**
+ * Inhalt
+ * @author ulrich
+ */
+public class Inhalt {
+  private String base;
+  private String url;
+  private String abst;
+  private Long lastModified;
+  private Long length;
+  private String mimetype;
+	private Boolean isDirectory;
+	private Boolean isHidden;
+
+  public String getBase() {
+    return base;
+  }
+
+  public void setBase(String base) {
+    this.base = base;
+  }
+
+  
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  public String getAbst() {
+    return abst;
+  }
+
+  public void setAbst(String abst) {
+    this.abst = abst;
+  }
+
+  public Long getLastModified() {
+    return lastModified;
+  }
+
+  public void setLastModified(Long lastModified) {
+    this.lastModified = lastModified;
+  }
+
+  public Long getLength() {
+    return length;
+  }
+
+  public void setLength(Long length) {
+    this.length = length;
+  }
+
+  public String getMimetype() {
+    return mimetype;
+  }
+
+  public void setMimetype(String mimetype) {
+    this.mimetype = mimetype;
+  }
+
+  public Boolean getIsDirectory() {
+    return isDirectory;
+  }
+
+  public void setIsDirectory(Boolean isDirectory) {
+    this.isDirectory = isDirectory;
+  }
+
+  public Boolean getIsHidden() {
+    return isHidden;
+  }
+
+  public void setIsHidden(Boolean isHidden) {
+    this.isHidden = isHidden;
+  }
+  
+  
+  
+}
diff --git a/src/de/uhilger/wbx/web/FeedServlet.java b/src/de/uhilger/wbx/web/FeedServlet.java
index d74d7d6..b005af5 100644
--- a/src/de/uhilger/wbx/web/FeedServlet.java
+++ b/src/de/uhilger/wbx/web/FeedServlet.java
@@ -57,7 +57,7 @@
  * folgenden Eintraege enthalten:</p>
  * <pre>
  * <Environment name="wbxFileBase" type="java.lang.String" value="absoluter/pfad/zur/dateiablage" override="false" />
- * <Environment name="wbxPubDir" type="java.lang.String" value="/www" override="false" />
+ * <Environment name="wbxPubDirName" type="java.lang.String" value="/www" override="false" />
  * <Environment name="wbxFeedTitle" type="java.lang.String" value="Newsfeed" override="false" />
  * <Environment name="wbxFeedSubtitle" type="java.lang.String" value="Text des Untertitels" override="false" />
  * <Environment name="wbxFeedCopyright" type="java.lang.String" value="Text des Copyright-Hinweises" override="false" />
@@ -69,9 +69,9 @@
   
   private static final Logger logger = Logger.getLogger(FeedServlet.class.getName());
   
-  public static final String JNDI_CTX_NAME = "java:comp/env";
-  public static final String WBX_FILE_BASE = "wbxFileBase";
-  public static final String WBX_PUB_DIR = "wbxPubDir";
+  //public static final String JNDI_CTX_NAME = "java:comp/env";
+  //public static final String WBX_FILE_BASE = "wbxFileBase";
+  //public static final String WBX_PUB_DIR = "wbxPubDir";
   public static final String WBX_MAX_FEED_DEPTH = "wbxMaxFeedDepth";
   public static final String WBX_MAX_FEED_ENTRIES = "wbxMaxFeedEntries";
   public static final String WBX_FEED_TITLE = "wbxFeedTitle";
@@ -94,11 +94,11 @@
     String zielPfad = url.substring(url.indexOf(contextPath));
     logger.fine(zielPfad);
     WbxUtils wu = new WbxUtils();
-    String basis = wu.getJNDIParameter(WBX_FILE_BASE, WbxUtils.EMPTY_STRING);
+    String basis = wu.getJNDIParameter(WbxUtils.WBX_FILE_BASE, WbxUtils.EMPTY_STRING);
     logger.fine("basis: " + basis);
     StringBuffer pfad = new StringBuffer();
     pfad.append(basis);
-    pfad.append(zielPfad.replace(contextPath, wu.getJNDIParameter(WBX_PUB_DIR, WbxUtils.EMPTY_STRING)));
+    pfad.append(zielPfad.replace(contextPath, wu.getJNDIParameter(WbxUtils.WBX_PUB_DIR_NAME, WbxUtils.WBX_DEFAULT_PUB_DIR_NAME)));
     logger.fine("pfad: " + pfad);
     String dirStr = pfad.toString().substring(0, pfad.lastIndexOf("/"));
     logger.fine("dirStr: " + dirStr);
@@ -153,7 +153,7 @@
 
       String urlStr = f.getAbsolutePath();
       urlStr = urlStr.replace(basis, domain);
-      urlStr = urlStr.replace(wu.getJNDIParameter(WBX_PUB_DIR, WbxUtils.EMPTY_STRING), contextPath);
+      urlStr = urlStr.replace(wu.getJNDIParameter(WbxUtils.WBX_PUB_DIR_NAME, WbxUtils.WBX_DEFAULT_PUB_DIR_NAME), contextPath);
 
       logger.fine(urlStr);
 

--
Gitblit v1.9.3