From df4fe259c98e741a9afd088e380182acd5ec500b Mon Sep 17 00:00:00 2001 From: allo Date: Thu, 18 Jan 2007 14:43:35 +0000 Subject: [PATCH] support for external Thumbnailers. TODO: Mimetype fix TODO: Demo Thumbnailer git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3245 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Thumbnail.html | 1 + htroot/Thumbnail.java | 69 +++++++++++++++++++++++++++++++++++++++++++ yacy.init | 3 ++ 3 files changed, 73 insertions(+) create mode 100644 htroot/Thumbnail.html create mode 100644 htroot/Thumbnail.java diff --git a/htroot/Thumbnail.html b/htroot/Thumbnail.html new file mode 100644 index 000000000..20f06a069 --- /dev/null +++ b/htroot/Thumbnail.html @@ -0,0 +1 @@ +#[image]# \ No newline at end of file diff --git a/htroot/Thumbnail.java b/htroot/Thumbnail.java new file mode 100644 index 000000000..cfc3ea659 --- /dev/null +++ b/htroot/Thumbnail.java @@ -0,0 +1,69 @@ +//Thumbnail.java +//------------ +// part of YACY +// +// (C) 2007 Alexander Schier +// +// last change: $LastChangedDate: $ by $LastChangedBy: $ +// $LastChangedRevision: $ +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +import de.anomic.http.httpHeader; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.plasma.plasmaURL; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; +import de.anomic.server.servletProperties; + +public class Thumbnail{ + public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { + servletProperties prop = new servletProperties(); + String command=env.getConfig("thumbnailProgram", ""); + if(command.equals("")||post==null||!post.containsKey("url")){ + prop.put("image", "thumbnail cannot be generated"); //TODO: put a "thumbnail not possible" image. + return prop; + } + String[] cmdline=new String[3]; + cmdline[0]=env.getConfig("thumbnailProgram", ""); + cmdline[1]=post.get("url", ""); + plasmaSwitchboard sb=plasmaSwitchboard.getSwitchboard(); + File path=new File(sb.workPath, plasmaURL.urlHash(cmdline[1])+".png"); + cmdline[2]=path.getAbsolutePath();//does not contain an extension! + try { + Runtime.getRuntime().exec(cmdline); + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path))); + String line; + StringBuffer image=new StringBuffer(); + while((line=br.readLine())!=null){ + image.append(line); + } + //path.delete(); //we do not cache, yet. + prop.put("image", image.toString()); + } catch (IOException e) { + prop.put("image", "error creating thumbnail");//TODO: put a "thumbnail error" image. + } + httpHeader out_header=new httpHeader(); + out_header.put(httpHeader.CONTENT_TYPE, "image/png"); + prop.setOutgoingHeader(out_header); + return prop; + } +} diff --git a/yacy.init b/yacy.init index b5a7c00ab..64a54278f 100644 --- a/yacy.init +++ b/yacy.init @@ -878,3 +878,6 @@ WikiAccess = admin # If this profile setting is empty, a hard-coded profile from plasmaSearchRanking is used rankingProfile = +#optional extern thumbnail program. +#the program must accept the invocation PROGRAM http://url /path/to/filename +thumbnailProgram =