/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
*
* This file is part of Mir.
*
/**
* Mir.java - main servlet, that dispatches to servletmodules
*
- * @author $Author: zapata $
- * @version $Revision: 1.21 $ $Date: 2002/10/25 03:25:13 $
- *
- * $Log: Mir.java,v $
- * Revision 1.21 2002/10/25 03:25:13 zapata
- * - producer links are moved to an "advanced" page, not intended for normal
- * users. Normal users have only 1 link "generate all new"
- * - used br1's support for log4j at 1 place (ServletModuleDispatch)
- * - misc. small changes/fixes here and there
- *
- * Revision 1.20 2002/10/09 16:09:05 bruno
- * contains only admin templates which should not be changed by users
- *
- * Revision 1.19 2002/09/01 22:05:47 mh
- * Mir goes GPL
- *
- * Revision 1.18 2002/08/25 19:00:06 mh
- * merge of localization branch into HEAD. mh and zap
- *
- * Revision 1.17 2002/07/21 22:27:39 mh
- * make the user error msg look nicer
+ * @author $Author: mh $
+ * @version $Id: Mir.java,v 1.22 2002/11/04 04:35:20 mh Exp $
*
*/
* Base Class of Entities
* Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant
*
- * @version $Revision: 1.9 $ $Date: 2002/09/01 22:05:48 $
- * @author $Author: mh $
- *
- * $Log: Entity.java,v $
- * Revision 1.9 2002/09/01 22:05:48 mh
- * Mir goes GPL
- *
- * Revision 1.8.2.1 2002/09/01 21:31:40 mh
- * Mir goes GPL
- *
- * Revision 1.8 2002/06/28 22:56:37 mh
- * fix so that webdb_lastchange appears in contentlist.template as it should
- *
- * Revision 1.7 2002/06/28 20:35:38 mh
- * use some cvs macros/id's
- *
+ * @version $Id: Entity.java,v 1.10 2002/11/04 04:35:21 mh Exp $
+ * @author rk
*
*/
package mir.media;
import java.util.*;
+import java.io.InputStream;
import freemarker.template.SimpleList;
* all the info for the specific media type itself. It's job is store the
* Media data (content) itself, this could be on the local filesystem, in the
* DB or even on a remote host. It then inserts the MetaData in the DB.
- * @param uploadedData, a byte array containing the uploaded data.
+ * @param InputStream, a stream of the uploaded data.
* @param ent, an Entity holding the media MetaData
* @param mediaType, an Entity holding the media_table entry
* @return boolean, success/fail
* @see mir.entity.Entity
*/
- public abstract boolean set (byte[] uploadedData, Entity ent,
+ public abstract void set (InputStream in, Entity ent,
Entity mediaTypeEnt ) throws MirMediaException;
public abstract void produce (Entity ent, Entity mediaTypeEnt )
throws MirMediaException;
/**
- * Get's the media data from storage and returns it as a byte array
+ * Get's the media data from storage and returns it as an InputStream
* Not very useful for most media types as they are stored in a file,
* but very usefull for ones stored in the DB as it is necessary to get
* it first before making a file out of it (in Producer*).
* @param ent, an Entity holding the media MetaData
* @param mediaType, an Entity holding the media_table entry
- * @return byte[]
+ * @return java.io.InputStream
* @see mir.entity.Entity
*/
- public abstract byte[] get (Entity ent, Entity mediaTypeEnt)
+ public abstract InputStream getMedia (Entity ent, Entity mediaTypeEnt)
throws MirMediaException;
/**
* Pretty much like get() above. But get's the specific Icon
* representation. useful for media stored in the DB.
* @param ent, an Entity holding the media MetaData
- * @return byte[]
+ * @return java.io.InputStream
* @see mir.entity.Entity
*/
- public abstract byte[] getIcon (Entity ent) throws MirMediaException;
+ public abstract InputStream getIcon (Entity ent) throws MirMediaException;
/**
* gets the final content representation for the media
* @return String, the icon filename.
* @see mir.misc.MirConfig
*/
- public abstract String getBigIcon ();
+ public abstract String getBigIconName ();
/**
* Returns the file name of the small Icon representing
* @return String, the icon filename.
* @see mir.misc.MirConfig
*/
- public abstract String getTinyIcon ();
+ public abstract String getTinyIconName ();
/**
* Returns the IMG SRC "ALT" text to be used
* for the Icon representations
* @return String, the ALT text.
*/
- public abstract String getIconAlt ();
+ public abstract String getIconAltName ();
/**
* your can all figure it out.
/*
* MirMediaException -
*
- * @version $Revision: 1.5 $ $Date: 2002/09/01 22:05:49 $
- * @author $Author: mh $
- *
- * $Log: MirMediaException.java,v $
- * Revision 1.5 2002/09/01 22:05:49 mh
- * Mir goes GPL
- *
- * Revision 1.4.2.1 2002/09/01 21:31:40 mh
- * Mir goes GPL
- *
- * Revision 1.4 2002/07/21 22:29:42 mh
- * cvs macros
+ * @version $Id: MirMediaException.java,v 1.6 2002/11/04 04:35:21 mh Exp $
+ * @author mh
*
*/
* differentiates itself from a bug in that it
* represents a probable user error
*
- * @version $Revision: 1.3 $ $Date: 2002/09/01 22:05:49 $
- * @author $Author: mh $
- *
- * $Log: MirMediaUserException.java,v $
- * Revision 1.3 2002/09/01 22:05:49 mh
- * Mir goes GPL
- *
- * Revision 1.2.2.1 2002/09/01 21:31:40 mh
- * Mir goes GPL
- *
- * Revision 1.2 2002/07/21 22:29:42 mh
- * cvs macros
- *
+ * @version $Id: MirMediaUserException.java,v 1.4 2002/11/04 04:35:21 mh Exp $
+ * @author mh
*
*/
--- /dev/null
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries. If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so. If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.misc;
+
+import com.oreilly.servlet.multipart.*;
+import java.util.HashMap;
+
+
+/**
+ * Interface that classes wishing to be used as a callback on FileParts for the
+ * WebdbMultipartRequest class should implement this interface.
+ *
+ * @author mh <mh@nadir.org>
+ * @version $Id: FileHandler.java,v 1.2 2002/11/04 04:35:21 mh Exp $
+ * @see mir.misc.WebdbMultipartRequest
+ *
+ */
+
+public interface FileHandler {
+
+ public void setFile (FilePart filePart, int fileNum, HashMap Params)
+ throws FileHandlerException, FileHandlerUserException;
+
+}
+
+
--- /dev/null
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries. If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so. If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.misc;
+
+import java.lang.*;
+
+/*
+ *
+ * @version $Revision: 1.2 $
+ * @author $Author: mh $
+ *
+ * $Log: FileHandlerException.java,v $
+ * Revision 1.2 2002/11/04 04:35:21 mh
+ * merge media InputStream changes from MIR_1_0 branch
+ *
+ * Revision 1.1.2.1 2002/11/01 05:38:20 mh
+ * Converted media Interface to use streams (Java IO) instead of byte buffers of
+ * the entire uplaoded files. These saves loads of unecessary memory use. JAI
+ * still consumes quite a bit though.
+ *
+ * A new temporary file (for JAI) parameter is necessary and is in the config.properties file.
+ *
+ * A nice side effect of this work is the FileHandler interface which is
+ * basically a call back mechanism for WebdbMultipartRequest which allows the
+ * uploaded file to handled by different classes. For example, for a media
+ * upload, the content-type, etc.. needs to be determined, but if say the
+ * FileEditor had a feature to upload static files... another handler wood be
+ * needed. Right now only the MediaRequest handler exists.
+ *
+ *
+ */
+
+public final class FileHandlerException extends Exception {
+ String msg;
+
+ public FileHandlerException(String msg) {
+ super(msg);
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries. If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so. If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.misc;
+
+import java.lang.*;
+
+/*
+ * differentiates itself from a bug in that it
+ * represents a probable user error
+ *
+ * @version $Revision: 1.2 $
+ * @author $Author: mh $
+ *
+ * $Log: FileHandlerUserException.java,v $
+ * Revision 1.2 2002/11/04 04:35:21 mh
+ * merge media InputStream changes from MIR_1_0 branch
+ *
+ * Revision 1.1.2.1 2002/11/01 05:38:20 mh
+ * Converted media Interface to use streams (Java IO) instead of byte buffers of
+ * the entire uplaoded files. These saves loads of unecessary memory use. JAI
+ * still consumes quite a bit though.
+ *
+ * A new temporary file (for JAI) parameter is necessary and is in the config.properties file.
+ *
+ * A nice side effect of this work is the FileHandler interface which is
+ * basically a call back mechanism for WebdbMultipartRequest which allows the
+ * uploaded file to handled by different classes. For example, for a media
+ * upload, the content-type, etc.. needs to be determined, but if say the
+ * FileEditor had a feature to upload static files... another handler wood be
+ * needed. Right now only the MediaRequest handler exists.
+ *
+ *
+ */
+
+public final class FileHandlerUserException extends Exception {
+ String msg;
+
+ public FileHandlerUserException(String msg) {
+ super(msg);
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+}
+
private FileUtil () {
}
- public static boolean write(String filename, byte[] in)
+ public static File getFile(String filename)
throws IOException {
- boolean retVal = false;
+ try {
+ File f = null;
+ f = new File(filename);
+ File dir = new File(f.getParent());
+ dir.mkdirs();
+
+ return f;
+ } catch(Exception e) {
+ throw new IOException(e.toString());
+ }
+
+ }
+
+ public static long write(File f, InputStream in)
+ throws IOException {
+
+ long size = 0;
+
+ if (in!=null) {
+ try {
+ FileOutputStream out = new FileOutputStream(f);
+
+ int read;
+ byte[] buf = new byte[8 * 1024];
+ while((read = in.read(buf)) != -1) {
+ out.write(buf, 0, read);
+ size += read;
+ }
+
+ in.close();
+ out.close();
+ } catch(IOException e) {
+ throw new IOException(e.toString());
+ }
+ }
+ return size;
+ }
+
+ public static long write(String filename, InputStream in)
+ throws IOException {
+
+ long size = 0;
+
+ if (in!=null) {
+ try {
+ File f = getFile(filename);
+ size = write(f, in);
+ } catch(IOException e) {
+ throw new IOException(e.toString());
+ }
+ }
+ return size;
+ }
+
+ public static long write(String filename, Reader in, String encoding)
+ throws IOException {
+
+ long size = 0;
if (in!=null) {
try {
- File f = null;
- f = new File(filename);
- File dir = new File(f.getParent());
- dir.mkdirs();
-
- FileOutputStream outStream;
- outStream = new FileOutputStream(f);
- outStream.write(in);
- outStream.close();
- retVal = true;
+ File f = getFile(filename);
+ FileOutputStream fOut = new FileOutputStream(f);
+ OutputStreamWriter out = new OutputStreamWriter(fOut, encoding);
+ int read;
+ char[] cbuf = new char[8*1024];
+ while((read = in.read(cbuf)) != -1) {
+ out.write(cbuf, 0, read);
+ size += read;
+ }
+
+ out.close();
+ in.close();
} catch(IOException e) {
throw new IOException(e.toString());
}
}
- return retVal;
+ return size;
}
public static boolean read(String filename, byte out[])
/**
* Statische Hilfsmethoden zur Stringbehandlung
*
- * @version $Revision: 1.25 $ $Date: 2002/09/14 03:32:12 $
- * @author $Author: zapata $
- *
- * $Log: StringUtil.java,v $
- * Revision 1.25 2002/09/14 03:32:12 zapata
- * fixed a small email address filtering bug
- *
- * Revision 1.24 2002/09/01 22:05:50 mh
- * Mir goes GPL
- *
- * Revision 1.23.2.1 2002/09/01 21:31:40 mh
- * Mir goes GPL
- *
- * Revision 1.23 2002/06/28 20:39:37 mh
- * added numberformat helper. make webdbDate2readableDate use webdb_create instead. make the order and appearance of it more consistent. cvs macros. and finally code tidying
- *
+ * @version $Id: StringUtil.java,v 1.26 2002/11/04 04:35:21 mh Exp $
+ * @author mir-coders group
*
*/
public final class StringUtil {
/**
* Title:
* Description:
- * Copyright: Copyright (c) 2001
- * Company: Indymedia
- * @author
- * @version 1.0
+ * Copyright: Copyright (c) 2002 Mir-coders
+ * @author $Author: mh $
+ * @version $Id: WebdbImage.java,v 1.8 2002/11/04 04:35:21 mh Exp $
*/
import java.io.*;
import java.util.Vector;
+import java.util.Random;
import javax.media.jai.*;
import com.sun.media.jai.codec.*;
import java.awt.image.renderable.ParameterBlock;
private int maxIconSize=120;
private int maxImageSize=640;
- private byte[] iconData;
- private byte[] imageData;
private int iconWidth;
private int iconHeight;
+ Random r = new Random();
+
// internal representation of the image
private PlanarImage planarImage;
// constructor
- public WebdbImage(byte[] image, String type)
- throws IOException
- {
- planarImage = JAI.create("stream",new ByteArraySeekableStream(image));
- _type = type;
- scaleImage();
- }
-
- public WebdbImage(byte[] image, String type, int iconMax)
- throws IOException
- {
- maxIconSize=iconMax;
- planarImage = JAI.create("stream",new ByteArraySeekableStream(image));
- _type = type;
- scaleImage();
- }
-
- public WebdbImage(byte[] image, String type, int iconMax, int imageMax)
+ // takes a temporary file as a parameter
+ public WebdbImage(File f, String type)
throws IOException
{
- maxIconSize=iconMax;
- maxImageSize=imageMax;
- planarImage = JAI.create("stream",new ByteArraySeekableStream(image));
+ // It has to be a FileSeekableStream cause the image conversion
+ // needs to seek backwards.
+ planarImage = JAI.create("stream",new FileSeekableStream(f));
_type = type;
scaleImage();
}
// acc3ssor-methods
+ // must be run after scaleIcon()
public int getIconWidth() throws IOException {
- if (iconData==null) scaleIcon();
return iconWidth;
}
+ // must be run after scaleIcon()
public int getIconHeight() throws IOException {
- if (iconData==null) scaleIcon();
return iconHeight;
}
return (int)planarImage.getHeight();
}
- public byte[] getImage() {
- if (imageData==null) {
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- JAI.create("encode", planarImage, outStream, _type, null);
- imageData = outStream.toByteArray();
- }
- return imageData;
+ public void setImage(OutputStream outStream) {
+ JAI.create("encode", planarImage, outStream, _type, null);
}
- public byte[] getIcon()
+ public void setIcon(OutputStream outStream)
throws IOException
{
- if (iconData == null) scaleIcon();
- return iconData;
+ scaleIcon(outStream);
}
private void scaleImage()
{
if (maxImageSize>0 && ( getImageHeight()> maxImageSize|| getImageWidth() >maxImageSize))
{
- System.out.println("SCALE_IMAGE");
float scale;
ParameterBlockJAI params = new ParameterBlockJAI("scale");
params.addSource(planarImage);
}
}
- private void scaleIcon()
+ private void scaleIcon(OutputStream outStream)
throws java.io.IOException
{
- System.out.println("SCALE_ICON");
- if (iconData==null) {
- float scale;
- ParameterBlockJAI params = new ParameterBlockJAI("scale");
- params.addSource(planarImage);
- if (getImageHeight() > getImageWidth())
- scale = (float)maxIconSize / (float)getImageHeight();
- else
- scale = (float)maxIconSize / (float)getImageWidth();
-
- params.setParameter("xScale", scale);
- params.setParameter("yScale", scale);
- params.setParameter("xTrans",0.0F);
- params.setParameter("yTrans",0.0F);
- params.setParameter("interpolation",new InterpolationBilinear());
- PlanarImage temp = JAI.create("scale", params);
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- JAI.create("encode", temp, outStream, _type, null);
- iconData = outStream.toByteArray();
- iconWidth=temp.getWidth();
- iconHeight=temp.getHeight();
- }
+ float scale;
+ ParameterBlockJAI params = new ParameterBlockJAI("scale");
+ params.addSource(planarImage);
+ if (getImageHeight() > getImageWidth())
+ scale = (float)maxIconSize / (float)getImageHeight();
+ else
+ scale = (float)maxIconSize / (float)getImageWidth();
+
+ params.setParameter("xScale", scale);
+ params.setParameter("yScale", scale);
+ params.setParameter("xTrans",0.0F);
+ params.setParameter("yTrans",0.0F);
+ params.setParameter("interpolation",new InterpolationBilinear());
+ PlanarImage temp = JAI.create("scale", params);
+ JAI.create("encode", temp, outStream, _type, null);
+ iconWidth=temp.getWidth();
+ iconHeight=temp.getHeight();
}
}
HttpServletRequest req=null;
Hashtable parameters = new Hashtable();
MultipartParser mp=null;
- public static ArrayList requestList;
+ FileHandler _fHandler;
- public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException
+ public WebdbMultipartRequest(HttpServletRequest theReq, FileHandler handler)
+ throws FileHandlerException, FileHandlerUserException, IOException
{
req=theReq;
int maxSize = Integer.parseInt(MirConfig.getProp("MaxMediaUploadSize"));
mp = new MultipartParser(req, 1024*maxSize);
- requestList = new ArrayList();
+ _fHandler = handler;
_evaluateRequest();
}
}
}
- private void _evaluateRequest() throws IOException{
+ private void _evaluateRequest() throws FileHandlerException,
+ FileHandlerUserException, IOException {
Part part;
- int i = 0;
+ int i = 1;
while ((part = mp.readNextPart()) != null) {
String name = part.getName();
if (part.isParam()) {
FilePart filePart = (FilePart) part;
String fn = filePart.getFileName();
if (filePart.getFileName() != null) {
- ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- filePart.writeTo(byteStream);
- requestList.add(i,new MpRequest(byteStream.toByteArray(),filePart.getFileName(),filePart.getContentType()));
+ if (_fHandler != null)
+ _fHandler.setFile(filePart, i, getParameters());
i++;
}
}
* Treiber, Host, User und Passwort, ueber den der Zugriff auf die
* Datenbank erfolgt.
*
- * @version $Revision: 1.23 $ $Date: 2002/09/01 22:05:52 $
- * @author $Author: mh $
- *
- * $Log: Database.java,v $
- * Revision 1.23 2002/09/01 22:05:52 mh
- * Mir goes GPL
- *
- * Revision 1.22 2002/08/25 19:00:09 mh
- * merge of localization branch into HEAD. mh and zap
- *
- * Revision 1.21 2002/08/04 23:38:22 mh
- * fix up the webdb_create update stuff
- *
- * Revision 1.20 2002/07/21 22:32:25 mh
- * on insert, the "webdb_lastchange" field should get a value
- *
- * Revision 1.19 2002/06/29 15:44:46 mh
- * make the webdb_create update be called webdb_create_update. it breaks things otherwise. a fixme case I know..
- *
- * Revision 1.18 2002/06/28 20:42:13 mh
- * added necessary bits in templates and Database.java to make webdb_create modifiable. make the conversion from sql/Timestamp to String more robust
- *
+ * @version $Id: Database.java,v 1.24 2002/11/04 04:35:21 mh Exp $
+ * @author rk
*
*/
public class Database implements StorageObject {
* This class handles storage of audio data and meta data
*
* @author mh
- * @version 11.11.2000
+ * @version $Id: EntityAudio.java,v 1.4 2002/11/04 04:35:21 mh Exp $
*/
setStorage(theStorage);
}
- //
- // methods
-
-
-
- public byte[] getAudio() throws StorageObjectException
- {
- theLog.printDebugInfo("--getaudio started");
- java.sql.Connection con=null;Statement stmt=null;
- byte[] data=null;
-
- try {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- LargeObjectManager lom;
- java.sql.Connection jCon;
- stmt = con.createStatement();
- ResultSet rs = theStorageObject.executeSql(stmt,
- "select audio_data from audio where id="+getId());
- jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
- .getNativeConnection();
- lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
- if(rs!=null) {
- if (rs.next()) {
- LargeObject lob = lom.open(rs.getInt(1));
- data = lob.read(lob.size());
- lob.close();
- //data = rs.getBytes(1);
- }
- rs.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printError("EntityAudio -- getAudio failed"+e.toString());
- throwStorageObjectException(e, "EntityAudio -- getAudio failed: ");
- }
- finally {
- try {
- con.setAutoCommit(true);
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printError(
- "EntityAudio -- getAudio reseting transaction mode failed"
- +e.toString());
- }
- theStorageObject.freeConnection(con,stmt);
- }
-
- return data;
- }
-
- public void setAudio(byte[] uploadData)
- throws StorageObjectException {
-
- if (uploadData!=null) {
- java.sql.Connection con=null;PreparedStatement pstmt=null;
- try {
-
- if (uploadData!=null) {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- theLog.printDebugInfo("setaudio :: trying to insert audio");
-
- // setting values
- LargeObjectManager lom;
- java.sql.Connection jCon;
- jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
- .getNativeConnection();
- lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
- int oid = lom.create();
- LargeObject lob = lom.open(oid);
- lob.write(uploadData);
- lob.close();
- String sql = "update images set"
- +" audio_data="+oid
- +" where id="+getId();
- theLog.printDebugInfo("setaudio :: updating: "+ sql);
- pstmt = con.prepareStatement(sql);
- //pstmt.setBytes(1, imageData);
- //pstmt.setBytes(2, iconData);
- pstmt.executeUpdate();
- sql="update content set is_produced='0' where to_media="+getId();
- pstmt = con.prepareStatement(sql);
- pstmt.executeUpdate();
- }
- }
- catch (Exception e) {
- throwStorageObjectException(e,"setaudio ::failed: ");
- }
- finally {
- try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,pstmt); }
- }
- }
-
-
public void update() throws StorageObjectException {
super.update();
try {
* this class implements mapping of one line of the database table content
* to a java object
*
- * @version $Revision: 1.10 $ $Date: 2002/09/01 22:05:53 $
- * @author $Author: mh $
+ * @version $Id: EntityContent.java,v 1.11 2002/11/04 04:35:21 mh Exp $
+ * @author mir-coders group
*
- * $Log: EntityContent.java,v $
- * Revision 1.10 2002/09/01 22:05:53 mh
- * Mir goes GPL
- *
- * Revision 1.9.2.1 2002/09/01 21:31:43 mh
- * Mir goes GPL
- *
- * Revision 1.9 2002/07/19 20:55:49 mh
- * commented out decodeHTML, as we don't encodeHTML anymore
- *
- * Revision 1.8 2002/06/28 20:37:33 mh
- * make date_formatted be webdb_create_short instead to be more consistent. also make date2webdb.. use webdb_create
- *
- *
*/
tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio");
iconAlt = "Audio";
} else if (tinyIcon == null && !mediaHandler.isImage()) {
- tinyIcon = mediaHandler.getTinyIcon();
- iconAlt = mediaHandler.getIconAlt();
+ tinyIcon = mediaHandler.getTinyIconName();
+ iconAlt = mediaHandler.getIconAltName();
}
}
import org.postgresql.Connection;
import org.postgresql.largeobject.LargeObject;
import org.postgresql.largeobject.LargeObjectManager;
+import org.postgresql.largeobject.BlobInputStream;
import mir.entity.*;
import mir.misc.*;
/**
* Diese Klasse enthält die Daten eines MetaObjekts
*
- * @author RK
- * @version 11.11.2000
+ * @author RK, mh
+ * @version $Id: EntityImages.java,v 1.8 2002/11/04 04:35:21 mh Exp $
*/
public class EntityImages extends EntityUploadedMedia
{
+
+ Random r = new Random();
+
public EntityImages()
{
super();
// methods
-
- public byte[] getImage() throws StorageObjectException
+ public InputStream getImage() throws StorageObjectException
{
theLog.printDebugInfo("--getimage started");
java.sql.Connection con=null;Statement stmt=null;
- byte[] img_data=null;
+ BlobInputStream in; InputStream img_in = null;
try {
con = theStorageObject.getPooledCon();
con.setAutoCommit(false);
LargeObjectManager lom;
- java.sql.Connection jCon;
- stmt = con.createStatement();
+ java.sql.Connection jCon;
+ stmt = con.createStatement();
ResultSet rs = theStorageObject.executeSql(stmt,
"select image_data from images where id="+getId());
- jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
- .getNativeConnection();
- lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
+ jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
+ .getNativeConnection();
+ lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
if(rs!=null) {
- if (rs.next()) {
- LargeObject lob = lom.open(rs.getInt(1));
- img_data = lob.read(lob.size());
- lob.close();
- //img_data = rs.getBytes(1);
- }
- rs.close();
+ if (rs.next()) {
+ LargeObject lob = lom.open(rs.getInt(1));
+ in = (BlobInputStream)lob.getInputStream();
+ img_in = new ImageInputStream(in, con, stmt);
+ }
+ rs.close();
}
} catch (Exception e) {
- e.printStackTrace();
- theLog.printError("EntityImages -- getImage failed"+e.toString());
- throwStorageObjectException(e, "EntityImages -- getImage failed: ");
- }
- finally {
- try {
- con.setAutoCommit(true);
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printError(
- "EntityImages -- getImage reseting transaction mode failed"
- +e.toString());
- }
- theStorageObject.freeConnection(con,stmt);
- }
-
- return img_data;
+ e.printStackTrace();
+ theLog.printError("EntityImages -- getImage failed"+e.toString());
+ throwStorageObjectException(e, "EntityImages -- getImage failed: ");
+ try {
+ con.setAutoCommit(true);
+ } catch (Exception e2) {
+ e.printStackTrace();
+ theLog.printError(
+ "EntityImages -- getImage reseting transaction mode failed"
+ +e2.toString());
+ }
+ theStorageObject.freeConnection(con,stmt);
+ }
+ //}
+ return img_in;
}
- public void setImage(byte[] uploadData, String type)
+ public void setImage(InputStream in, String type)
throws StorageObjectException {
- if (uploadData!=null) {
+ if (in!=null) {
java.sql.Connection con=null;PreparedStatement pstmt=null;
+ File f = null;
try {
theLog.printDebugInfo("settimage :: making internal representation of image");
- WebdbImage webdbImage= new WebdbImage(uploadData, type);
+
+ String fName = MirConfig.getProp("TempDir")+File.separator+r.nextInt();
+ f = new File(fName);
+ FileUtil.write(f, in);
+ WebdbImage webdbImage= new WebdbImage(f, type);
theLog.printDebugInfo("settimage :: made internal representation of image");
- byte[] imageData = webdbImage.getImage();
- theLog.printDebugInfo("settimage :: getImage");
- byte[] iconData = webdbImage.getIcon();
- theLog.printDebugInfo("settimage :: getIcon");
-
-
- if (iconData!=null && imageData!=null) {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- theLog.printDebugInfo("settimage :: trying to insert image");
-
- // setting values
- LargeObjectManager lom;
- java.sql.Connection jCon;
- jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
- .getNativeConnection();
- lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
- int oidImage = lom.create();
- int oidIcon = lom.create();
- LargeObject lobImage = lom.open(oidImage);
- LargeObject lobIcon = lom.open(oidIcon);
- lobImage.write(imageData);
- lobIcon.write(iconData);
- lobImage.close();
- lobIcon.close();
- String sql = "update images set img_height='"
- +webdbImage.getImageHeight() +
- "',img_width='" + webdbImage.getImageWidth() +
- "',icon_height='" + webdbImage.getIconHeight() +
- "',icon_width='" + webdbImage.getIconWidth()
- + "', image_data="+oidImage+", icon_data="+oidIcon
- +" where id="+getId();
- theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
- pstmt = con.prepareStatement(sql);
- //pstmt.setBytes(1, imageData);
- //pstmt.setBytes(2, iconData);
- pstmt.executeUpdate();
- sql="update content set is_produced='0' where to_media="+getId();
- pstmt = con.prepareStatement(sql);
- pstmt.executeUpdate();
- }
+
+ con = theStorageObject.getPooledCon();
+ con.setAutoCommit(false);
+ theLog.printDebugInfo("settimage :: trying to insert image");
+
+ // setting values
+ LargeObjectManager lom;
+ java.sql.Connection jCon;
+ jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
+ .getNativeConnection();
+ lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
+ int oidImage = lom.create();
+ int oidIcon = lom.create();
+ LargeObject lobImage = lom.open(oidImage);
+ LargeObject lobIcon = lom.open(oidIcon);
+ webdbImage.setImage(lobImage.getOutputStream());
+ webdbImage.setIcon(lobIcon.getOutputStream());
+ lobImage.close();
+ lobIcon.close();
+ String sql = "update images set img_height='"
+ +webdbImage.getImageHeight() +
+ "',img_width='" + webdbImage.getImageWidth() +
+ "',icon_height='" + webdbImage.getIconHeight() +
+ "',icon_width='" + webdbImage.getIconWidth()
+ + "', image_data="+oidImage+", icon_data="+oidIcon
+ +" where id="+getId();
+ theLog.printDebugInfo("settimage :: updating sizes: "+ sql);
+ pstmt = con.prepareStatement(sql);
+ //pstmt.setBytes(1, imageData);
+ //pstmt.setBytes(2, iconData);
+ pstmt.executeUpdate();
+ sql="update content set is_produced='0' where to_media="+getId();
+ pstmt = con.prepareStatement(sql);
+ pstmt.executeUpdate();
}
catch (Exception e) {throwStorageObjectException(e, "settimage :: setImage gescheitert: ");}
finally {
- try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,pstmt); }
+ try {
+ if (con!=null)
+ con.setAutoCommit(true);
+ // get rid of the temp. file
+ f.delete();
+ } catch (Exception e) {;}
+ theStorageObject.freeConnection(con,pstmt);
+ }
}
}
super.setValues(theStringValues);
}
- public byte[] getIcon() throws StorageObjectException
+ /**
+ * Takes an OutputStream as an argument and reads in the data
+ * from the DB and writes it to the OutputStream.
+ *
+ * It will also take care of closing the OutputStream.
+ */
+ public InputStream getIcon() throws StorageObjectException
{
java.sql.Connection con=null;Statement stmt=null;
- byte[] img_data=null;
+ BlobInputStream in=null;ImageInputStream img_in=null;
try {
con = theStorageObject.getPooledCon();
con.setAutoCommit(false);
- LargeObjectManager lom;
- java.sql.Connection jCon;
+ LargeObjectManager lom;
+ java.sql.Connection jCon;
stmt = con.createStatement();
ResultSet rs = theStorageObject.executeSql(stmt,
"select icon_data from images where id="+getId());
- jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
+ jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
.getNativeConnection();
- lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
+ lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
if(rs!=null) {
if (rs.next()) {
- LargeObject lob = lom.open(rs.getInt(1));
- img_data = lob.read(lob.size());
- lob.close();
- //img_data = rs.getBytes(1);
+ LargeObject lob = lom.open(rs.getInt(1));
+ in = (BlobInputStream)lob.getInputStream();
+ img_in = new ImageInputStream( in, con ,stmt);
+ //img_data = rs.getBytes(1);
}
- rs.close();
+ rs.close();
}
} catch (Exception e) {
- e.printStackTrace();
- theLog.printError("EntityImages -- getIcon failed"+e.toString());
- throwStorageObjectException(e, "EntityImages -- getIcon failed:");
- } finally {
- try {
- con.setAutoCommit(true);
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printError(
- "EntityImages -- getIcon reseting transaction mode failed"
- +e.toString());
- }
- theStorageObject.freeConnection(con,stmt);
- }
-
- return img_data;
+ e.printStackTrace();
+ theLog.printError("EntityImages -- getIcon failed"+e.toString());
+ throwStorageObjectException(e, "EntityImages -- getIcon failed:");
+ try {
+ con.setAutoCommit(true);
+ } catch (Exception e2) {
+ e.printStackTrace();
+ theLog.printError(
+ "EntityImages -- getIcon reseting transaction mode failed"
+ +e2.toString());
+ }
+ theStorageObject.freeConnection(con,stmt);
+ }
+
+ return img_in;
}
+ /**
+ * a small wrapper class that allows us to store the DB connection resources
+ * that the BlobInputStream is using and free them upon closing of the stream
+ */
+ private class ImageInputStream extends InputStream {
+
+ InputStream _in;
+ java.sql.Connection _con;
+ Statement _stmt;
+
+ public ImageInputStream(BlobInputStream in, java.sql.Connection con,
+ Statement stmt )
+ {
+ _in = in;
+ _con = con;
+ _stmt = stmt;
+ }
+
+ public void close () throws IOException {
+ _in.close();
+
+ try {
+ _con.setAutoCommit(true);
+ theStorageObject.freeConnection(_con,_stmt);
+ } catch (Exception e) {
+ throw new IOException("close(): "+e.toString());
+ }
+ }
+
+ public int read() throws IOException {
+ return _in.read();
+ }
+
+ }
+
}
setStorage(theStorage);
}
- //
- // methods
-
-
-
- public byte[] getOther() throws StorageObjectException
- {
- theLog.printDebugInfo("--getother started");
- java.sql.Connection con=null;Statement stmt=null;
- byte[] img_data=null;
-
- try {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- LargeObjectManager lom;
- java.sql.Connection jCon;
- stmt = con.createStatement();
- ResultSet rs = theStorageObject.executeSql(stmt,
- "select other_data from other where id="+getId());
- jCon = ((com.codestudio.sql.PoolManConnectionHandle)con)
- .getNativeConnection();
- lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI();
- if(rs!=null) {
- if (rs.next()) {
- LargeObject lob = lom.open(rs.getInt(1));
- img_data = lob.read(lob.size());
- lob.close();
- //img_data = rs.getBytes(1);
- }
- rs.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printError("EntityOther -- getOther failed"+e.toString());
- throwStorageObjectException(e, "EntityOther -- getOther failed: ");
- }
- finally {
- try {
- con.setAutoCommit(true);
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printError(
- "EntityOther -- getOther reseting transaction mode failed"
- +e.toString());
- }
- theStorageObject.freeConnection(con,stmt);
- }
-
- return img_data;
- }
-
- public void setOther(byte[] otherData, String otherType)
- throws StorageObjectException {
-
- if (otherData!=null) {
- java.sql.Connection con=null;PreparedStatement pstmt=null;
- try {
-
- theLog.printDebugInfo("settother :: making internal representation of other");
- theLog.printDebugInfo("settother :: made internal representation of other");
- theLog.printDebugInfo("settother :: getOther");
-
- if ( otherData!=null) {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- theLog.printDebugInfo("settother :: trying to insert other");
-
- // setting values
- pstmt.setBytes(1, otherData);
- String sql="update content set is_produced='0' where to_media="+getId();
- pstmt = con.prepareStatement(sql);
- pstmt.executeUpdate();
- }
- }
- catch (Exception e) {throwStorageObjectException(e, "settother :: setOther gescheitert: ");}
- finally {
- try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,pstmt); }
- }
- }
-
public void update() throws StorageObjectException {
super.update();
try {
if (key != null) {
if (key.equals("big_icon"))
- returnValue = getBigIcon();
+ returnValue = getBigIconName();
else if (key.equals("descr"))
returnValue = getDescr();
else if (key.equals("mediatype"))
return null;
}
- private String getBigIcon() {
+ private String getBigIconName() {
MirMedia mediaHandler = null;
Entity mediaType = null;
try {
mediaType = getMediaType();
mediaHandler = MediaHelper.getHandler(mediaType);
- return mediaHandler.getBigIcon();
+ return mediaHandler.getBigIconName();
}
catch (Exception ex) {
- theLog.printWarning("-- getBigIcon: could not fetch data "
+ theLog.printWarning("-- getBigIconName: could not fetch data "
+ this.getClass().toString() + " " + ex.toString());
}
return null;
return mediaType.getValue("mime_type");
}
catch (Exception ex) {
- theLog.printWarning("-- getBigIcon: could not fetch data "
+ theLog.printWarning("-- getBigIconName: could not fetch data "
+ this.getClass().toString() + " " + ex.toString());
}
return null;
//
// methods
- public byte[] getVideoData() throws StorageObjectException
- {
-
- Connection con=null;Statement stmt=null;
- byte[] video_data=null;
-
- try {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- stmt = con.createStatement();
- ResultSet rs = theStorageObject.executeSql(stmt,"select video_data from video where id="+getId());
- if(rs!=null) {
- if (rs.next()) {
- video_data = rs.getBytes(1);
- }
- rs.close();
- }
- }
- catch (Exception e) {theLog.printDebugInfo("-- getImage gescheitert: "+e.toString());}
- finally {
- try {con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,stmt); }
-
- return video_data;
- }
-
- public void setVideoData(byte[] uploadData) throws StorageObjectException
- {
- if (uploadData!=null) {
- Connection con=null;PreparedStatement pstmt=null;
- try {
-
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- theLog.printDebugInfo("setvideo :: trying to insert video");
-
- // setting values
- String sql = "update videos set image_data=? where id="+getId();
- theLog.printDebugInfo("setvideo: "+ sql);
- pstmt = con.prepareStatement(sql);
- pstmt.setBytes(1, uploadData);
- pstmt.executeUpdate();
- sql="update content set is_produced='0' where to_media="+getId();
- pstmt = con.prepareStatement(sql);
- pstmt.executeUpdate();
- }
- catch (Exception e) {theLog.printDebugInfo("setvideo :: setvideo gescheitert: "+e.toString());}
- finally {
- try {con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,pstmt); }
- }
- }
-
public void update() throws StorageObjectException {
super.update();
try {
iconAlt = "Image";\r
}\r
else {\r
- tinyIcon = mediaHandler.getTinyIcon();\r
- iconAlt = mediaHandler.getIconAlt();\r
+ tinyIcon = mediaHandler.getTinyIconName();\r
+ iconAlt = mediaHandler.getIconAltName();\r
}\r
\r
}\r
}\r
}\r
}\r
-}
\ No newline at end of file
+}\r
return tinyIcon;
}
- public String getBigIcon()
+ public String getBigIconName()
{
return bigIcon;
}
* Of course it implements the MirMedia interface.
*
* @see mir.media.MirMedia
- * @author mh <heckmann@hbe.ca>
- * @version 24.09.2001
+ * @author mh <mh@nadir.org>
+ * @version $Id: MediaHandlerGeneric.java,v 1.10 2002/11/04 04:35:22 mh Exp $
*/
public class MediaHandlerGeneric implements MirMedia
{
protected static String imageHost = MirConfig.getProp("Producer.Image.Host");
protected static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
- protected static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
+ protected static Logfile theLog = Logfile.getInstance(
+ MirConfig.getProp("Home")+
"log/media.log");
- public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt )
+ private final String sepChar = File.separator;
+
+ public void set (InputStream in, Entity ent, Entity mediaTypeEnt )
throws MirMediaException {
String ext = mediaTypeEnt.getValue("name");
String mediaFname = ent.getId()+"."+ext;
String date = ent.getValue("date");
String datePath = StringUtil.webdbDate2path(date);
- Integer size = new Integer(uploadedData.length);
try {
- FileUtil.write(getStoragePath()+"/"+datePath+"/"+mediaFname,
- uploadedData);
- //were done with the data, dereference.
- uploadedData=null;
-
- ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
- ent.setValueForProperty("size", size.toString());
+ long size = FileUtil.write(getStoragePath()+sepChar+datePath+
+ sepChar+mediaFname, in);
+ ent.setValueForProperty("publish_path",datePath+sepChar+mediaFname);
+ ent.setValueForProperty("size", new Long(size).toString());
ent.update();
} catch (Exception e) {
theLog.printError(e.toString());
throw new MirMediaException(e.toString());
}
- return true;
}
public void produce (Entity ent, Entity mediaTypeEnt )
" does not exist!");
}
-
- //a method that will probably never get used..
- private byte[] getFile (String fileName)
- throws MirMediaException {
-
- long size = FileUtil.getSize(fileName);
- if (size < 0) return null;
-
- byte[] container = new byte[(int)size];
-
- try {
- FileUtil.read(fileName, container);
- } catch (Exception e) {
- theLog.printError(e.toString());
- throw new MirMediaException(e.toString());
- }
-
- return container;
- }
-
- public byte[] get (Entity ent, Entity mediaTypeEnt) {
- return null;
- }
-
- public byte[] getIcon (Entity ent) {
+ public InputStream getMedia (Entity ent, Entity mediaTypeEnt)
+ throws MirMediaException {
+ String publishPath = mediaTypeEnt.getValue("publish_path");
+ String fname = getStoragePath()+publishPath;
+ File f = new File(fname);
+ if(! f.exists())
+ throw new MirMediaException("error in MirMedia.getMedia(): "+fname+
+ "does not exist!");
+ FileInputStream in;
+ try {
+ in = new FileInputStream(f);
+ } catch (IOException e) {
+ throw new MirMediaException("getMedia(): "+e.toString());
+ }
+ return in;
+ }
+
+ public InputStream getIcon (Entity ent) {
return null;
}
return MirConfig.getProp("Producer.Media.Host");
}
- public String getTinyIcon()
+ public String getTinyIconName()
{
return MirConfig.getProp("Producer.Icon.TinyText");
}
- public String getBigIcon()
+ public String getBigIconName()
{
return MirConfig.getProp("Producer.Icon.BigText");
}
- public String getIconAlt()
+ public String getIconAltName()
{
return "Generic media";
}
*
* @see mir.media.MirMedia
* @author mh
- * @version 24.09.2001
+ * @version $Date: 2002/11/04 04:35:22 $ $Revision: 1.11 $
*/
abstract String getType();
- public byte[] get(Entity ent, Entity mediaTypeEnt)
+ public InputStream getMedia(Entity ent, Entity mediaTypeEnt)
throws MirMediaException
{
- byte[] image_data = null;
-
+ InputStream in;
try {
- image_data = ((EntityImages)ent).getImage();
+ in = ((EntityImages)ent).getImage();
} catch ( StorageObjectException e) {
- theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString());
+ theLog.printDebugInfo("MediaHandlerImages.getImage: "+e.toString());
throw new MirMediaException(e.toString());
}
- return image_data;
+ return in;
}
- public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
+ public void set(InputStream in, Entity ent, Entity mediaTypeEnt)
throws MirMediaException {
try {
- ((EntityImages)ent).setImage(uploadData, getType());
+ ((EntityImages)ent).setImage(in, getType());
} catch ( StorageObjectException e) {
theLog.printError("MediaHandlerImages.set: "+e.toString());
throw new MirMediaException(e.toString());
}
- //deref. -mh
- uploadData=null;
- return true;
}
public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException
String filepath = datePath+ent.getId()+ext;
String iconFilePath = MirConfig.getProp("Producer.StorageRoot")
+getIconStoragePath() + filepath;
- String productionFilePath = getStoragePath() + "/" + filepath;
+ String productionFilePath = getStoragePath() + File.separator + filepath;
if (ent.getValue("icon_data")!= null &&
ent.getValue("image_data")!= null) {
// make icon
try {
- FileUtil.write(iconFilePath,((EntityImages)ent).getIcon());
- FileUtil.write(productionFilePath,((EntityImages)ent).getImage());
+ InputStream in = ((EntityImages)ent).getIcon();
+ FileUtil.write(iconFilePath, in);
+ in = ((EntityImages)ent).getImage();
+ FileUtil.write(productionFilePath, in);
ent.setValueForProperty("icon_path",getIconStoragePath()+filepath);
ent.setValueForProperty("publish_path",filepath);
ent.update();
}
- public byte[] getIcon(Entity ent) throws MirMediaException
+ public InputStream getIcon(Entity ent) throws MirMediaException
{
- byte[] icon_data = null;
-
+ InputStream in;
try {
- icon_data = ((EntityImages)ent).getIcon();
+ in = ((EntityImages)ent).getIcon();
} catch ( StorageObjectException e) {
theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString());
throw new MirMediaException(e.toString());
}
- return icon_data;
+ return in;
}
public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
return MirConfig.getProp("Producer.Image.Host");
}
- public String getTinyIcon ()
+ public String getTinyIconName()
{
return MirConfig.getProp("Producer.Icon.TinyImage");
}
- public String getBigIcon ()
+ public String getBigIconName()
{
return MirConfig.getProp("Producer.Icon.BigImage");
}
- public String getIconAlt ()
+ public String getIconAltName()
{
return "Image";
}
- public boolean isVideo ()
+ public boolean isVideo()
{
return false;
}
- public boolean isAudio ()
+ public boolean isAudio()
{
return false;
}
package mircoders.media;
import java.util.*;
+import java.io.StringReader;
import freemarker.template.SimpleList;
import freemarker.template.SimpleHash;
//write the "meta" files
//first the .m3u since it only contains one line
FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile,
- mp3Pointer.getBytes());
+ new StringReader(mp3Pointer), "US-ASCII");
//now the .pls file
FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile,
- mp3Pointer.getBytes());
+ new StringReader(mp3Pointer), "US-ASCII");
} catch (Exception e) {
theLog.printError(e.toString());
throw new MirMediaException(e.toString());
package mircoders.media;
import java.util.*;
+import java.io.StringReader;
import freemarker.template.SimpleList;
import freemarker.template.SimpleHash;
try {
//write an rm (ram?. -mh) file
FileUtil.write(super.getStoragePath()+"/"+RealMediaFile,
- RealMediaPointer.getBytes());
+ new StringReader(RealMediaPointer), "US-ASCII");
} catch (Exception e) {
theLog.printError(e.toString());
throw new MirMediaException(e.toString());
package mircoders.media;
import java.util.*;
+import java.io.StringReader;
import freemarker.template.SimpleList;
import freemarker.template.SimpleHash;
try {
//write an rm (ram?. -mh) file
FileUtil.write(super.getStoragePath()+"/"+RealMediaFile,
- RealMediaPointer.getBytes());
+ new StringReader(RealMediaPointer), "US-ASCII");
} catch (Exception e) {
theLog.printError(e.toString());
throw new MirMediaException(e.toString());
return tinyIcon;
}
- public String getBigIcon()
+ public String getBigIconName()
{
return bigIcon;
}
package mircoders.media;
import java.util.*;
+import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletContext;
+import com.oreilly.servlet.multipart.FilePart;
+
import mircoders.storage.DatabaseMediaType;
import mircoders.producer.ProducerMedia;
import mir.storage.StorageObjectException;
* uploaded via the com.oreilly.servlet.multipart package. Finally the
* appropriate media objects are set.
*
- * @author $Author: mh $
- * @version $Revision: 1.2 $
- *
- * $Log: MediaRequest.java,v $
- * Revision 1.2 2002/09/01 22:05:55 mh
- * Mir goes GPL
- *
- * Revision 1.1.2.1 2002/09/01 21:31:43 mh
- * Mir goes GPL
- *
- * Revision 1.1 2002/07/21 22:38:39 mh
- * parses a multipart request's files and makes media Entity's out of them. Basically the old code from insposting() in ServletModuleOpenIndy
- *
+ * @author mh
+ * @version $Id: MediaRequest.java,v 1.3 2002/11/04 04:35:22 mh Exp $
*
*/
-public class MediaRequest
+public class MediaRequest implements FileHandler
{
- WebdbMultipartRequest _mp;
String _user;
+ EntityList _returnList = new EntityList();
+ boolean _produce, _publish;
- public MediaRequest(WebdbMultipartRequest mPreq, String user) {
- _mp = mPreq;
+ public MediaRequest(String user, boolean produce, boolean publish) {
_user = user;
+ _produce = produce;
+ _publish = publish;
+ }
+
+ public EntityList getEntityList() {
+ return _returnList;
}
/*
* is_published parameter (from the upload form) is supplied. (for backwards
* compatibility.)
*/
- public EntityList getMedia(boolean produce, boolean publish)
- throws MirMediaException,
- MirMediaUserException {
+ public void setFile(FilePart filePart, int fileNum, HashMap mediaValues)
+ throws FileHandlerException, FileHandlerUserException {
+
String mediaId=null;
- HashMap mediaValues = _mp.getParameters();
- EntityList returnList = new EntityList();
MirMedia mediaHandler;
Database mediaStorage = null;
ProducerMedia mediaProducer = null;
- int i=1;
- for(Iterator it = _mp.requestList.iterator(); it.hasNext();){
- try {
- MpRequest mpReq = (MpRequest)it.next();
- String fileName = mpReq.getFilename();
-
- //get the content-type from what the client browser
- //sends us. (the "Oreilly method")
- String contentType = mpReq.getContentType();
-
- //theLog.printInfo("FROM BROWSER: "+contentType);
-
- //if the client browser sent us unknown (text/plain is default)
- //or if we got application/octet-stream, it's possible that
- //the browser is in error, better check against the file extension
- if (contentType.equals("text/plain") ||
- contentType.equals("application/octet-stream")) {
- /**
- * Fallback to finding the mime-type through the standard ServletApi
- * ServletContext getMimeType() method.
- *
- * This is a way to get the content-type via the .extension,
- * we could maybe use a magic method as an additional method of
- * figuring out the content-type, by looking at the header (first
- * few bytes) of the file. (like the file(1) command). We could
- * also call the "file" command through Runtime. This is an
- * option that I almost prefer as it is already implemented and
- * exists with an up-to-date map on most modern Unix like systems.
- * I haven't found a really nice implementation of the magic method
- * in pure java yet.
- *
- * The first method we try thought is the "Oreilly method". It
- * relies on the content-type that the client browser sends and
- * that sometimes is application-octet stream with
- * broken/mis-configured browsers.
- *
- * The map file we use for the extensions is the standard web-app
- * deployment descriptor file (web.xml). See Mir's web.xml or see
- * your Servlet containers (most likely Tomcat) documentation.
- * So if you support a new media type you have to make sure that
- * it is in this file -mh
- */
- ServletContext ctx =
- (ServletContext)MirConfig.getPropAsObject("ServletContext");
- contentType = ctx.getMimeType(fileName);
- if (contentType==null)
- contentType = "text/plain"; // rfc1867 says this is the default
- }
- //theLog.printInfo("CONTENT TYPE IS: "+contentType);
-
- if (contentType.equals("text/plain") ||
- contentType.equals("application/octet-stream")) {
- _throwBadContentType(fileName, contentType);
- }
+ try {
+ String fileName = filePart.getFileName();
- String mediaTitle = (String)mediaValues.get("media_title"+i);
- i++;
- if ( (mediaTitle == null) || (mediaTitle.length() == 0))
- throw new MirMediaUserException("Missing field: media title");
-
- // TODO: need to add all the extra fields that can be present in the
- // admin upload form. -mh
- mediaValues.put("title", mediaTitle);
- mediaValues.put("date", StringUtil.date2webdbDate(
- new GregorianCalendar()));
- mediaValues.put("to_publisher", _user);
- //mediaValues.put("to_media_folder", "7"); // op media_folder
- mediaValues.put("is_produced", "0");
-
- // icky backwards compatibility code -mh
- if (publish == true) {
- mediaValues.put("is_published", "1");
- } else {
- if (!mediaValues.containsKey("is_published"))
- mediaValues.put("is_published", "0");
- }
+ //get the content-type from what the client browser
+ //sends us. (the "Oreilly method")
+ String contentType = filePart.getContentType();
- // @todo this should probably be moved to DatabaseMediaType -mh
- String[] cTypeSplit = StringUtil.split(contentType, "/");
- String wc = " mime_type LIKE '"+cTypeSplit[0]+"%'";
+ //theLog.printInfo("FROM BROWSER: "+contentType);
- DatabaseMediaType mediaTypeStor = DatabaseMediaType.getInstance();
- EntityList mediaTypesList = mediaTypeStor.selectByWhereClause(wc);
+ //if the client browser sent us unknown (text/plain is default)
+ //or if we got application/octet-stream, it's possible that
+ //the browser is in error, better check against the file extension
+ if (contentType.equals("text/plain") ||
+ contentType.equals("application/octet-stream")) {
+ /**
+ * Fallback to finding the mime-type through the standard ServletApi
+ * ServletContext getMimeType() method.
+ *
+ * This is a way to get the content-type via the .extension,
+ * we could maybe use a magic method as an additional method of
+ * figuring out the content-type, by looking at the header (first
+ * few bytes) of the file. (like the file(1) command). We could
+ * also call the "file" command through Runtime. This is an
+ * option that I almost prefer as it is already implemented and
+ * exists with an up-to-date map on most modern Unix like systems.
+ * I haven't found a really nice implementation of the magic method
+ * in pure java yet.
+ *
+ * The first method we try thought is the "Oreilly method". It
+ * relies on the content-type that the client browser sends and
+ * that sometimes is application-octet stream with
+ * broken/mis-configured browsers.
+ *
+ * The map file we use for the extensions is the standard web-app
+ * deployment descriptor file (web.xml). See Mir's web.xml or see
+ * your Servlet containers (most likely Tomcat) documentation.
+ * So if you support a new media type you have to make sure that
+ * it is in this file -mh
+ */
+ ServletContext ctx =
+ (ServletContext)MirConfig.getPropAsObject("ServletContext");
+ contentType = ctx.getMimeType(fileName);
+ if (contentType==null)
+ contentType = "text/plain"; // rfc1867 says this is the default
+ }
+ //theLog.printInfo("CONTENT TYPE IS: "+contentType);
+
+ if (contentType.equals("text/plain") ||
+ contentType.equals("application/octet-stream")) {
+ _throwBadContentType(fileName, contentType);
+ }
- String mediaTypeId = null;
+ String mediaTitle = (String)mediaValues.get("media_title"+fileNum);
+ if ( (mediaTitle == null) || (mediaTitle.length() == 0))
+ throw new FileHandlerUserException("Missing field: media title "+mediaTitle+fileNum);
- //if we didn't find an entry matching the
- //content-type int the table.
- if (mediaTypesList.size() == 0) {
- _throwBadContentType(fileName, contentType);
- }
+ // TODO: need to add all the extra fields that can be present in the
+ // admin upload form. -mh
+ mediaValues.put("title", mediaTitle);
+ mediaValues.put("date", StringUtil.date2webdbDate(
+ new GregorianCalendar()));
+ mediaValues.put("to_publisher", _user);
+ //mediaValues.put("to_media_folder", "7"); // op media_folder
+ mediaValues.put("is_produced", "0");
- Entity mediaType = null;
- Entity mediaType2 = null;
-
- // find out if we an exact content-type match if so take it.
- // otherwise try to match majortype/*
- // @todo this should probably be moved to DatabaseMediaType -mh
- for(int j=0;j<mediaTypesList.size();j++) {
- if(contentType.equals(
- mediaTypesList.elementAt(j).getValue("mime_type")))
- mediaType = mediaTypesList.elementAt(j);
- else if ((mediaTypesList.elementAt(j).getValue("mime_type")).equals(
- cTypeSplit[0]+"/*") )
- mediaType2= mediaTypesList.elementAt(j);
- }
+ // icky backwards compatibility code -mh
+ if (_publish == true) {
+ mediaValues.put("is_published", "1");
+ } else {
+ if (!mediaValues.containsKey("is_published"))
+ mediaValues.put("is_published", "0");
+ }
- if ( (mediaType == null) && (mediaType2 == null) ) {
- _throwBadContentType(fileName, contentType);
- }
- else if( (mediaType == null) && (mediaType2 != null) )
- mediaType = mediaType2;
-
- //get the class names from the media_type table.
- mediaTypeId = mediaType.getId();
- // ############### @todo: merge these and the getURL call into one
- // getURL helper call that just takes the Entity as a parameter
- // along with media_type
+ // @todo this should probably be moved to DatabaseMediaType -mh
+ String[] cTypeSplit = StringUtil.split(contentType, "/");
+ String wc = " mime_type LIKE '"+cTypeSplit[0]+"%'";
+
+ DatabaseMediaType mediaTypeStor = DatabaseMediaType.getInstance();
+ EntityList mediaTypesList = mediaTypeStor.selectByWhereClause(wc);
+
+ String mediaTypeId = null;
+
+ //if we didn't find an entry matching the
+ //content-type int the table.
+ if (mediaTypesList.size() == 0) {
+ _throwBadContentType(fileName, contentType);
+ }
+
+ Entity mediaType = null;
+ Entity mediaType2 = null;
+
+ // find out if we an exact content-type match if so take it.
+ // otherwise try to match majortype/*
+ // @todo this should probably be moved to DatabaseMediaType -mh
+ for(int j=0;j<mediaTypesList.size();j++) {
+ if(contentType.equals(
+ mediaTypesList.elementAt(j).getValue("mime_type")))
+ mediaType = mediaTypesList.elementAt(j);
+ else if ((mediaTypesList.elementAt(j).getValue("mime_type")).equals(
+ cTypeSplit[0]+"/*") )
+ mediaType2= mediaTypesList.elementAt(j);
+ }
+
+ if ( (mediaType == null) && (mediaType2 == null) ) {
+ _throwBadContentType(fileName, contentType);
+ } else if( (mediaType == null) && (mediaType2 != null) ) {
+ mediaType = mediaType2;
+ }
+
+ //get the class names from the media_type table.
+ mediaTypeId = mediaType.getId();
+ // ############### @todo: merge these and the getURL call into one
+ // getURL helper call that just takes the Entity as a parameter
+ // along with media_type
+ try {
mediaHandler = MediaHelper.getHandler(mediaType);
mediaStorage = MediaHelper.getStorage(mediaType,
- "mircoders.storage.Database");
- mediaValues.put("to_media_type",mediaTypeId);
-
- //load the classes via reflection
- String MediaId;
- Entity mediaEnt = null;
- try {
- mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
- if (produce == true) {
- Class prodCls = Class.forName("mircoders.producer.Producer"+
- mediaType.getValue("tablename"));
- mediaProducer = (ProducerMedia)prodCls.newInstance();
- }
- } catch (Exception e) {
- throw new MirMediaException("Error in MediaRequest: "+e.toString());
- }
-
- mediaEnt.setStorage(mediaStorage);
- mediaEnt.setValues(mediaValues);
- mediaId = mediaEnt.insert();
-
- //save and store the media data/metadata
- mediaHandler.set(mpReq.getMedia(), mediaEnt,
- mediaType);
- try {
- if (produce == true )
- mediaProducer.handle(null, null, false, false, mediaId);
- } catch (ModuleException e) {
- // first try to delete it.. don't catch exception as we've already..
- try { mediaStorage.delete(mediaId); } catch (Exception e2) {}
- throw new MirMediaException("error in MediaRequest: "+e.toString());
+ "mircoders.storage.Database");
+ } catch (MirMediaException e) {
+ throw new FileHandlerException (e.getMsg());
+ }
+ mediaValues.put("to_media_type",mediaTypeId);
+
+ //load the classes via reflection
+ String MediaId;
+ Entity mediaEnt = null;
+ try {
+ mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
+ if (_produce == true) {
+ Class prodCls = Class.forName("mircoders.producer.Producer"+
+ mediaType.getValue("tablename"));
+ mediaProducer = (ProducerMedia)prodCls.newInstance();
}
+ } catch (Exception e) {
+ throw new FileHandlerException("Error in MediaRequest: "+e.toString());
+ }
+
+ mediaEnt.setStorage(mediaStorage);
+ mediaEnt.setValues(mediaValues);
+ mediaId = mediaEnt.insert();
+
+ //try {
+ // File f = null;
+ // f = new File("/tmp/img.jpg");
+ // File dir = new File(f.getParent());
+ // dir.mkdirs();
+
+ // FileOutputStream out = new FileOutputStream(f);
+ // System.out.println("WRITE");
+ // filePart.writeTo(out);
+ // out.close();
+ //} catch (Exception e) {System.out.println("EE "+e.toString());}
+
- returnList.add(mediaEnt);
- } catch (StorageObjectException e) {
+ //mir.misc.FileUtil.write("/tmp/img.jpg", filePart.getInputStream());
+ //save and store the media data/metadata
+ try {
+ mediaHandler.set(filePart.getInputStream(), mediaEnt, mediaType);
+ } catch (MirMediaException e) {
+ throw new FileHandlerException(e.getMsg());
+ }
+ try {
+ if (_produce == true )
+ mediaProducer.handle(null, null, false, false, mediaId);
+ } catch (ModuleException e) {
// first try to delete it.. don't catch exception as we've already..
try { mediaStorage.delete(mediaId); } catch (Exception e2) {}
- throw new MirMediaException("error in MediaRequest: "+e.toString());
- } //end try/catch block
+ throw new FileHandlerException("error in MediaRequest: "+e.toString());
+ }
+
+ _returnList.add(mediaEnt);
+ } catch (StorageObjectException e) {
+ // first try to delete it.. don't catch exception as we've already..
+ try { mediaStorage.delete(mediaId); } catch (Exception e2) {}
+ throw new FileHandlerException("error in MediaRequest: "+e.toString());
+ } //end try/catch block
- } //end for Iterator...
- return returnList;
- } // method getMedia()
+ } // method setFile()
private void _throwBadContentType (String fileName, String contentType)
- throws MirMediaUserException {
+ throws FileHandlerUserException {
//theLog.printDebugInfo("Wrong file type uploaded!: " + fileName+" "
// +contentType);
- throw new MirMediaUserException("The file you uploaded is of the "
+ throw new FileHandlerUserException("The file you uploaded is of the "
+"following mime-type: "+contentType
+", we do not support this mime-type. "
+"Error One or more files of unrecognized type. Sorry");
/*
* ContentObjekt -
*
+ * @version $Id: ModuleContent.java,v 1.9 2002/11/04 04:35:22 mh Exp $
*
* @author RK
+ *
+ * $Log: ModuleContent.java,v $
+ * Revision 1.9 2002/11/04 04:35:22 mh
+ * merge media InputStream changes from MIR_1_0 branch
+ *
+ * Revision 1.7.4.3 2002/11/01 05:38:20 mh
+ * Converted media Interface to use streams (Java IO) instead of byte buffers of
+ * the entire uplaoded files. These saves loads of unecessary memory use. JAI
+ * still consumes quite a bit though.
+ *
+ * A new temporary file (for JAI) parameter is necessary and is in the config.properties file.
+ *
+ * A nice side effect of this work is the FileHandler interface which is
+ * basically a call back mechanism for WebdbMultipartRequest which allows the
+ * uploaded file to handled by different classes. For example, for a media
+ * upload, the content-type, etc.. needs to be determined, but if say the
+ * FileEditor had a feature to upload static files... another handler wood be
+ * needed. Right now only the MediaRequest handler exists.
+ *
+ *
*/
public class ModuleContent extends AbstractModule
public EntityList getFeatures(int offset, int limit) throws ModuleException
{
- return getContent("is_published=true AND to_article_type=2", "date desc, webdb_create desc",
+ return getContent("is_published=true AND to_article_type=2", "webdb_create desc",
offset, limit);
}
public EntityList getNewsWire(int offset, int limit) throws ModuleException
{
return getContent("is_published=true AND to_article_type = 1",
- "date desc, webdb_create desc",offset,limit);
+ "webdb_create desc",offset,limit);
}
public EntityList getStartArticle() throws ModuleException
{
EntityList returnList = getContent("is_published=true AND to_article_type=4",
- "date desc, webdb_create desc",0,1);
+ "webdb_create desc",0,1);
//if no startspecial exists
if (returnList==null || returnList.size()==0)
returnList = getContent("is_published=true AND to_article_type=3",
- "date desc, webdb_create desc",0,1);
+ "webdb_create desc",0,1);
return returnList;
}
}
if(whereClause.equals("nfrei")) {
- whereClause="is_published='0'"; orderBy="date desc";
+ whereClause="is_published='0'"; orderBy="webdb_create desc";
}
if(whereClause.equals("lastchange")) {
int contentBatchsize =
Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
- orderBy = "date desc, webdb_lastchange desc";
+ orderBy = "webdb_lastchange desc";
// get batch of non-produced medias, that are to be published
whereClause="is_published='1'";
* ServletModuleContent -
* deliver html for the article admin form.
*
- * @version $Revision: 1.21 $
- * @author $Author: mh $
- *
- * $Log: ServletModuleContent.java,v $
- * Revision 1.21 2002/09/01 22:05:57 mh
- * Mir goes GPL
- *
- * Revision 1.20 2002/08/25 19:00:11 mh
- * merge of localization branch into HEAD. mh and zap
- *
- * Revision 1.19 2002/07/20 22:24:25 mh
- * made the add() method use _showObject. Fixes a bug that cause the popUps not to show up when adding an article in the admin
- *
+ * @version $Id: ServletModuleContent.java,v 1.22 2002/11/04 04:35:22 mh Exp $
+ * @author rk, mir-coders
*
*/
tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio");
iconAlt = "Audio";
} else if (tinyIcon == null && !mediaHandler.isImage()) {
- tinyIcon = mediaHandler.getTinyIcon();
- iconAlt = mediaHandler.getIconAlt();
+ tinyIcon = mediaHandler.getTinyIconName();
+ iconAlt = mediaHandler.getIconAltName();
}
}
}
res.setContentType(ctx.getMimeType(fName));
ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist
- byte[] outbytes = entImage.getImage();
- out.write(outbytes);
+ InputStream in = entImage.getImage();
+ int read;
+ byte[] buf = new byte[8 * 1024];
+ while((read = in.read(buf)) != -1) {
+ out.write(buf, 0, read);
+ }
+ in.close();
out.close();
}
res.setContentType(ctx.getMimeType(fName));
ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist
- byte[] outbytes = entImage.getIcon();
- out.write(outbytes);
+ InputStream in = entImage.getIcon();
+ int read;
+ byte[] buf = new byte[8 * 1024];
+ while((read = in.read(buf)) != -1) {
+ out.write(buf, 0, read);
+ }
+ in.close();
+ //out.write(outbytes);
out.close();
}
* adding comments to articles &
* open-postings to the newswire
*
- * @author $Author: bruno $
- * @version $Revision: 1.41 $ $Date: 2002/09/03 14:30:37 $
- *
- * $Log: ServletModuleOpenIndy.java,v $
- * Revision 1.41 2002/09/03 14:30:37 bruno
- * seperation of admin and open posting bundles
- *
- * Revision 1.40 2002/09/01 22:05:57 mh
- * Mir goes GPL
- *
- * Revision 1.39 2002/08/25 19:00:11 mh
- * merge of localization branch into HEAD. mh and zap
- *
- * Revision 1.38 2002/07/21 22:50:14 mh
- * cleanup coding style of getpdf() method
- *
- * Revision 1.37 2002/07/21 22:41:45 mh
- * make use of new MediaRequest class. A big cleanup and optimization.
- *
- * Revision 1.36 2002/06/29 15:45:20 mh
- * cvs macros
- *
+ * @author mir-coders group
+ * @version $Id: ServletModuleOpenIndy.java,v 1.42 2002/11/04 04:35:22 mh Exp $
*
*/
boolean setTopic = false;
try {
- WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
+
+ WebdbMultipartRequest mp = null;
EntityList mediaList = null;
try {
// new MediaRequest, "1" is the id for the openPosting user
- mediaList = new MediaRequest(mp, "1").getMedia(true, true);
- } catch (MirMediaUserException e) {
+ MediaRequest mediaReq = new MediaRequest("1", true, true);
+ mp = new WebdbMultipartRequest(req, (FileHandler)mediaReq);
+ mediaList = mediaReq.getEntityList();
+ } catch (FileHandlerUserException e) {
throw new ServletModuleUserException(e.getMsg());
}
throw new ServletModuleException(t.getMessage());
}
}
- catch (MirMediaException e) { throw new ServletModuleException("MediaException: "+ e.toString());}
+ catch (FileHandlerException e) { throw new ServletModuleException("MediaException: "+ e.toString());}
catch (IOException e) { throw new ServletModuleException("IOException: "+ e.toString());}
catch (StorageObjectException e) { throw new ServletModuleException("StorageObjectException" + e.toString());}
catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.toString());}
import mir.media.MirMedia;
import mir.media.MirMediaException;
import mir.media.MirMediaUserException;
-import mir.misc.MirConfig;
-import mir.misc.MpRequest;
-import mir.misc.StringUtil;
-import mir.misc.WebdbMultipartRequest;
+import mir.misc.*;
import mir.module.ModuleException;
import mir.servlet.ServletModule;
import mir.servlet.ServletModuleException;
public void insert(HttpServletRequest req, HttpServletResponse res)
throws ServletModuleException, ServletModuleUserException {
try {
- WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
EntityUsers user = _getUser(req);
- EntityList mediaList =
- new MediaRequest(mp, user.getId()).getMedia(false, false);
- list(req, res);
+ MediaRequest mediaReq = new MediaRequest(user.getId(), false, false);
+ WebdbMultipartRequest mp = new WebdbMultipartRequest(req, (FileHandler)mediaReq);
+ EntityList mediaList = mediaReq.getEntityList();
+
+ SimpleHash mergeData = new SimpleHash();
+ SimpleHash popups = new SimpleHash();
+ mergeData.put("contentlist", mediaList);
+ if (mediaList.getOrder() != null) {
+ mergeData.put("order", mediaList.getOrder());
+ mergeData.put("order_encoded", URLEncoder.encode(mediaList.getOrder()));
+ }
+ mergeData.put("count", (new Integer(mediaList.getCount())).toString());
+ mergeData.put("from", (new Integer(mediaList.getFrom())).toString());
+ mergeData.put("to", (new Integer(mediaList.getTo())).toString());
+ if (mediaList.hasNextBatch())
+ mergeData.put("next", (new Integer(mediaList.getNextBatch())).toString());
+ if (mediaList.hasPrevBatch())
+ mergeData.put("prev", (new Integer(mediaList.getPrevBatch())).toString());
+ //fetch the popups
+ popups.put("mediafolderPopupData", DatabaseMediafolder.getInstance().getPopupData());
+ // raus damit
+ deliver(req, res, mergeData, popups, templateListString);
}
- catch (MirMediaUserException e) {
+ catch (FileHandlerUserException e) {
throw new ServletModuleUserException(e.getMsg());
}
- catch (MirMediaException e) {
+ catch (FileHandlerException e) {
throw new ServletModuleException(
"upload -- media handling exception " + e.toString());
}
+ catch (StorageObjectException e) {
+ throw new ServletModuleException("upload -- storageobjectexception "
+ + e.toString());
+ }
catch (IOException e) {
throw new ServletModuleException("upload -- ioexception " + e.toString());
}
public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException {
try {
- WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
+ EntityUsers user = _getUser(req);
+ WebdbMultipartRequest mp = new WebdbMultipartRequest(req, null);
HashMap parameters = mp.getParameters();
- EntityUsers user = _getUser(req);
parameters.put("to_publisher", user.getId());
parameters.put("is_produced", "0");
if (!parameters.containsKey("is_published"))
catch (ModuleException e) {
throw new ServletModuleException("upload -- moduleexception " + e.toString());
}
+ catch (Exception e) {
+ throw new ServletModuleException("upload -- exception " + e.toString());
+ }
}