diff --git a/src/org/forkalsrud/album/exif/DirectoryEntry.java b/src/org/forkalsrud/album/exif/DirectoryEntry.java index b040732..96625d3 100644 --- a/src/org/forkalsrud/album/exif/DirectoryEntry.java +++ b/src/org/forkalsrud/album/exif/DirectoryEntry.java @@ -299,6 +299,8 @@ public class DirectoryEntry extends Entry { private void populate(Properties props) throws ParseException { String coverFileName = props.getProperty("cover"); + String caption = props.getProperty("caption"); + setCaption(caption); HashMap entryMap = new HashMap(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss"); Iterator i = props.keySet().iterator(); @@ -317,7 +319,7 @@ public class DirectoryEntry extends Entry { thumbnail.setEtag(props.getProperty("file." + name + ".etag")); entry.setThumbnail(thumbnail); children.add(entry); - if (name != null && (coverFileName == null || name.equals(coverFileName))) { + if (name != null && name.equals(coverFileName)) { setThumbnail(thumbnail); } } @@ -326,6 +328,9 @@ public class DirectoryEntry extends Entry { children.add(new DirectoryEntry(this, new File(file, name))); } } + if (thumbnail == null && !children.isEmpty()) { + setThumbnail(children.get(0).getThumbnail()); + } } } diff --git a/src/org/forkalsrud/album/web/AlbumServlet.java b/src/org/forkalsrud/album/web/AlbumServlet.java index 38ca54b..29f4fa6 100644 --- a/src/org/forkalsrud/album/web/AlbumServlet.java +++ b/src/org/forkalsrud/album/web/AlbumServlet.java @@ -103,6 +103,7 @@ public class AlbumServlet try { res.setContentType("text/html"); req.setAttribute("entry", entry); + req.setAttribute("thmb", new Integer(250)); RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/photo.vm"); rd.forward(req, res); } catch (Exception e) { @@ -111,27 +112,28 @@ public class AlbumServlet } - boolean etagMatches(HttpServletRequest req, HttpServletResponse res, Thumbnail thumbnail, String size) { + boolean etagMatches(HttpServletRequest req, String fileEtag) { String cacheControl = req.getHeader("Cache-Control"); if ("max-age=0".equals(cacheControl)) { return false; } String reqEtag = req.getHeader("If-None-Match"); - String fileEtag = thumbnail.getEtag() + "-" + size; if (reqEtag != null) { return reqEtag.equals(fileEtag); } - res.setHeader("ETag", fileEtag); return false; } void scaleImage(HttpServletRequest req, HttpServletResponse res, File file, Thumbnail thumbnail, String size) throws IOException { - if (etagMatches(req, res, thumbnail, size)) { + String fileEtag = thumbnail.getEtag() + "-" + size; + if (etagMatches(req, fileEtag)) { res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } + res.setHeader("ETag", fileEtag); + Dimension orig = thumbnail.getSize(); Dimension outd; if (size.endsWith("h")) { @@ -208,6 +210,10 @@ public class AlbumServlet } + /** + * maps files to uris relative to servlet, e.g. /home/joe/photos/holiday/arrival.jpg -> /photos/holiday/arrival.jpg + * assuming base is /home/joe/photos + */ public class Mapper { public String map(File file) { diff --git a/webapp/WEB-INF/velocity/photo.vm b/webapp/WEB-INF/velocity/photo.vm index c82e3aa..a5bcbd9 100644 --- a/webapp/WEB-INF/velocity/photo.vm +++ b/webapp/WEB-INF/velocity/photo.vm @@ -8,7 +8,7 @@