From 3024826f572c72f01eb19aed18c199a787af08ec Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Tue, 16 Oct 2018 00:17:49 +0200 Subject: [PATCH] Fixed media not showing up --- WebContent/page_gallery.jsp | 8 ++++---- WebContent/page_login.jsp | 6 +++--- WebContent/page_register.jsp | 6 +++--- src/zall/bean/Folder.java | 3 +++ src/zall/bean/Image.java | 5 ++++- src/zall/bean/Media.java | 15 ++++++++++++++- src/zall/bean/Video.java | 5 ++++- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/WebContent/page_gallery.jsp b/WebContent/page_gallery.jsp index bbbc0a5..e04823c 100755 --- a/WebContent/page_gallery.jsp +++ b/WebContent/page_gallery.jsp @@ -1,6 +1,6 @@ -<%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> +<%@ page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %> @@ -38,7 +38,7 @@
- +
diff --git a/WebContent/page_login.jsp b/WebContent/page_login.jsp index f3a12b0..15eaea2 100755 --- a/WebContent/page_login.jsp +++ b/WebContent/page_login.jsp @@ -1,6 +1,6 @@ -<%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> +<%@ page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %> diff --git a/WebContent/page_register.jsp b/WebContent/page_register.jsp index f02bdf0..4a59645 100755 --- a/WebContent/page_register.jsp +++ b/WebContent/page_register.jsp @@ -1,6 +1,6 @@ -<%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> +<%@ page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %> diff --git a/src/zall/bean/Folder.java b/src/zall/bean/Folder.java index 2436346..4d0d58e 100755 --- a/src/zall/bean/Folder.java +++ b/src/zall/bean/Folder.java @@ -29,6 +29,9 @@ public class Folder extends DBBean { } public static List loadSubFolders(DBConnection db, Folder folder) throws SQLException { + if (folder == null || folder.getId() == null) + return Collections.emptyList(); + PreparedStatement sql = db.getPreparedStatement("SELECT * FROM Folder WHERE parent=?"); sql.setLong(1, folder.getId()); return DBConnection.exec(sql, DBBeanSQLResultHandler.createList(Folder.class, db)); diff --git a/src/zall/bean/Image.java b/src/zall/bean/Image.java index 61aafa5..1dd1600 100644 --- a/src/zall/bean/Image.java +++ b/src/zall/bean/Image.java @@ -6,6 +6,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.logging.Logger; @@ -37,7 +38,8 @@ public class Image extends Media { */ public static List loadFolder(DBConnection db, Folder folder) throws SQLException { if (folder == null || folder.getId() == null) - return new LinkedList(); + return Collections.emptyList(); + PreparedStatement sql = db.getPreparedStatement("SELECT * FROM Image WHERE folder=? ORDER BY dateUploaded DESC"); sql.setLong(1, folder.getId()); return DBConnection.exec(sql, DBBeanSQLResultHandler.createList(Image.class, db)); @@ -64,6 +66,7 @@ public class Image extends Media { public void setFile(FileItem item) throws Exception { if (folder == null) throw new Exception("Folder not set for image!"); + // Generate unique filename fileName = ResourceManager.generateFileName(); fileExtension = FileUtil.getFileExtension(item.getName()); diff --git a/src/zall/bean/Media.java b/src/zall/bean/Media.java index eab0f62..f5b0223 100644 --- a/src/zall/bean/Media.java +++ b/src/zall/bean/Media.java @@ -14,6 +14,7 @@ import java.util.logging.Logger; import org.apache.commons.fileupload.FileItem; import zall.manager.ResourceManager; +import zall.page.ContentServlet; import zutil.db.DBConnection; import zutil.db.bean.DBBean; import zutil.log.LogUtil; @@ -134,6 +135,18 @@ public abstract class Media extends DBBean implements Comparable { return ResourceManager.getFile(this, size); } - public abstract Type getType(); + + public String getUrlSmall() { + return ContentServlet.getMediaUrl(this, Size.SMALL); + } + public String getUrlMedium() { + return ContentServlet.getMediaUrl(this, Size.MEDIUM); + } + public String getUrlLarge() { + return ContentServlet.getMediaUrl(this, Size.LARGE); + } + public String getUrlOriginal() { + return ContentServlet.getMediaUrl(this, Size.ORIGINAL); + } } diff --git a/src/zall/bean/Video.java b/src/zall/bean/Video.java index 1862dc7..7147339 100755 --- a/src/zall/bean/Video.java +++ b/src/zall/bean/Video.java @@ -2,6 +2,7 @@ package zall.bean; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -42,7 +43,8 @@ public class Video extends Media { */ public static List