250 pixel thumbnails

This commit is contained in:
erik 2009-01-12 01:11:24 +00:00
parent 7a1dfbd03c
commit 396aed49a0
3 changed files with 21 additions and 9 deletions

View file

@ -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<String, Entry> entryMap = new HashMap<String, Entry>();
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());
}
}
}

View file

@ -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) {

View file

@ -8,7 +8,7 @@
<style type="text/css">
body {
font-size: 11px;
font-family: "Lucida Grande", Arial, sans-serif;
font-family: "Lucida Grande", "Lucida Sans", Arial, sans-serif;
color: #6d6d6d;
background: #acc95f;
margin: 10px auto;
@ -28,11 +28,12 @@
}
div.photo {
align: center;
height: 200px;
height: 200px;
}
div.grid {
float: left;
height: 150px;
#set($divheight = $thmb + 50)
height: ${divheight}px;
}
img {
padding: 5px;
@ -61,7 +62,7 @@
<span class="caption">$!entry.caption</span>
</div>
#else
#set($thmb = 150)
#foreach($en in $entry.getContents())
#set($dim = $en.thumbnail.size.scaled($thmb))
#set($thpath = $mapper.map(${en.thumbnail.getPath()}))