From e639c2788805fce3f6c266f48444db3099906586 Mon Sep 17 00:00:00 2001
From: ulrich <undisclosed>
Date: Tue, 03 Apr 2018 16:40:30 +0000
Subject: [PATCH] collectFiles als API-Methode hinzugefuegt

---
 src/java/de/uhilger/filecms/data/Inhalt.java |  102 ++++++++++++++++++++++++++++++++++
 src/java/de/uhilger/filecms/api/FileMgr.java |   64 +++++++++++++++++++++
 2 files changed, 165 insertions(+), 1 deletions(-)

diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java
index 32c3a54..3df6b93 100644
--- a/src/java/de/uhilger/filecms/api/FileMgr.java
+++ b/src/java/de/uhilger/filecms/api/FileMgr.java
@@ -19,9 +19,12 @@
 package de.uhilger.filecms.api;
 
 import de.uhilger.filecms.data.FileRef;
+import de.uhilger.filecms.data.Inhalt;
 import de.uhilger.filecms.pub.AbstractComparator;
 import de.uhilger.filecms.pub.FileNameComparator;
 import de.uhilger.wbx.Bild;
+import de.uhilger.wbx.WbxUtils;
+import static de.uhilger.wbx.web.FeedServlet.WBX_FILE_BASE;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -143,7 +146,66 @@
     }
     return files;
   }
-  
+ 
+  /**
+   * Wie list nur mit drill down
+   * 
+   * TODO '/data' muss noch variabel gestaltet werden
+   * 
+   * @param relativePath
+   * @param maxTiefe
+   * @param maxAnzahl
+   * @return 
+   */
+  public List<Inhalt> collectFiles(String relativePath, int maxTiefe, int maxAnzahl) {
+    Bild bild = new Bild();
+    WbxUtils wu = new WbxUtils();
+    String basis = wu.getJNDIParameter(WBX_FILE_BASE, WbxUtils.EMPTY_STRING);
+    String pubDirName = wu.getJNDIParameter(WbxUtils.WBX_PUB_DIR_NAME, WbxUtils.WBX_DEFAULT_PUB_DIR_NAME);
+    String relPath = relativePath.replace("/data", pubDirName);
+    String absPath = basis + relPath;
+    
+    ArrayList beitraege = new ArrayList();
+    ArrayList<Inhalt> files = new ArrayList<>();
+    wu.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
+      */
+      StringBuffer requestUrl = getRequest().getRequestURL();
+      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("/data", "");
+      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;
+  } 
   
   public FileRef newFolder(String relPath, String folderName) {
     if (!relPath.startsWith(".")) {
diff --git a/src/java/de/uhilger/filecms/data/Inhalt.java b/src/java/de/uhilger/filecms/data/Inhalt.java
new file mode 100644
index 0000000..49152f0
--- /dev/null
+++ b/src/java/de/uhilger/filecms/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.filecms.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;
+  }
+  
+  
+  
+}

--
Gitblit v1.9.3