| | |
| | | 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.filecms.pub.ImgFileFilter; |
| | | import de.uhilger.wbx.Bild; |
| | | import de.uhilger.wbx.WbxUtils; |
| | | import static de.uhilger.wbx.web.FeedServlet.WBX_FILE_BASE; |
| | | import static de.uhilger.wbx.WbxUtils.EMPTY_STRING; |
| | | import static de.uhilger.wbx.WbxUtils.WBX_FILE_BASE; |
| | | import de.uhilger.wbx.data.Inhalt; |
| | | import de.uhilger.wbx.web.TNServlet; |
| | | import java.io.File; |
| | | import java.io.FileFilter; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | |
| | | import java.security.Principal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Enumeration; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | import java.util.zip.ZipOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.apache.commons.io.FileUtils; |
| | | |
| | |
| | | logger.fine("listing path: " + path); |
| | | File dir = new File(path); |
| | | if (dir.exists()) { |
| | | File[] fileArray = dir.listFiles(); |
| | | File[] fileArray = dir.listFiles(new ImgFileFilter()); |
| | | if (orderBy != null && orderBy.equalsIgnoreCase("name")) { |
| | | Arrays.sort(fileArray, new FileNameComparator(order)); |
| | | } else { |
| | |
| | | } |
| | | 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 List<Inhalt> collect(String relativePath, int maxTiefe, int maxAnzahl, int len) { |
| | | |
| | | WbxUtils wu = new WbxUtils(); |
| | | HttpServletRequest req = getRequest(); |
| | | String requestUrl = req.getRequestURL().toString(); |
| | | String contextPath = req.getContextPath(); |
| | | return wu.collectFiles(requestUrl, contextPath, relativePath, maxTiefe, maxAnzahl, len); |
| | | } |
| | | |
| | | public FileRef newFolder(String relPath, String folderName) { |
| | | if (!relPath.startsWith(".")) { |