250 pixel thumbnails
This commit is contained in:
parent
7a1dfbd03c
commit
396aed49a0
3 changed files with 21 additions and 9 deletions
|
|
@ -299,6 +299,8 @@ public class DirectoryEntry extends Entry {
|
||||||
private void populate(Properties props) throws ParseException {
|
private void populate(Properties props) throws ParseException {
|
||||||
|
|
||||||
String coverFileName = props.getProperty("cover");
|
String coverFileName = props.getProperty("cover");
|
||||||
|
String caption = props.getProperty("caption");
|
||||||
|
setCaption(caption);
|
||||||
HashMap<String, Entry> entryMap = new HashMap<String, Entry>();
|
HashMap<String, Entry> entryMap = new HashMap<String, Entry>();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||||
Iterator i = props.keySet().iterator();
|
Iterator i = props.keySet().iterator();
|
||||||
|
|
@ -317,7 +319,7 @@ public class DirectoryEntry extends Entry {
|
||||||
thumbnail.setEtag(props.getProperty("file." + name + ".etag"));
|
thumbnail.setEtag(props.getProperty("file." + name + ".etag"));
|
||||||
entry.setThumbnail(thumbnail);
|
entry.setThumbnail(thumbnail);
|
||||||
children.add(entry);
|
children.add(entry);
|
||||||
if (name != null && (coverFileName == null || name.equals(coverFileName))) {
|
if (name != null && name.equals(coverFileName)) {
|
||||||
setThumbnail(thumbnail);
|
setThumbnail(thumbnail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -326,6 +328,9 @@ public class DirectoryEntry extends Entry {
|
||||||
children.add(new DirectoryEntry(this, new File(file, name)));
|
children.add(new DirectoryEntry(this, new File(file, name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (thumbnail == null && !children.isEmpty()) {
|
||||||
|
setThumbnail(children.get(0).getThumbnail());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ public class AlbumServlet
|
||||||
try {
|
try {
|
||||||
res.setContentType("text/html");
|
res.setContentType("text/html");
|
||||||
req.setAttribute("entry", entry);
|
req.setAttribute("entry", entry);
|
||||||
|
req.setAttribute("thmb", new Integer(250));
|
||||||
RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/photo.vm");
|
RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/photo.vm");
|
||||||
rd.forward(req, res);
|
rd.forward(req, res);
|
||||||
} catch (Exception e) {
|
} 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");
|
String cacheControl = req.getHeader("Cache-Control");
|
||||||
if ("max-age=0".equals(cacheControl)) {
|
if ("max-age=0".equals(cacheControl)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String reqEtag = req.getHeader("If-None-Match");
|
String reqEtag = req.getHeader("If-None-Match");
|
||||||
String fileEtag = thumbnail.getEtag() + "-" + size;
|
|
||||||
if (reqEtag != null) {
|
if (reqEtag != null) {
|
||||||
return reqEtag.equals(fileEtag);
|
return reqEtag.equals(fileEtag);
|
||||||
}
|
}
|
||||||
res.setHeader("ETag", fileEtag);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scaleImage(HttpServletRequest req, HttpServletResponse res, File file, Thumbnail thumbnail, String size) throws IOException {
|
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);
|
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
res.setHeader("ETag", fileEtag);
|
||||||
|
|
||||||
Dimension orig = thumbnail.getSize();
|
Dimension orig = thumbnail.getSize();
|
||||||
Dimension outd;
|
Dimension outd;
|
||||||
if (size.endsWith("h")) {
|
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 class Mapper {
|
||||||
|
|
||||||
public String map(File file) {
|
public String map(File file) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body {
|
body {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-family: "Lucida Grande", Arial, sans-serif;
|
font-family: "Lucida Grande", "Lucida Sans", Arial, sans-serif;
|
||||||
color: #6d6d6d;
|
color: #6d6d6d;
|
||||||
background: #acc95f;
|
background: #acc95f;
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
|
|
@ -28,11 +28,12 @@
|
||||||
}
|
}
|
||||||
div.photo {
|
div.photo {
|
||||||
align: center;
|
align: center;
|
||||||
height: 200px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
div.grid {
|
div.grid {
|
||||||
float: left;
|
float: left;
|
||||||
height: 150px;
|
#set($divheight = $thmb + 50)
|
||||||
|
height: ${divheight}px;
|
||||||
}
|
}
|
||||||
img {
|
img {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|
@ -61,7 +62,7 @@
|
||||||
<span class="caption">$!entry.caption</span>
|
<span class="caption">$!entry.caption</span>
|
||||||
</div>
|
</div>
|
||||||
#else
|
#else
|
||||||
#set($thmb = 150)
|
|
||||||
#foreach($en in $entry.getContents())
|
#foreach($en in $entry.getContents())
|
||||||
#set($dim = $en.thumbnail.size.scaled($thmb))
|
#set($dim = $en.thumbnail.size.scaled($thmb))
|
||||||
#set($thpath = $mapper.map(${en.thumbnail.getPath()}))
|
#set($thpath = $mapper.map(${en.thumbnail.getPath()}))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue