removed unused servlets
This commit is contained in:
parent
62e9aa2eeb
commit
c99838b0ec
3 changed files with 0 additions and 408 deletions
|
|
@ -1,225 +0,0 @@
|
||||||
package org.forkalsrud.album.web;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.*;
|
|
||||||
|
|
||||||
import javax.imageio.*;
|
|
||||||
|
|
||||||
import javax.servlet.*;
|
|
||||||
import javax.servlet.http.*;
|
|
||||||
|
|
||||||
public class BitmapServlet
|
|
||||||
extends HttpServlet
|
|
||||||
implements ImageObserver
|
|
||||||
{
|
|
||||||
File baseDir = new File("photos");
|
|
||||||
File cacheDir = new File("/var/org.forkalsrud.album");
|
|
||||||
|
|
||||||
final static int BUF_SIZE = 1024;
|
|
||||||
protected volatile boolean complete = false;
|
|
||||||
protected int size;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init()
|
|
||||||
throws ServletException
|
|
||||||
{
|
|
||||||
System.out.println("in init of Bitmap");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
File cacheFile(String filename, int size) {
|
|
||||||
return new File(cacheDir, filename + "-" + size + ".png");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doGet(HttpServletRequest req, HttpServletResponse res)
|
|
||||||
throws ServletException, IOException
|
|
||||||
{
|
|
||||||
res.setContentType("image/png");
|
|
||||||
|
|
||||||
// Determine which file to show
|
|
||||||
String filename = req.getServletPath();
|
|
||||||
filename = filename.substring(
|
|
||||||
"/".length(),
|
|
||||||
filename.length() - ".bitmap".length());
|
|
||||||
|
|
||||||
System.out.println("file: " + filename);
|
|
||||||
|
|
||||||
File file = new File(baseDir, filename);
|
|
||||||
if (file == null) {
|
|
||||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.isFile()) {
|
|
||||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.canRead()) {
|
|
||||||
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int size = Integer.parseInt(req.getParameter("size"));
|
|
||||||
|
|
||||||
File cacheFile = cacheFile(filename, size);
|
|
||||||
|
|
||||||
if (!cacheFile.exists()) {
|
|
||||||
writeJpegImage(file, size, cacheFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
OutputStream out = res.getOutputStream();
|
|
||||||
FileInputStream infile = new FileInputStream(cacheFile);
|
|
||||||
byte[] buf = new byte[BUF_SIZE];
|
|
||||||
int chunksize;
|
|
||||||
do {
|
|
||||||
chunksize = infile.read(buf);
|
|
||||||
if (chunksize > 0)
|
|
||||||
out.write(buf, 0, chunksize);
|
|
||||||
} while (!(chunksize < 0));
|
|
||||||
infile.close();
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
System.err.println("File creation error! " + e1.getMessage());
|
|
||||||
} catch (IOException e2) {
|
|
||||||
System.err.println("IO error! " + e2.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int DONE = (ABORT | ALLBITS | ERROR | FRAMEBITS);
|
|
||||||
|
|
||||||
int previousInfoFlags = 0;
|
|
||||||
// HEIGHT PROPERTIES SOMEBITS WIDTH
|
|
||||||
public boolean imageUpdate(Image img, int infoflags,
|
|
||||||
int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
if (infoflags != previousInfoFlags) {
|
|
||||||
/* StringBuffer b = new StringBuffer("Flags:");
|
|
||||||
if ((infoflags & ABORT) != 0)
|
|
||||||
b.append(" ABORT");
|
|
||||||
if ((infoflags & ALLBITS) != 0)
|
|
||||||
b.append(" ALLBITS");
|
|
||||||
if ((infoflags & ERROR) != 0)
|
|
||||||
b.append(" ERROR");
|
|
||||||
if ((infoflags & FRAMEBITS) != 0)
|
|
||||||
b.append(" FRAMEBITS");
|
|
||||||
if ((infoflags & HEIGHT) != 0)
|
|
||||||
b.append(" HEIGHT");
|
|
||||||
if ((infoflags & WIDTH) != 0)
|
|
||||||
b.append(" WIDTH");
|
|
||||||
if ((infoflags & PROPERTIES) != 0)
|
|
||||||
b.append(" PROPERTIES");
|
|
||||||
if ((infoflags & SOMEBITS) != 0)
|
|
||||||
b.append(" SOMEBITS");
|
|
||||||
System.err.println(b.toString());
|
|
||||||
*/
|
|
||||||
previousInfoFlags = infoflags;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((infoflags & DONE) != 0) {
|
|
||||||
synchronized (this) {
|
|
||||||
this.complete = true;
|
|
||||||
// new Throwable().printStackTrace(System.err);
|
|
||||||
notify();
|
|
||||||
// System.err.println("Wakeup! " + this.complete + " " + this);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Dimension scaleMaxExtent(int extent, Dimension in)
|
|
||||||
{
|
|
||||||
Dimension original = new Dimension(in);
|
|
||||||
if (extent > 0) {
|
|
||||||
if (original.width > original.height && original.width > extent) {
|
|
||||||
original.height *= extent;
|
|
||||||
original.height /= original.width;
|
|
||||||
original.width = extent;
|
|
||||||
} else if (original.height > extent) {
|
|
||||||
original.width *= extent;
|
|
||||||
original.width /= original.height;
|
|
||||||
original.height = extent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void writeJpegImage(File source, int size, File destination)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
BufferedImage img = ImageIO.read(source);
|
|
||||||
Dimension dim = scaleMaxExtent(size, new Dimension(
|
|
||||||
img.getWidth(), img.getHeight()));
|
|
||||||
|
|
||||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
complete = false;
|
|
||||||
boolean alreadyDone = tk.prepareImage(img, -1, -1, this);
|
|
||||||
complete = complete || alreadyDone;
|
|
||||||
|
|
||||||
// Suspend until the image is rendered completely
|
|
||||||
for (int i = 0; !this.complete && i < 10; ++i)
|
|
||||||
try {
|
|
||||||
// System.err.println("Waiting 1: " + this.complete + " " + this);
|
|
||||||
wait(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedImage buff = new BufferedImage(
|
|
||||||
dim.width, dim.height, BufferedImage.TYPE_INT_RGB);
|
|
||||||
Graphics g = buff.createGraphics();
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
complete = false;
|
|
||||||
|
|
||||||
boolean alreadyDone = g.drawImage(img, 0, 0, dim.width, dim.height, this);
|
|
||||||
|
|
||||||
complete = complete || alreadyDone;
|
|
||||||
|
|
||||||
// Suspend until the image is rendered completely
|
|
||||||
for (int i = 0; !complete && i < 10; ++i)
|
|
||||||
try {
|
|
||||||
// System.err.println("Waiting 2: " + this.complete);
|
|
||||||
wait(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size > 120 || size == 0) {
|
|
||||||
g.setColor(Color.cyan);
|
|
||||||
int lineHeight = g.getFontMetrics().getHeight();
|
|
||||||
int year = Calendar.getInstance().get(Calendar.YEAR);
|
|
||||||
g.drawString("<EFBFBD> " + year + " forkalsrud.org", 5, 5 + lineHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
destination.getParentFile().mkdirs();
|
|
||||||
FileOutputStream out = new FileOutputStream(destination);
|
|
||||||
ImageIO.write(buff, "png", out);
|
|
||||||
out.close();
|
|
||||||
/* System.err.println("OK: " + ok
|
|
||||||
+ " Writers : "
|
|
||||||
+ Arrays.asList(ImageIO.getWriterFormatNames()));
|
|
||||||
*/
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
System.err.println("File creation error! " + e1.getMessage());
|
|
||||||
} catch (IOException e2) {
|
|
||||||
System.err.println("IO error! " + e2.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// eof
|
|
||||||
|
|
@ -1,173 +0,0 @@
|
||||||
package org.forkalsrud.album.web;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.*;
|
|
||||||
|
|
||||||
import javax.imageio.*;
|
|
||||||
|
|
||||||
import javax.servlet.*;
|
|
||||||
import javax.servlet.http.*;
|
|
||||||
|
|
||||||
public class PhotoServlet
|
|
||||||
extends HttpServlet
|
|
||||||
implements ImageObserver
|
|
||||||
{
|
|
||||||
File baseDir = new File("/home/knut");
|
|
||||||
File cacheDir = new File("/var/org.forkalsrud.album");
|
|
||||||
|
|
||||||
final static int BUF_SIZE = 1024;
|
|
||||||
protected volatile boolean complete = false;
|
|
||||||
protected int size;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init()
|
|
||||||
throws ServletException
|
|
||||||
{
|
|
||||||
System.out.println("in init of Bitmap");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
File cacheFile(String filename, int size) {
|
|
||||||
return new File(cacheDir, filename + "-" + size + ".jpeg");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doGet(HttpServletRequest req, HttpServletResponse res)
|
|
||||||
throws ServletException, IOException
|
|
||||||
{
|
|
||||||
res.setContentType("text/plain");
|
|
||||||
|
|
||||||
// Determine which file to show
|
|
||||||
String filename = req.getServletPath();
|
|
||||||
filename = filename.substring(
|
|
||||||
"/".length(),
|
|
||||||
filename.length() - ".photo".length());
|
|
||||||
|
|
||||||
System.out.println("file: " + filename);
|
|
||||||
|
|
||||||
File file = new File(baseDir, filename);
|
|
||||||
if (file == null) {
|
|
||||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.isFile()) {
|
|
||||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.canRead()) {
|
|
||||||
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintWriter out = res.getWriter();
|
|
||||||
|
|
||||||
|
|
||||||
String[] formats = ImageIO.getReaderFormatNames();
|
|
||||||
out.println(Arrays.asList(formats).toString());
|
|
||||||
|
|
||||||
Iterator ii = ImageIO.getImageReadersByFormatName("jpeg");
|
|
||||||
while (ii.hasNext()) {
|
|
||||||
ImageReader ir = (ImageReader)ii.next();
|
|
||||||
|
|
||||||
Class[] inputs = ir.getOriginatingProvider().getInputTypes();
|
|
||||||
out.println(" inputs: " + Arrays.asList(inputs).toString());
|
|
||||||
|
|
||||||
ir.setInput(ImageIO.createImageInputStream(file));
|
|
||||||
|
|
||||||
int cnt = ir.getNumImages(true);
|
|
||||||
|
|
||||||
int thCnt = ir.getNumThumbnails(0);
|
|
||||||
|
|
||||||
out.println("Num images: " + cnt + " thumbnails: " + thCnt);
|
|
||||||
|
|
||||||
// BufferedImage th = ir.readThumbnail(0, 0);
|
|
||||||
|
|
||||||
// out.println(" Thumbnail size: " + th.getWidth() + "x" + th.getWidth());
|
|
||||||
ir.dispose();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
EXIFInfo info = new EXIFInfo(file);
|
|
||||||
Map props = info.getEXIFMetaData();
|
|
||||||
|
|
||||||
Set s = props.entrySet();
|
|
||||||
Iterator i = s.iterator();
|
|
||||||
|
|
||||||
while (i.hasNext()) {
|
|
||||||
Map.Entry e = (Map.Entry)i.next();
|
|
||||||
out.println(e.getKey() + ": " + e.getValue());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int DONE = (ABORT | ALLBITS | ERROR | FRAMEBITS);
|
|
||||||
|
|
||||||
int previousInfoFlags = 0;
|
|
||||||
// HEIGHT PROPERTIES SOMEBITS WIDTH
|
|
||||||
public boolean imageUpdate(Image img, int infoflags,
|
|
||||||
int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
if (infoflags != previousInfoFlags) {
|
|
||||||
/* StringBuffer b = new StringBuffer("Flags:");
|
|
||||||
if ((infoflags & ABORT) != 0)
|
|
||||||
b.append(" ABORT");
|
|
||||||
if ((infoflags & ALLBITS) != 0)
|
|
||||||
b.append(" ALLBITS");
|
|
||||||
if ((infoflags & ERROR) != 0)
|
|
||||||
b.append(" ERROR");
|
|
||||||
if ((infoflags & FRAMEBITS) != 0)
|
|
||||||
b.append(" FRAMEBITS");
|
|
||||||
if ((infoflags & HEIGHT) != 0)
|
|
||||||
b.append(" HEIGHT");
|
|
||||||
if ((infoflags & WIDTH) != 0)
|
|
||||||
b.append(" WIDTH");
|
|
||||||
if ((infoflags & PROPERTIES) != 0)
|
|
||||||
b.append(" PROPERTIES");
|
|
||||||
if ((infoflags & SOMEBITS) != 0)
|
|
||||||
b.append(" SOMEBITS");
|
|
||||||
System.err.println(b.toString());
|
|
||||||
*/
|
|
||||||
previousInfoFlags = infoflags;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((infoflags & DONE) != 0) {
|
|
||||||
synchronized (this) {
|
|
||||||
this.complete = true;
|
|
||||||
// new Throwable().printStackTrace(System.err);
|
|
||||||
notify();
|
|
||||||
// System.err.println("Wakeup! " + this.complete + " " + this);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Dimension scaleMaxExtent(int extent, Dimension in)
|
|
||||||
{
|
|
||||||
Dimension original = new Dimension(in);
|
|
||||||
if (extent > 0) {
|
|
||||||
if (original.width > original.height && original.width > extent) {
|
|
||||||
original.height *= extent;
|
|
||||||
original.height /= original.width;
|
|
||||||
original.width = extent;
|
|
||||||
} else if (original.height > extent) {
|
|
||||||
original.width *= extent;
|
|
||||||
original.width /= original.height;
|
|
||||||
original.height = extent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// eof
|
|
||||||
|
|
@ -5,16 +5,6 @@
|
||||||
<servlet-class>org.forkalsrud.album.web.AlbumServlet</servlet-class>
|
<servlet-class>org.forkalsrud.album.web.AlbumServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>photo</servlet-name>
|
|
||||||
<servlet-class>org.forkalsrud.album.web.PhotoServlet</servlet-class>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>bitmap</servlet-name>
|
|
||||||
<servlet-class>org.forkalsrud.album.web.BitmapServlet</servlet-class>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>velocity</servlet-name>
|
<servlet-name>velocity</servlet-name>
|
||||||
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
|
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue