| | |
| | | package de.uhilger.wbx; |
| | | |
| | | import de.uhilger.wbx.data.Inhalt; |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileReader; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | |
| | | import javax.naming.Context; |
| | | import javax.naming.InitialContext; |
| | | import javax.naming.NamingException; |
| | | import javax.servlet.ServletContext; |
| | | |
| | | /** |
| | | * |
| | |
| | | public static final String WBX_PUB_URL_NAME = "wbxPubUrlName"; |
| | | public static final String WBX_DEFAULT_PUB_URL_NAME = "/data"; |
| | | |
| | | /** |
| | | * Bei der WebBox ist das Datenverzeichnis relativ zum Verzeichnis |
| | | * $CATALINA_BASE/webapps untergebracht. |
| | | * Die Abfrage ServletContext.getRealPath |
| | | * liefert das Verzeichnis des Context dieser Webanwendung, also |
| | | * $CATALINA_BASE/webapps/file-cms |
| | | * oder |
| | | * $WBX/sys/base/webapps/file-cms |
| | | * |
| | | * Unter Windows z.B. |
| | | * C:\Users\fred\Documents\srv\wbx\sys\base\webapps\file-cms |
| | | * Unter Linux oder Mac OS z.B. |
| | | * /home/fred/srv/wbx/sys/base/webapps/file-cms |
| | | * |
| | | * Das Datenverzeichis liegt dann auf |
| | | * $WBX/daten |
| | | * |
| | | * Mit dem Verzeichnis des Context dieser Webanwendung ist das |
| | | * Datenverzeichnis der WebBox hart kodierbar mit dieser Methode |
| | | * |
| | | * @return Verzeichnis 'daten' der WebBox |
| | | */ |
| | | public File getWbxDataDir() { |
| | | File file = getWbxDir(); |
| | | file = new File(file, "daten/"); |
| | | logger.fine("WebBox Datenbasis: " + file.getAbsolutePath()); |
| | | return file; |
| | | } |
| | | |
| | | public File getWbxDir() { |
| | | logger.fine("Catalina Base: " + System.getProperty("catalina.base")); |
| | | File catalinaBase = new File(System.getProperty("catalina.base")); |
| | | File wbxDir = catalinaBase.getParentFile().getParentFile(); |
| | | return wbxDir; |
| | | } |
| | | |
| | | public List<Inhalt> collectFiles(String requestUrl, String contextPath, |
| | | String relativePath, int maxTiefe, int maxAnzahl, int length) { |
| | | Bild bild = new Bild(); |
| | | //WbxUtils wu = new WbxUtils(); |
| | | String basis = getJNDIParameter(WBX_FILE_BASE, WbxUtils.EMPTY_STRING); |
| | | if(basis.equals(WbxUtils.EMPTY_STRING)) { |
| | | basis = getWbxDataDir().getAbsolutePath(); |
| | | } |
| | | 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); |
| | |
| | | * @param dateizaehler |
| | | */ |
| | | public void collectFiles(File dir, int tiefe, List beitraege, int maxTiefe, int maxBeitraege) { |
| | | logger.fine(dir.getAbsolutePath()); |
| | | List dirs = new ArrayList(); |
| | | List beitraegeHier = new ArrayList(); |
| | | File[] files = dir.listFiles(); |
| | |
| | | String nm = bf.getName().toLowerCase(); |
| | | if(nm.endsWith(".htmi") || nm.endsWith(".html") || nm.endsWith(".htm") || |
| | | nm.endsWith(".jpg") || nm.endsWith(".jpeg") || nm.endsWith(".png") || |
| | | nm.endsWith(".txt")) { |
| | | nm.endsWith(".txt") || nm.endsWith(".md")) { |
| | | beitraege.add(bf); |
| | | } |
| | | } |