Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1256 → Rev 1257

/PhotoAlbum/trunk/src/ak/photoalbum/images/Thumbnailer.java
4,7 → 4,6
import java.util.HashMap;
import java.util.Comparator;
import java.util.Arrays;
import java.io.*; // FIXME
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
11,6 → 10,8
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Graphics;
176,6 → 177,17
buildCache(imagesRoot);
}
 
public void reloadCache()
throws IOException
{
logger.info("reload cache");
 
smallCache.clear();
mediumCache.clear();
dirCache.clear();
loadCaches(cacheDir);
}
 
protected void deleteCache(File dir)
throws IOException
{
342,8 → 354,15
"unknown type of cached " + file.getCanonicalPath());
}
 
if(origin != null && cache != null)
if(origin != null && cache != null) {
loadCacheInfo(file, origin, cache);
}
else {
file.delete();
 
if(logger.isDebugEnabled())
logger.debug("deleted (unknown origin)");
}
}
 
protected void loadCacheInfo(File file, File origin, Map cache)
379,8 → 398,6
 
if(children == null) return; // the dir does not exists
 
Arrays.sort(children, fileNameComparator);
 
for(int i = 0; i < children.length; i++) {
if(children[i].isDirectory())
loadCaches(children[i]);
/PhotoAlbum/trunk/src/ak/photoalbum/logic/Logic.java
130,6 → 130,24
getBranch(uri).getThumbnailer().buildCache();
}
 
public void rebuildCache(String uri)
throws IOException, LogicException
{
getBranch(uri).getThumbnailer().rebuildCache();
}
 
public void deleteCache(String uri)
throws IOException, LogicException
{
getBranch(uri).getThumbnailer().deleteCache();
}
 
public void reloadCache(String uri)
throws IOException, LogicException
{
getBranch(uri).getThumbnailer().reloadCache();
}
 
public void getEntry(String uri, String path, IndexEntry page,
IndexEntry index, IndexEntry prev, IndexEntry current, IndexEntry next)
throws IOException, SAXException, LogicException
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/CacheAction.java
3,6 → 3,7
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
10,20 → 11,31
import org.apache.log4j.Logger;
import ak.photoalbum.logic.Logic;
 
public final class BuildCacheAction
public final class CacheAction
extends Action
{
private static final Logger logger = Logger.getLogger(IndexAction.class);
private static final Logger logger = Logger.getLogger(CacheAction.class);
 
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
PathForm theForm = (PathForm)form;
String branch = theForm.getBranch();
CacheForm theForm = (CacheForm)form;
String branch = theForm.getBranch();
String action = theForm.getAction();
// FIXME: show progress bar
 
// FIXME: show progress bar
Logic.getLogic().buildCache(branch);
if("build".equals(action))
Logic.getLogic().buildCache(branch);
else if("rebuild".equals(action))
Logic.getLogic().rebuildCache(branch);
else if("reload".equals(action))
Logic.getLogic().reloadCache(branch);
else if("delete".equals(action))
Logic.getLogic().deleteCache(branch);
else
throw new ServletException("unknown action");
 
return mapping.findForward("success");
}
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/CacheForm.java
0,0 → 1,30
package ak.photoalbum.webapp;
 
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
 
public class CacheForm
extends BranchForm
{
protected String action;
 
public String getAction()
{
return action;
}
 
public void setAction(String action)
{
this.action = action;
}
 
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
 
return errors;
}
}
/PhotoAlbum/trunk/webapp/cache.html
0,0 → 1,47
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Cache Management</title>
<style type="text/css">
input[type=submit] { width:100%; }
input[type=text] { width:100%; }
</style>
</head>
 
<body>
 
<h1>Cache Management</h1>
 
<form action="cache.do" method=GET>
<table>
<tr>
<td>Branch:</td>
<td><input type=text name=branch></td>
</tr>
<tr>
<td><input type=submit name=action value=reload></td>
<td>reload cache from disk and delete old files from it</td>
</tr>
<tr>
<td><input type=submit name=action value=delete></td>
<td>delete cache from disk</td>
</tr>
<tr>
<td><input type=submit name=action value=build></td>
<td>build cache for new and changed files only</td>
</tr>
<tr>
<td><input type=submit name=action value=rebuild></td>
<td>rebuild cache for all files</td>
</tr>
</table>
</form>
 
<p><em>Note:</em> (re)build of cache with a lot of images may take a really long time.</p>
 
</body>
 
</html>
 
/PhotoAlbum/trunk/webapp/WEB-INF/struts-config.xml
15,6 → 15,11
name="indexForm"
type="ak.photoalbum.webapp.IndexForm"
/>
 
<form-bean
name="cacheForm"
type="ak.photoalbum.webapp.CacheForm"
/>
</form-beans>
 
<global-forwards>
82,8 → 87,11
/>
 
<action
path="/buildCache"
type="ak.photoalbum.webapp.BuildCacheAction"
path="/cache"
type="ak.photoalbum.webapp.CacheAction"
name="cacheForm"
validate="true"
scope="request"
>
<forward name="success" path="/cacheOk.jsp"/>
</action>
/PhotoAlbum/trunk/webapp/cacheOk.jsp
6,13 → 6,15
<html>
 
<head>
<title>Build Cache: OK</title>
<title>Cache <bean:write name="cacheForm" property="action" />: OK</title>
</head>
 
<body bgcolor="white">
 
<h1>Build Cache: OK</h1>
<h1>Cache <bean:write name="cacheForm" property="action" />: OK</h1>
 
<p><a href="cache.html">cache management</a></p>
 
</body>
 
</html>
/PhotoAlbum/trunk/todo.txt
3,7 → 3,7
 
Sometimes by changing image size (or image rotation) the cached thumbnail is not recreated.
 
Cached files are not deleted when origins are.
Give admin possibility to reload cache (and to clear old files from it).
 
Split thumbnal and cache.