From e2f0bbb60123a12b84d86062789c2fb605f37dba Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Tue, 03 Apr 2018 16:45:08 +0000 Subject: [PATCH] collectFiles als API-Methode hinzugefuegt --- src/java/de/uhilger/filecms/api/FileMgr.java | 68 +++++++++++++++++++++++++++++++++ 1 files changed, 67 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..c2a26a5 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,70 @@ } return files; } - + + /** + * Wie list nur mit drill down + * + * TODO '/data' muss noch variabel gestaltet werden + * + * @param relativePath + * @param maxTiefe + * @param maxAnzahl + * @return + */ + /* + Beispiel + http://localhost:8097/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&m=collectFiles&p=/data/admin/journal/&p=2&p=200&f=JSONNICE + */ + 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(".")) { -- Gitblit v1.9.3