Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1273 → Rev 1274

/PhotoAlbum/trunk/src/ak/photoalbum/config/ConfigDirThumbnail.java
1,7 → 1,5
package ak.photoalbum.config;
 
import java.util.List;
import java.util.ArrayList;
import org.apache.log4j.Logger;
 
public class ConfigDirThumbnail
/PhotoAlbum/trunk/src/ak/photoalbum/config/ConfigRoot.java
9,7 → 9,7
private static final Logger logger = Logger.getLogger(ConfigRoot.class);
 
private String defaultBranch;
private List branches = new ArrayList();
private final List branches = new ArrayList();
 
public ConfigRoot()
{
/PhotoAlbum/trunk/src/ak/photoalbum/config/ConfigBranch.java
14,9 → 14,9
private String thumbnailFormat;
private int columns;
private int rows;
private List imagesMasks = new ArrayList();
private String dirTemplate;
private List dirThumbnails = new ArrayList();
private final List imagesMasks = new ArrayList();
private final List dirThumbnails = new ArrayList();
 
public ConfigBranch()
{
/PhotoAlbum/trunk/src/ak/photoalbum/images/jiu/JiuResizer.java
12,7 → 12,6
import net.sourceforge.jiu.data.BilevelImage;
import net.sourceforge.jiu.data.Gray8Image;
import net.sourceforge.jiu.data.MemoryRGB24Image;
import net.sourceforge.jiu.data.Palette;
import net.sourceforge.jiu.data.Paletted8Image;
import net.sourceforge.jiu.data.PixelImage;
import net.sourceforge.jiu.data.RGB24Image;
36,11 → 35,10
FILTER_TYPE_MITCHELL 3.6 7.1
*/
 
protected Logger logger;
private static final Logger logger = Logger.getLogger(JiuResizer.class);
 
public JiuResizer()
{
this.logger = Logger.getLogger(this.getClass());
}
 
public BufferedImage resize(Image origin, int newWidth, int newHeight)
64,7 → 62,7
return convertToAwtImage(resample.getOutputImage(), DEFAULT_ALPHA);
}
catch(Exception ex) {
ex.printStackTrace();
logger.warn("Cannot resize image", ex);
 
throw new RuntimeException(ex.getMessage());
}
/PhotoAlbum/trunk/src/ak/photoalbum/images/Thumbnailer.java
8,7 → 8,6
import java.io.FileFilter;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
41,7 → 40,8
protected static final int CACHED_NOT_MODIFIED = 1;
protected static final int CACHED_WRITTEN = 2;
 
protected Logger logger;
private static final Logger logger = Logger.getLogger(Thumbnailer.class);
 
protected ImageResizer resizer;
protected int smallWidth = DEFAULT_SMALL_WIDTH;
protected int smallHeight = DEFAULT_SMALL_HEIGHT;
65,7 → 65,6
 
public Thumbnailer()
{
this.logger = Logger.getLogger(this.getClass());
}
 
public String getMime()
140,15 → 139,15
in = new FileInputStream(origin);
ii.setInput(in);
 
if(!ii.check()) {
if(ii.check()) {
res[0] = ii.getWidth();
res[1] = ii.getHeight();
}
else{
logger.warn("not supported format of " + origin.getCanonicalPath());
res[0] = 0;
res[1] = 0;
}
else{
res[0] = ii.getWidth();
res[1] = ii.getHeight();
}
}
finally {
if(in != null) in.close();
373,15 → 372,15
"unknown type of cached " + file.getCanonicalPath());
}
 
if(origin != null && cache != null) {
loadCacheInfo(file, origin, cache);
}
else {
if(origin == null || cache == null) {
file.delete();
 
if(logger.isDebugEnabled())
logger.debug("deleted (unknown origin)");
}
else {
loadCacheInfo(file, origin, cache);
}
}
 
protected void loadCacheInfo(File file, File origin, Map cache)
553,145 → 552,154
return true; // image written
}
 
synchronized protected BufferedImage createThumbnail(File imageFile,
protected BufferedImage createThumbnail(File imageFile,
int width, int height)
throws IOException
{
if(logger.isDebugEnabled())
logger.debug("create thumbnail " + imageFile.getCanonicalPath());
// FIXME make several instances parallel if we have sevelar processors
synchronized(this) {
if(logger.isDebugEnabled())
logger.debug("create thumbnail " + imageFile.getCanonicalPath());
 
Image image = loadImage(imageFile.getCanonicalPath());
// = ImageIO.read(imageFile);
int[] sizes;
Image image = loadImage(imageFile.getCanonicalPath());
// = ImageIO.read(imageFile);
int[] sizes;
 
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
 
return null;
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
width, height);
logger.debug("resize to " + sizes[0] + "x" + sizes[1]);
return null;
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
width, height);
logger.debug("resize to " + sizes[0] + "x" + sizes[1]);
 
return resizer.resize(image, sizes[0], sizes[1]);
return resizer.resize(image, sizes[0], sizes[1]);
}
}
}
 
synchronized protected BufferedImage createThumbnailNative(File dir, File cacheFile,
protected BufferedImage createThumbnailNative(File dir, File cacheFile,
File imageFile, int width, int height)
throws IOException
{
if(logger.isDebugEnabled())
logger.debug("create thumbnail2 " + imageFile.getCanonicalPath() + " to "
+ cacheFile.getCanonicalPath());
// FIXME make several instances parallel if we have sevelar processors
synchronized(this) {
if(logger.isDebugEnabled())
logger.debug("create thumbnail2 " + imageFile.getCanonicalPath() + " to "
+ cacheFile.getCanonicalPath());
 
dir.mkdirs();
dir.mkdirs();
 
// FIMXE: 1) make util path (and params?) configurable
Process process = Runtime.getRuntime().exec(new String[] {
"/usr/local/bin/convert",
"-size", width + "x" + height,
"-thumbnail", width + "x" + height,
imageFile.getCanonicalPath(),
cacheFile.getCanonicalPath()
});
// FIXME: 1) make util path (and params?) configurable
Process process = Runtime.getRuntime().exec(new String[] {
"/usr/local/bin/convert",
"-size", width + "x" + height,
"-thumbnail", width + "x" + height,
imageFile.getCanonicalPath(),
cacheFile.getCanonicalPath()
});
 
// FIXME make it finner
BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while((line = in.readLine()) != null) {
System.out.println("EXEC: " + line);
}
// FIXME make it finner
BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while((line = in.readLine()) != null) {
logger.info("EXEC: " + line);
}
 
try {
int res = process.waitFor();
try {
int res = process.waitFor();
 
if(logger.isDebugEnabled())
logger.debug("process exited with result " + res);
}
catch(InterruptedException ex) {
logger.debug("process interrupted");
}
if(logger.isDebugEnabled())
logger.debug("process exited with result " + res);
}
catch(InterruptedException ex) {
logger.debug("process interrupted");
}
 
return null;
return null;
}
}
 
synchronized protected BufferedImage createDirThumbnail(File dir)
protected BufferedImage createDirThumbnail(File dir)
throws IOException
{
long timeStart = System.currentTimeMillis();
// FIXME make several instances parallel if we have sevelar processors
synchronized(this) {
long timeStart = System.currentTimeMillis();
 
if(logger.isDebugEnabled())
logger.debug("create dir thumbnail " + dir.getCanonicalPath());
if(logger.isDebugEnabled())
logger.debug("create dir thumbnail " + dir.getCanonicalPath());
 
Image template = loadImage(dirTemplate.getCanonicalPath());
BufferedImage dirThumbnail;
Graphics graphics;
int count;
File[] firstFiles;
Image template = loadImage(dirTemplate.getCanonicalPath());
BufferedImage dirThumbnail;
Graphics graphics;
int count;
File[] firstFiles;
 
if(template == null) { // not supported format
logger.warn("unsupported format for template or operation interrupted");
if(template == null) { // not supported format
logger.warn("unsupported format for template or operation interrupted");
 
return null;
}
return null;
}
 
dirThumbnail = createBufferedImage(template);
dirThumbnail = createBufferedImage(template);
 
graphics = dirThumbnail.getGraphics();
count = dirThumbnailPositions.length;
firstFiles = new File[count];
count = getFirstFiles(dir, count, firstFiles, 0);
graphics = dirThumbnail.getGraphics();
count = dirThumbnailPositions.length;
firstFiles = new File[count];
count = getFirstFiles(dir, count, firstFiles, 0);
 
for(int i = 0; i < count; i++) {
Image image;
BufferedImage thumbnail = null;
int[] sizes;
for(int i = 0; i < count; i++) {
Image image;
BufferedImage thumbnail = null;
int[] sizes;
 
if(nativeMode) {
File cacheFileDir = getCacheFileDir(firstFiles[i]);
File cacheFile = getCacheFile(cacheFileDir, firstFiles[i], DIR_PART_SUFFIX);
createThumbnailNative(cacheFileDir, cacheFile, firstFiles[i],
dirThumbnailPositions[i].getWidth(), dirThumbnailPositions[i].getHeight());
image = loadImage(cacheFile.getCanonicalPath());
thumbnail = createBufferedImage(image);
}
else {
image = loadImage(firstFiles[i].getCanonicalPath());
}
if(nativeMode) {
File cacheFileDir = getCacheFileDir(firstFiles[i]);
File cacheFile = getCacheFile(cacheFileDir, firstFiles[i], DIR_PART_SUFFIX);
createThumbnailNative(cacheFileDir, cacheFile, firstFiles[i],
dirThumbnailPositions[i].getWidth(), dirThumbnailPositions[i].getHeight());
image = loadImage(cacheFile.getCanonicalPath());
thumbnail = createBufferedImage(image);
}
else {
image = loadImage(firstFiles[i].getCanonicalPath());
}
 
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
 
return null;
return null;
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
dirThumbnailPositions[i].getWidth(),
dirThumbnailPositions[i].getHeight());
}
 
if(!nativeMode) {
thumbnail = resizer.resize(image, sizes[0], sizes[1]);
}
 
graphics.drawImage(thumbnail,
getXPosition(dirThumbnailPositions[i].getX(),
dirThumbnailPositions[i].getWidth(), sizes[0],
dirThumbnailPositions[i].getHorAlign()),
getYPosition(dirThumbnailPositions[i].getY(),
dirThumbnailPositions[i].getHeight(), sizes[1],
dirThumbnailPositions[i].getVertAlign()),
null);
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
dirThumbnailPositions[i].getWidth(),
dirThumbnailPositions[i].getHeight());
}
 
if(!nativeMode) {
thumbnail = resizer.resize(image, sizes[0], sizes[1]);
if(logger.isDebugEnabled()) {
logger.debug("dir thumbnail created in "
+ (System.currentTimeMillis() - timeStart) + " ms");
}
 
graphics.drawImage(thumbnail,
getXPosition(dirThumbnailPositions[i].getX(),
dirThumbnailPositions[i].getWidth(), sizes[0],
dirThumbnailPositions[i].getHorAlign()),
getYPosition(dirThumbnailPositions[i].getY(),
dirThumbnailPositions[i].getHeight(), sizes[1],
dirThumbnailPositions[i].getVertAlign()),
null);
return dirThumbnail;
}
 
if(logger.isDebugEnabled()) {
logger.debug("dir thumbnail created in "
+ (System.currentTimeMillis() - timeStart) + " ms");
}
 
return dirThumbnail;
}
 
protected Image loadImage(String fileName)
795,8 → 803,9
Arrays.sort(children, fileNameComparatorRev);
 
for(int i = 0; i < children.length && pos < count; i++) {
if(children[i].isDirectory())
; //pos = getFirstFiles(children[i], count, files, pos);
if(children[i].isDirectory()) {
//pos = getFirstFiles(children[i], count, files, pos);
}
else {
files[pos++] = children[i];
}
/PhotoAlbum/trunk/src/ak/photoalbum/logic/PageItem.java
1,11 → 1,9
package ak.photoalbum.logic;
 
import java.io.File;
 
public class PageItem
{
private int number;
private boolean isCurrent;
private final int number;
private final boolean isCurrent;
 
public PageItem(int number, boolean isCurrent)
{
/PhotoAlbum/trunk/src/ak/photoalbum/logic/Branch.java
8,8 → 8,6
import java.io.File;
import java.io.IOException;
 
import org.apache.log4j.Logger;
 
import ak.photoalbum.images.Thumbnailer;
import ak.photoalbum.images.ThumbnailPosition;
import ak.photoalbum.util.FileNameComparator;
23,14 → 21,14
protected static final int DEFAULT_COLUMNS = 5;
protected static final int DEFAULT_ROWS = 4;
 
private Thumbnailer thumbnailer;
private ConfigBranch config;
private File imagesRoot;
private int columns = DEFAULT_COLUMNS;
private int rows = DEFAULT_ROWS;
private ImagesFilter imagesFilter;
private Comparator fileNameComparator = new FileNameComparator(true);
private Map metaInfos = new Hashtable(); // <File, MetaInfo>
private final Thumbnailer thumbnailer;
private final ConfigBranch config;
private final File imagesRoot;
private final int columns;
private final int rows;
private final ImagesFilter imagesFilter;
private final Comparator fileNameComparator = new FileNameComparator(true);
private final Map metaInfos = new Hashtable(); // <File, MetaInfo>
 
// FIXME use branch template
public Branch(ResourceFactory resourceFactory, ConfigBranch config)
39,9 → 37,17
this.config = config;
this.imagesRoot = new File(config.getImagesRoot());
this.imagesFilter = new ImagesFilter(config.getImagesMasks());
if(config.getColumns() > 0) this.columns = config.getColumns();
if(config.getRows() > 0) this.rows = config.getRows();
 
if(config.getColumns() > 0)
this.columns = config.getColumns();
else
this.columns = DEFAULT_COLUMNS;
 
if(config.getRows() > 0)
this.rows = config.getRows();
else
this.rows = DEFAULT_ROWS;
 
this.thumbnailer = new Thumbnailer();
this.thumbnailer.setImagesRoot(this.imagesRoot);
this.thumbnailer.setCacheDir(new File(config.getCacheDir()));
/PhotoAlbum/trunk/src/ak/photoalbum/logic/Logic.java
9,8 → 9,6
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.net.URLEncoder;
31,7 → 29,8
protected static final String URL_ENCODING = "UTF-8";
protected static final String META_FILE_NAME = "meta.xml"; // FIXME make configurable (?)
 
protected Logger logger;
private static final Logger logger = Logger.getLogger(Logic.class);
 
protected ConfigRoot config;
protected Map branches = new Hashtable(); // <String, Branch>
protected Digester configDigester = createConfigDigester();
39,7 → 38,6
 
protected Logic()
{
this.logger = Logger.getLogger(this.getClass());
}
 
protected Digester createConfigDigester()
/PhotoAlbum/trunk/src/ak/photoalbum/logic/MetaInfo.java
9,7 → 9,7
{
private File dir;
private String dirPath;
private Map items = new Hashtable(); // <String, MetaInfoItem>
private final Map items = new Hashtable(); // <String, MetaInfoItem>
 
public MetaInfo()
{
/PhotoAlbum/trunk/src/ak/photoalbum/util/FileNameComparator.java
6,7 → 6,7
public class FileNameComparator
implements Comparator
{
private boolean dirFirst;
private final boolean dirFirst;
 
public FileNameComparator(boolean dirFirst)
{
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/ServletResourceFactory.java
7,7 → 7,7
public class ServletResourceFactory
implements ResourceFactory
{
private ServletContext servletContext;
private final ServletContext servletContext;
 
public ServletResourceFactory(ServletContext servletContext)
{
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/IndexAction.java
47,7 → 47,7
request.setAttribute("current", current);
request.setAttribute("nextEntry", next);
request.setAttribute("pages", pages);
request.setAttribute("severalPages", new Boolean(pages.size() > 1));
request.setAttribute("severalPages", Boolean.valueOf(pages.size() > 1));
request.setAttribute("firstPage", pages.get(0));
request.setAttribute("lastPage", pages.get(pages.size() - 1));
request.setAttribute("prevPage", (page == 0) ? null : pages.get(page-1));
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/CacheForm.java
1,7 → 1,6
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;
 
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/BaseAction.java
1,6 → 1,5
package ak.photoalbum.webapp;
 
import java.util.List;
import java.io.FileNotFoundException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
9,7 → 8,6
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.log4j.Logger;
import ak.photoalbum.util.FileUtils;
import ak.photoalbum.logic.LogicSecurityException;
 
public abstract class BaseAction
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/IndexForm.java
3,7 → 3,6
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
 
public class IndexForm
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/ImageAction.java
1,6 → 1,5
package ak.photoalbum.webapp;
 
import java.io.FileNotFoundException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionMapping;
69,7 → 68,7
private class HttpTimestampRecipient
implements TimestampRecipient
{
private HttpServletResponse response;
private final HttpServletResponse response;
 
public HttpTimestampRecipient(HttpServletResponse response)
{
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/PathForm.java
1,7 → 1,6
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;
 
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/BranchForm.java
1,7 → 1,6
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.ActionForm;
import org.apache.struts.action.ActionMapping;
/PhotoAlbum/trunk/src/ak/photoalbum/webapp/CacheAction.java
1,6 → 1,5
package ak.photoalbum.webapp;
 
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
14,8 → 13,6
public final class CacheAction
extends Action
{
private static final Logger logger = Logger.getLogger(CacheAction.class);
 
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception