| | |
| | | |
| | | package de.uhilger.wbx; |
| | | |
| | | import de.uhilger.wbx.data.Inhalt; |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | |
| | | 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' |