src/java/de/uhilger/filecms/api/FileMgr.java | ●●●●● patch | view | raw | blame | history | |
src/java/de/uhilger/filecms/pub/AbstractComparator.java | ●●●●● patch | view | raw | blame | history | |
src/java/de/uhilger/filecms/pub/Catalog.java | ●●●●● patch | view | raw | blame | history | |
src/java/de/uhilger/filecms/pub/FileDateComparator.java | ●●●●● patch | view | raw | blame | history | |
src/java/de/uhilger/filecms/pub/FileNameComparator.java | ●●●●● patch | view | raw | blame | history |
src/java/de/uhilger/filecms/api/FileMgr.java
@@ -20,6 +20,9 @@ import de.uhilger.filecms.data.Bild; import de.uhilger.filecms.data.FileRef; import de.uhilger.filecms.pub.AbstractComparator; import de.uhilger.filecms.pub.FileDateComparator; import de.uhilger.filecms.pub.FileNameComparator; import java.awt.Container; import java.awt.Image; import java.awt.MediaTracker; @@ -34,6 +37,7 @@ import java.io.Reader; import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -68,6 +72,26 @@ * @return */ public List<FileRef> list(String relPath) { return listInt(relPath, "name", AbstractComparator.ORDER_ASC); } public List<FileRef> listOrdered(String relPath, String orderBy, String order) { return listInt(relPath, orderBy, order); } /** * Inhalte der WebBox listen. Hier wird nur der relative Pfad * ausgehend von www oder home ausgegeben sowie zudem ausgehend * von $daten und $basis, sofern der Benutzer die Rolle wbxAdmin hat. * * Andere Inhalte werden nicht ausgegeben. * * @param relPath * @param orderBy 'name' * @param order AbstractComparator.ORDER_ASC oder AbstractComparator.ORDER_DESC * @return */ private List<FileRef> listInt(String relPath, String orderBy, String order) { Bild bild = new Bild(); List<FileRef> files = new ArrayList(); if(relPath.length() == 0) { @@ -90,6 +114,11 @@ File dir = new File(path); if(dir.exists()) { File[] fileArray = dir.listFiles(); if(orderBy != null && orderBy.equalsIgnoreCase("name")) { Arrays.sort(fileArray, new FileNameComparator(order)); } else { Arrays.sort(fileArray, new FileNameComparator(AbstractComparator.ORDER_ASC)); } for(int i = 0; i < fileArray.length; i++) { logger.fine(fileArray[i].toURI().toString()); String fname = fileArray[i].toURI().toString().replace("file:/", ""); @@ -106,6 +135,7 @@ return files; } public FileRef newFolder(String relPath, String folderName) { logger.finer(relPath); String targetPath = null; src/java/de/uhilger/filecms/pub/AbstractComparator.java
New file @@ -0,0 +1,41 @@ /* Dateiverwaltung - File management in your browser Copyright (C) 2017 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.pub; import java.util.Comparator; import java.util.logging.Logger; /** * * @author ulrich */ public abstract class AbstractComparator implements Comparator { protected static final Logger logger = Logger.getLogger(AbstractComparator.class.getName()); public static final String ORDER_ASC = "asc"; public static final String ORDER_DESC = "desc"; protected String order; @Override public abstract int compare(Object o1, Object o2); } src/java/de/uhilger/filecms/pub/Catalog.java
@@ -24,7 +24,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.logging.Logger; src/java/de/uhilger/filecms/pub/FileDateComparator.java
@@ -1,19 +1,13 @@ package de.uhilger.filecms.pub; import java.io.File; import java.util.Comparator; import java.util.Date; import java.util.logging.Logger; /** * * @author ulrich */ public class FileDateComparator implements Comparator { private static final Logger logger = Logger.getLogger(FileDateComparator.class.getName()); private String order; public class FileDateComparator extends AbstractComparator { public FileDateComparator(String order) { this.order = order; @@ -32,7 +26,7 @@ if(f1 != null && f2 != null) { Date l1 = new Date(f1.lastModified()); Date l2 = new Date(f2.lastModified()); if(order != null && order.equalsIgnoreCase("asc")) { if(order != null && order.equalsIgnoreCase(ORDER_ASC)) { if(l1.before(l2)) { logger.fine("asc: " + f1.getName() + " kleiner " + f2.getName()); return -1; src/java/de/uhilger/filecms/pub/FileNameComparator.java
New file @@ -0,0 +1,54 @@ /* Dateiverwaltung - File management in your browser Copyright (C) 2017 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.pub; import java.io.File; /** * * @author ulrich */ public class FileNameComparator extends AbstractComparator { public FileNameComparator(String order) { this.order = order; } @Override public int compare(Object o1, Object o2) { File f1 = null; File f2 = null; if(o1 instanceof File) { f1 = (File) o1; } if(o2 instanceof File) { f2 = (File) o2; } if(f1 != null && f2 != null) { if(order != null && order.equalsIgnoreCase(ORDER_ASC)) { return f1.getName().compareToIgnoreCase(f2.getName()); } else { return f2.getName().compareToIgnoreCase(f1.getName()); } } else { logger.fine("f1 oder f2 null"); return 0; } } }