# will be linked to.
Producer.ImageRoot=img
+
# the url of the video-server
Producer.Video.Host=http://indy.code-fu.de/video
# the url of the image-server
Producer.Image.Host=http://indy.code-fu.de/images
+# the url of the media-server
+Producer.Media.Host=http://indy.code-fu.de/media
+
# image specific storage directories
# absolute directory, where the images are saved
Producer.Image.Path=/pub/Dokumente/Indymedia/de-tech/Mir/produced/images
+# media specific storage directories
+# absolute directory, where the media files are saved
+Producer.Media.Path=/pub/Dokumente/Indymedia/de-tech/Mir/produced/media
+
# relativ directory, where the thumbnails will be saved
Producer.Image.IconPath=/icon
--- /dev/null
+#sun.net.www MIME content-types table; version 1.6, 05/04/99
+#
+# Property fields:
+#
+# <description> ::= 'description' '=' <descriptive string>
+# <extensions> ::= 'file_extensions' '=' <comma-delimited list, include '.'>
+# <image> ::= 'icon' '=' <filename of icon image>
+# <action> ::= 'browser' | 'application' | 'save' | 'unknown'
+# <application> ::= 'application' '=' <command line template>
+#
+
+#
+# The "we don't know anything about this data" type(s).
+# Used internally to mark unrecognized types.
+#
+content/unknown: description=Unknown Content
+unknown/unknown: description=Unknown Data Type
+
+#
+# The template we should use for temporary files when launching an application
+# to view a document of given type.
+#
+temp.file.template: /tmp/%s
+
+#
+# The "real" types.
+#
+application/octet-stream: \
+ description=Generic Binary Stream;\
+ file_extensions=.saveme,.dump,.hqx,.arc,.o,.a,.bin,.exe,.z,.gz
+
+application/oda: \
+ description=ODA Document;\
+ file_extensions=.oda
+
+application/pdf: \
+ description=Adobe PDF Format;\
+ file_extensions=.pdf
+
+application/postscript: \
+ description=Postscript File;\
+ file_extensions=.eps,.ai,.ps;\
+ icon=ps;\
+ action=application;\
+ application=imagetool %s
+
+application/x-dvi: \
+ description=TeX DVI File;\
+ file_extensions=.dvi;\
+ action=application;\
+ application=xdvi %s
+
+application/x-hdf: \
+ description=Hierarchical Data Format;\
+ file_extensions=.hdf;\
+ action=save
+
+application/x-latex: \
+ description=LaTeX Source;\
+ file_extensions=.latex
+
+application/x-netcdf: \
+ description=Unidata netCDF Data Format;\
+ file_extensions=.nc,.cdf;\
+ action=save
+
+application/x-tex: \
+ description=TeX Source;\
+ file_extensions=.tex
+
+application/x-texinfo: \
+ description=Gnu Texinfo;\
+ file_extensions=.texinfo,.texi
+
+application/x-troff: \
+ description=Troff Source;\
+ file_extensions=.t,.tr,.roff;\
+ action=application;\
+ application=xterm -title troff -e sh -c \"nroff %s | col | more -w\"
+
+application/x-troff-man: \
+ description=Troff Manpage Source;\
+ file_extensions=.man;\
+ action=application;\
+ application=xterm -title troff -e sh -c \"nroff -man %s | col | more -w\"
+
+application/x-troff-me: \
+ description=Troff ME Macros;\
+ file_extensions=.me;\
+ action=application;\
+ application=xterm -title troff -e sh -c \"nroff -me %s | col | more -w\"
+
+application/x-troff-ms: \
+ description=Troff MS Macros;\
+ file_extensions=.ms;\
+ action=application;\
+ application=xterm -title troff -e sh -c \"nroff -ms %s | col | more -w\"
+
+application/x-wais-source: \
+ description=Wais Source;\
+ file_extensions=.src,.wsrc
+
+application/zip: \
+ description=Zip File;\
+ file_extensions=.zip;\
+ icon=zip;\
+ action=save
+
+application/x-bcpio: \
+ description=Old Binary CPIO Archive;\
+ file_extensions=.bcpio; action=save
+
+application/x-cpio: \
+ description=Unix CPIO Archive;\
+ file_extensions=.cpio; action=save
+
+application/x-gtar: \
+ description=Gnu Tar Archive;\
+ file_extensions=.gtar;\
+ icon=tar;\
+ action=save
+
+application/x-shar: \
+ description=Shell Archive;\
+ file_extensions=.sh,.shar;\
+ action=save
+
+application/x-sv4cpio: \
+ description=SVR4 CPIO Archive;\
+ file_extensions=.sv4cpio; action=save
+
+application/x-sv4crc: \
+ description=SVR4 CPIO with CRC;\
+ file_extensions=.sv4crc; action=save
+
+application/x-tar: \
+ description=Tar Archive;\
+ file_extensions=.tar;\
+ icon=tar;\
+ action=save
+
+application/x-ustar: \
+ description=US Tar Archive;\
+ file_extensions=.ustar;\
+ action=save
+
+audio/basic: \
+ description=Basic Audio;\
+ file_extensions=.snd,.au;\
+ icon=audio;\
+ action=application;\
+ application=audiotool %s
+
+audio/x-aiff: \
+ description=Audio Interchange Format File;\
+ file_extensions=.aifc,.aif,.aiff;\
+ icon=aiff
+
+audio/x-wav: \
+ description=Wav Audio;\
+ file_extensions=.wav;\
+ icon=wav
+
+image/gif: \
+ description=GIF Image;\
+ file_extensions=.gif;\
+ icon=gif;\
+ action=browser
+
+image/ief: \
+ description=Image Exchange Format;\
+ file_extensions=.ief
+
+image/jpeg: \
+ description=JPEG Image;\
+ file_extensions=.jfif,.jfif-tbnl,.jpe,.jpg,.jpeg;\
+ icon=jpeg;\
+ action=browser;\
+ application=imagetool %s
+
+image/tiff: \
+ description=TIFF Image;\
+ file_extensions=.tif,.tiff;\
+ icon=tiff
+
+image/vnd.fpx: \
+ description=FlashPix Image;\
+ file_extensions=.fpx,.fpix
+
+image/x-cmu-rast: \
+ description=CMU Raster Image;\
+ file_extensions=.ras
+
+image/x-portable-anymap: \
+ description=PBM Anymap Format;\
+ file_extensions=.pnm
+
+image/x-portable-bitmap: \
+ description=PBM Bitmap Format;\
+ file_extensions=.pbm
+
+image/x-portable-graymap: \
+ description=PBM Graymap Format;\
+ file_extensions=.pgm
+
+image/x-portable-pixmap: \
+ description=PBM Pixmap Format;\
+ file_extensions=.ppm
+
+image/x-rgb: \
+ description=RGB Image;\
+ file_extensions=.rgb
+
+image/x-xbitmap: \
+ description=X Bitmap Image;\
+ file_extensions=.xbm,.xpm
+
+image/x-xwindowdump: \
+ description=X Window Dump Image;\
+ file_extensions=.xwd
+
+image/png: \
+ description=PNG Image;\
+ file_extensions=.png;\
+ icon=png;\
+ action=browser
+
+text/html: \
+ description=HTML Document;\
+ file_extensions=.htm,.html;\
+ icon=html
+
+text/plain: \
+ description=Plain Text;\
+ file_extensions=.text,.c,.cc,.c++,.h,.pl,.txt,.java,.el;\
+ icon=text;\
+ action=browser
+
+text/tab-separated-values: \
+ description=Tab Separated Values Text;\
+ file_extensions=.tsv
+
+text/x-setext: \
+ description=Structure Enhanced Text;\
+ file_extensions=.etx
+
+video/mpeg: \
+ description=MPEG Video Clip;\
+ file_extensions=.mpg,.mpe,.mpeg;\
+ icon=mpeg;\
+ action=application;\
+ application=mpeg_play %s
+
+video/quicktime: \
+ description=QuickTime Video Clip;\
+ file_extensions=.mov,.qt
+
+application/x-troff-msvideo: \
+ description=AVI Video;\
+ file_extensions=.avi;\
+ icon=avi
+
+video/x-sgi-movie: \
+ description=SGI Movie;\
+ file_extensions=.movie,.mv
+
+message/rfc822: \
+ description=Internet Email Message;\
+ file_extensions=.mime
+
+application/xml: \
+ description=XML document;\
+ file_extensions=.xml
+
+audio/mp3: \
+ description=MPEG Layer 3;\
+ file_extensions=.mp3;\
+ icon=mpeg;\
+ action=application;\
+ application=mpg123 %s
+
+
if (isField(theProp))
theValuesHash.put(theProp, theValue);
else
- theLog.printWarning("Property not found: " + theProp);
+ theLog.printWarning("Property not found: " + theProp+theValue);
+
}
/**
--- /dev/null
+/*
+ * put your module comment here
+ */
+
+
+package mir.media;
+
+import java.util.*;
+
+import mir.entity.*;
+import mir.misc.*;
+import mir.storage.*;
+
+
+/**
+ * Interfacedefinition für Datenbank-Adpatoren. Die Adaptoren legen
+ * jeweils das Verhalten und die Befehlsmächtigkeit der Datenbank
+ * fest.
+ *
+ * @author <mh>
+ * @version 24.09.2001
+ */
+
+public class MediaHandlerGeneric implements MirMedia
+{
+
+ private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
+ public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) {
+ String ext = mediaTypeEnt.getValue("name");
+ String dir = MirConfig.getProp("Producer.Media.Path");
+ String mediaHost = MirConfig.getProp("Producer.Media.Host");
+ String mediaFname = ent.getId()+"."+ext;
+ if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
+ try {
+ ent.setValueForProperty("publish_path", mediaFname);
+ ent.setValueForProperty("publish_server", mediaHost);
+ ent.update();
+ } catch (StorageObjectException e) {
+ theLog.printError("StorageObjectException: "+e.toString());
+ return false;
+ }
+ } else {
+ theLog.printError("could not write FILE!");
+ return false;
+ }
+
+ return true;
+ }
+
+ //a class that will probably never get used..
+ private byte[] getFile (String fileName) {
+ long size = FileUtil.getSize(fileName);
+ if (size < 0) return null;
+
+ byte[] container = new byte[(int)size];
+
+ if(!FileUtil.read(fileName, container))
+ return null;
+
+ return container;
+ }
+
+ public byte[] get (Entity ent, Entity mediaTypeEnt) {
+ String ext = mediaTypeEnt.getValue("extension");
+ String dir = MirConfig.getProp("Producer.Media.Path");
+ String fullFname = dir+"/"+ent.getId()+"."+ext;
+ return getFile(fullFname);
+ }
+
+ public byte[] getIcon (Entity ent) {
+ String name = "/path/to/some/generic/icon";
+ return getFile(name);
+ }
+}
+
+
+
--- /dev/null
+
+package mir.media;
+
+import java.lang.*;
+import java.io.*;
+import java.util.*;
+import java.lang.reflect.*;
+
+import mir.misc.*;
+import mir.entity.*;
+
+/**
+ * This class handles saving, fetching creating representations
+ * for all images.
+ *
+ * ok. this is a big hack, it's cause putting the image in the DB
+ * and fetching it from the DB needs low level db connections for
+ * some reason. -mh 25.09.2001
+ *
+ * @author mh
+ * @version 24.09.2001
+ */
+
+
+public class MediaHandlerImages
+{
+ protected final String WEBDB_JPG="0";
+ protected final String WEBDB_GIF="1";
+
+ protected String imageType="0";
+ private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
+
+ public byte[] get(Entity ent, Entity mediaTypeEnt)
+ {
+ byte[] image_data = null;
+
+ try {
+ Method method = ent.getClass().getMethod("getImage",null);
+ image_data = (byte[])method.invoke(ent, null);
+ } catch ( NoSuchMethodException e) {
+ theLog.printDebugInfo("method lookup unsuccesful: "+e.toString());
+ } catch ( IllegalAccessException e) {
+ theLog.printDebugInfo("method illegal: "+e.toString());
+ } catch ( InvocationTargetException e) {
+ theLog.printDebugInfo("invocation target illegal: "+e.toString());
+ }
+
+
+ return image_data;
+ }
+
+ protected boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
+ {
+ try {
+ Class[] params = {byte[].class, String.class};
+ Method method = ent.getClass().getMethod("setImage",params);
+ method.invoke(ent, new Object[] {uploadData, imageType});
+ } catch ( NoSuchMethodException e) {
+ theLog.printDebugInfo("method lookup unsuccesful: "+e.toString());
+ return false;
+ } catch ( IllegalAccessException e) {
+ theLog.printDebugInfo("method illegal: "+e.toString());
+ return false;
+ } catch ( InvocationTargetException e) {
+ theLog.printDebugInfo("invocation target illegal: "+e.toString());
+ return false;
+ }
+ return true;
+ }
+
+ public byte[] getIcon(Entity ent)
+ {
+ byte[] icon_data = null;
+
+ try {
+ Method method = ent.getClass().getMethod("getIcon",null);
+ icon_data = (byte[])method.invoke(ent, null);
+ } catch ( NoSuchMethodException e) {
+ theLog.printDebugInfo("method lookup unsuccesful: "+e.toString());
+ } catch ( IllegalAccessException e) {
+ theLog.printDebugInfo("method illegal: "+e.toString());
+ } catch ( InvocationTargetException e) {
+ theLog.printDebugInfo("invocation target illegal: "+e.toString());
+ }
+
+ return icon_data;
+ }
+}
--- /dev/null
+
+package mir.media;
+
+import java.lang.*;
+import java.io.*;
+import java.util.*;
+import java.sql.*;
+
+import mir.entity.*;
+
+/**
+ * This class handles saving, fetching creating representations
+ * for gif images.
+ *
+ * @author mh
+ * @version 24.09.2001
+ */
+
+
+public class MediaHandlerImagesGif extends MediaHandlerImages implements MirMedia
+{
+
+ public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
+ {
+ imageType = WEBDB_GIF;
+ return super.set(uploadData, ent, mediaTypeEnt);
+ }
+}
--- /dev/null
+
+package mir.media;
+
+import java.lang.*;
+import java.io.*;
+import java.util.*;
+import java.sql.*;
+
+import mir.entity.*;
+
+/**
+ * This class handles saving, fetching creating representations
+ * for jpeg images.
+ *
+ * @author mh <heckmann@hbe.ca>
+ * @version 24.09.2001
+ */
+
+
+public class MediaHandlerImagesJpeg extends MediaHandlerImages implements MirMedia
+{
+ public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
+ {
+ imageType = WEBDB_JPG;
+ return super.set(uploadData, ent, mediaTypeEnt);
+ }
+}
--- /dev/null
+/*
+ * put your module comment here
+ */
+
+
+package mir.media;
+
+import java.util.*;
+
+import mir.entity.*;
+
+/**
+ * Interfacedefinition für Datenbank-Adpatoren. Die Adaptoren legen
+ * jeweils das Verhalten und die Befehlsmächtigkeit der Datenbank
+ * fest.
+ *
+ * @author <mh>
+ * @version 24.09.2001
+ */
+
+public interface MirMedia{
+
+ /* Liefert den Namen der Adaptorklasse
+ * @return Adaptorklasse als String
+ */
+ public abstract boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt );
+
+
+ public abstract byte[] get (Entity ent, Entity mediaTypeEnt);
+
+
+ /**
+ * Liefert die URL für JDBC zurück, in den die Parameter user, pass und host
+ * eingefügt werden. Die URL wird aus der Konfiguration geholt.
+ *
+ * @param user user als String
+ * @param pass passwort als String
+ * @param host host als String
+ * @return url als String
+ */
+ //public abstract String makeURL (Entity ent);
+
+
+ /**
+ * Gibt zurück, ob das SQL der Datenbank den <code>limit</code>-Befehl beherrscht.
+ * @return true wenn ja, sonst false
+ */
+ public abstract byte[] getIcon (Entity ent);
+
+}
+
+
--- /dev/null
+
+/*
+ * put your module comment here
+ */
+
+
+package mir.misc;
+
+import java.lang.*;
+import java.util.*;
+import java.io.*;
+import java.net.*;
+import freemarker.template.*;
+import mir.entity.*;
+import mir.storage.*;
+import javax.servlet.http.*;
+
+
+/**
+ * Hilfsklasse zum Mergen von Template und Daten
+ */
+public final class FileUtil {
+
+ private static boolean fileNameMapLoaded = false;
+ private static FileNameMap fileNameMap;
+ private static String producerStorageRoot;
+
+ //
+ // Initialisierung
+
+ static {
+ System.setProperty("content.types.user.table", MirConfig.getProp("Home")+"content-types.properties");
+ fileNameMap = sun.net.www.MimeTable.loadTable();
+ producerStorageRoot = MirConfig.getProp("Producer.StorageRoot");
+ }
+
+ /**
+ * Privater Konstruktor, um versehentliche Instantiierung zu verhindern
+ */
+ private FileUtil () {
+ }
+
+ public static boolean write(String filename, byte[] in) {
+
+ boolean retVal = false;
+
+ 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;
+ } catch(IOException exception) {}
+ }
+ return retVal;
+ }
+
+ public static boolean read(String filename, byte out[]) {
+
+ File f = null;
+ f = new File(filename);
+
+ if (f.exists()) {
+ try {
+ if (out.length != f.length())
+ return false;
+ FileInputStream inStream;
+ inStream = new FileInputStream(f);
+ inStream.read(out);
+ inStream.close();
+ } catch(IOException exception) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ public static long getSize(String filename) {
+ File f = null;
+ f = new File(filename);
+ long l=0;
+
+ if (f.exists()) {
+ return f.length();
+ } else {
+ return -1;
+ }
+ }
+
+ private static FileNameMap getFileNameMap() {
+ if ((fileNameMap == null) && !fileNameMapLoaded) {
+ fileNameMap = sun.net.www.MimeTable.loadTable();
+ fileNameMapLoaded = true;
+ }
+
+ return new FileNameMap() {
+ private FileNameMap map = fileNameMap;
+ public String getContentTypeFor(String fileName) {
+ return map.getContentTypeFor(fileName);
+ }
+ };
+ }
+
+ public static void setFileNameMap(FileNameMap map) {
+ fileNameMap = map;
+ }
+
+ public static String guessContentTypeFromName(String fname) {
+ String contentType = null;
+
+ contentType = getFileNameMap().getContentTypeFor(fname);
+
+ return contentType;
+ }
+
+
+
+
+}
}
}
-}
\ No newline at end of file
+}
+++ /dev/null
-package mircoders.entity;
-
-import java.lang.*;
-import java.io.*;
-import java.util.*;
-import java.sql.*;
-
-import mir.entity.*;
-import mir.misc.*;
-import mir.storage.*;
-
-/**
- * Diese Klasse enthält die Daten eines MetaObjekts
- *
- * @author RK
- * @version 11.11.2000
- */
-
-
-public class EntityImage extends AbstractEntity implements Entity
-{
- private static int instances;
-
- public EntityImage()
- {
- super();
- instances++;
- }
-
- public EntityImage(StorageObject theStorage) {
- this();
- setStorage(theStorage);
- }
-
- //
- // methods
-
-
-
- public byte[] getImage()
- {
- theLog.printDebugInfo("--getimage started");
- Connection con=null;Statement stmt=null;
- byte[] img_data=null;
-
- try {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- stmt = con.createStatement();
- ResultSet rs = theStorageObject.executeSql(stmt,"select image_data from images where id="+getId());
- if(rs!=null) {
- if (rs.next()) {
- img_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 img_data;
- }
-
- public void setImage(byte[] uploadData, int imageType)
- {
- if (uploadData!=null) {
- Connection con=null;PreparedStatement pstmt=null;
- try {
-
- theLog.printDebugInfo("settimage :: making internal representation of image");
- WebdbImage webdbImage= new WebdbImage(uploadData,imageType);
- 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
- String sql = "update images set img_height='"+webdbImage.getImageHeight() +
- "',img_width='" + webdbImage.getImageWidth() +
- "',icon_height='" + webdbImage.getIconHeight() +
- "',icon_width='" + webdbImage.getIconWidth() + "', image_data=?, icon_data=? 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) {theLog.printDebugInfo("settimage :: setImage gescheitert: "+e.toString());}
- finally {
- try {con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,pstmt); }
- }
- }
-
- public void update() throws StorageObjectException {
- super.update();
- try {
- theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
- } catch (SQLException e) {
- theLog.printError("EntityImage :: update :: failed!! "+ e.toString());
- }
- }
-
- public void setValues(HashMap theStringValues)
- {
- if (theStringValues != null) {
- if (!theStringValues.containsKey("is_published"))
- theStringValues.put("is_published","0");
- }
- super.setValues(theStringValues);
- }
-
- public byte[] getIcon()
- {
- Connection con=null;Statement stmt=null;
- byte[] img_data=null;
-
- try {
- con = theStorageObject.getPooledCon();
- con.setAutoCommit(false);
- stmt = con.createStatement();
- ResultSet rs = theStorageObject.executeSql(stmt,"select icon_data from images where id="+getId());
- if(rs!=null) {
- if (rs.next()) {
- img_data = rs.getBytes(1);
- }
- rs.close();
- }
- }
- catch (Exception e) {theLog.printDebugInfo("-- getIcon gescheitert: "+e.toString());}
- finally {
- try {con.setAutoCommit(true); } catch (Exception e) {;}
- theStorageObject.freeConnection(con,stmt); }
-
- return img_data;
- }
-
- public void finalize() {
- instances--;
- super.finalize();
- }
-
-}
--- /dev/null
+package mircoders.entity;
+
+import java.lang.*;
+import java.io.*;
+import java.util.*;
+import java.sql.*;
+
+import mir.entity.*;
+import mir.misc.*;
+import mir.storage.*;
+
+/**
+ * Diese Klasse enthält die Daten eines MetaObjekts
+ *
+ * @author RK
+ * @version 11.11.2000
+ */
+
+
+public class EntityImages extends AbstractEntity implements Entity
+{
+ private static int instances;
+
+ public EntityImages()
+ {
+ super();
+ instances++;
+ }
+
+ public EntityImages(StorageObject theStorage) {
+ this();
+ setStorage(theStorage);
+ }
+
+ //
+ // methods
+
+
+
+ public byte[] getImage()
+ {
+ theLog.printDebugInfo("--getimage started");
+ Connection con=null;Statement stmt=null;
+ byte[] img_data=null;
+
+ try {
+ con = theStorageObject.getPooledCon();
+ con.setAutoCommit(false);
+ stmt = con.createStatement();
+ ResultSet rs = theStorageObject.executeSql(stmt,"select image_data from images where id="+getId());
+ if(rs!=null) {
+ if (rs.next()) {
+ img_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 img_data;
+ }
+
+ public void setImage(byte[] uploadData, String imageType)
+ {
+ int type = 0;
+
+ //hack -mh
+ if (imageType.equals("1"))
+ type = 1;
+
+ if (uploadData!=null) {
+ Connection con=null;PreparedStatement pstmt=null;
+ try {
+
+ theLog.printDebugInfo("settimage :: making internal representation of image");
+ WebdbImage webdbImage= new WebdbImage(uploadData,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
+ String sql = "update images set img_height='"+webdbImage.getImageHeight() +
+ "',img_width='" + webdbImage.getImageWidth() +
+ "',icon_height='" + webdbImage.getIconHeight() +
+ "',icon_width='" + webdbImage.getIconWidth() + "', image_data=?, icon_data=? 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) {theLog.printDebugInfo("settimage :: setImage gescheitert: "+e.toString());}
+ finally {
+ try {con.setAutoCommit(true); } catch (Exception e) {;}
+ theStorageObject.freeConnection(con,pstmt); }
+ }
+ }
+
+ public void update() throws StorageObjectException {
+ super.update();
+ try {
+ theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
+ } catch (SQLException e) {
+ theLog.printError("EntityImages :: update :: failed!! "+ e.toString());
+ }
+ }
+
+ public void setValues(HashMap theStringValues)
+ {
+ if (theStringValues != null) {
+ if (!theStringValues.containsKey("is_published"))
+ theStringValues.put("is_published","0");
+ }
+ super.setValues(theStringValues);
+ }
+
+ public byte[] getIcon()
+ {
+ Connection con=null;Statement stmt=null;
+ byte[] img_data=null;
+
+ try {
+ con = theStorageObject.getPooledCon();
+ con.setAutoCommit(false);
+ stmt = con.createStatement();
+ ResultSet rs = theStorageObject.executeSql(stmt,"select icon_data from images where id="+getId());
+ if(rs!=null) {
+ if (rs.next()) {
+ img_data = rs.getBytes(1);
+ }
+ rs.close();
+ }
+ }
+ catch (Exception e) {theLog.printDebugInfo("-- getIcon gescheitert: "+e.toString());}
+ finally {
+ try {con.setAutoCommit(true); } catch (Exception e) {;}
+ theStorageObject.freeConnection(con,stmt); }
+
+ return img_data;
+ }
+
+ public void finalize() {
+ instances--;
+ super.finalize();
+ }
+
+}
setStorage(theStorage);
}
+ public void setValues(HashMap theStringValues)
+ {
+ if (theStringValues != null) {
+ if (!theStringValues.containsKey("is_published"))
+ theStringValues.put("is_published","0");
+ }
+ super.setValues(theStringValues);
+ }
+
public void finalize() {
instances--;
super.finalize();
String iconFilename;
String imageFilename;
String productionPath;
- EntityImage currentImage;
+ EntityImages currentImage;
EntityList batchEntityList;
int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
while (batchEntityList != null) {
for(int i=0;i<batchEntityList.size();i++) {
theLog.printDebugInfo("trying image: " + i);
- currentImage = (EntityImage)batchEntityList.elementAt(i);
+ currentImage = (EntityImages)batchEntityList.elementAt(i);
// make filenames
String date = currentImage.getValue("date");
parameters.put("is_published","0");
String id = mainModule.add(parameters);
- EntityImage entImage = (EntityImage)mainModule.getById(id);
+ EntityImages entImage = (EntityImages)mainModule.getById(id);
if (imageData!=null && fileName!=null) {
int fileType = -1;
parameters.put("is_published","0");
String id = mainModule.set(parameters);
- EntityImage entImage = (EntityImage)mainModule.getById(id);
+ EntityImages entImage = (EntityImages)mainModule.getById(id);
if (imageData!=null && fileName!=null) {
int fileType = -1;
String idParam = req.getParameter("id");
if (idParam!=null && !idParam.equals("")) {
try {
- EntityImage entImage =(EntityImage)mainModule.getById(idParam);
+ EntityImages entImage =(EntityImages)mainModule.getById(idParam);
res.setContentType("image/jpeg"); // testweise
ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist
String idParam = req.getParameter("id");
if (idParam!=null && !idParam.equals("")) {
try {
- EntityImage entImage =(EntityImage)mainModule.getById(idParam);
+ EntityImages entImage =(EntityImages)mainModule.getById(idParam);
res.setContentType("image/jpeg"); // testweise
ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist
if (contentType.equals("image/jpeg")) fileType=0;
if (contentType.equals("image/gif")) fileType=1;
if (fileType>=0) {
- EntityImage entImage = (EntityImage)mainModule.getById(idParam);
+ EntityImages entImage = (EntityImages)mainModule.getById(idParam);
entImage.setImage(imageData, fileType);
}
else
import java.io.*;
import java.sql.*;
import java.util.*;
+import java.net.*;
+import java.lang.reflect.*;
import javax.servlet.*;
import javax.servlet.http.*;
import mir.misc.*;
import mir.entity.*;
import mir.storage.*;
+import mir.media.*;
import mircoders.entity.*;
import mircoders.storage.*;
int i=1;
for(Iterator it = mp.requestList.iterator(); it.hasNext();){
MpRequest mpReq = (MpRequest)it.next();
- byte[] mediaData=mpReq.getMedia();
- String fileName=mpReq.getFilename();
- String contentType=mpReq.getContentType();
- if (mediaData!=null && fileName!=null) {
- HashMap mediaValues = new HashMap();
- mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
- mediaValues.put("to_publisher", "1"); // op user
- mediaValues.put("to_media_folder", "7"); // op media_folder
- mediaValues.put("is_produced", "0");
- mediaValues.put("is_published","1");
-
- String mediaTitle=(String)withValues.get("media_title"+i);
- i++;
- if (mediaTitle==null)
+ String fileName = mpReq.getFilename();
+ String contentType = FileUtil.guessContentTypeFromName(fileName);
+ HashMap mediaValues = new HashMap();
+
+ theLog.printError("CONTENT TYPE IS: "+contentType);
+
+ if ((contentType==null) || (contentType=="application/octet-stream")) {
+ throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
+ }
+
+
+ String mediaTitle=(String)withValues.get("media_title"+i);
+ i++;
+
+ if (mediaTitle==null)
mediaTitle = (String)withValues.get("title");
- mediaValues.put("title",mediaTitle);
+
+ mediaValues.put("title", mediaTitle);
+ mediaValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
+ mediaValues.put("to_publisher", "1"); // op user
+ mediaValues.put("to_media_folder", "7"); // op media_folder
+ mediaValues.put("is_produced", "0");
+ mediaValues.put("is_published","1");
+
+ String wc = " mime_type='"+contentType+"'";
+
+ EntityList mediaTypesList = DatabaseMediaType.getInstance().selectByWhereClause(wc);
+
+ String mediaTypeId = null;
+ String mediaStorageName = null;
+ String mediaHandlerName = null;
- if (fileName.toLowerCase().endsWith("rm")) {
- // this is video !!
+ if (mediaTypesList.size() > 0) {
+ mediaTypeId = mediaTypesList.elementAt(0).getId();
+ mediaStorageName = mediaTypesList.elementAt(0).getValue("tablename");
+ mediaHandlerName = mediaTypesList.elementAt(0).getValue("classname");
+ mediaValues.put("to_media_type",mediaTypeId);
+
+ String MediaId;
+ try {
+ Class mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
+ Method m = mediaStorageClass.getMethod("getInstance", null);
+ Database mediaStorage = (Database)m.invoke(null, null);
+ Entity mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
+ mediaEnt.setStorage(mediaStorage);
+ mediaEnt.setValues(mediaValues);
+ mediaId = mediaEnt.insert();
+
+ Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+ MirMedia mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
+ mediaHandler.set(mpReq.getMedia(), mediaEnt,mediaTypesList.elementAt(0));
+ if(mediaId!=null){
+ //new ProducerImages().handle(null, null, false, false, mediaId);
+ }
+ } catch (Exception e) {
+ theLog.printError("setting uploaded_media failed: "+e.toString());
+ }
+
+
+ try{
+ DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
+ theLog.printError("setting content_x_media success");
+ } catch (Exception e) {
+ theLog.printError("setting content_x_media failed");
+ }
+
+ } else {
+ theLog.printDebugInfo("Wrong file uploaded!: " + fileName);
+ throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
+ }
+
+
+
+
+
+
+ //MirUploadedMedia Media = MirUploadedMedia(mpReq, cid);
+ //mediaValues.put("title",mediaTitle);
+
+ //mediaId = Media.add();
+ /* // this is video !!
//theLog.printDebugInfo("--GOT VIDEO");
EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
+ //notice the discr here..... (imageModule).
entVideo.setValues(mediaValues);
mediaId = entVideo.insert();
entVideo.setVideoData(mediaData);
}
+ //try content type first then go by xtension?
else if (contentType.equals("image/jpeg") || contentType.equals("image/gif")) {
// this is image !!
mediaId = imageModule.add(mediaValues);
- EntityImage entImage = (EntityImage)imageModule.getById(mediaId);
+ EntityImages entImage = (EntityImages)imageModule.getById(mediaId);
int fileType = -1;
+
+ //replace all this with DatabaseContentMedia.getInst().getEn(contentType).set(mediaData) ??? w/ a catch for error, then return form w/ and error
if (contentType.equals("image/jpeg")) fileType=0;
if (contentType.equals("image/gif")) fileType=1;
if (fileType>=0) {
theLog.printDebugInfo("Wrong file uploaded!" + fileName);
}
}
- }
+ }*/
}
// producing openpostinglist
this.theTable="images";
this.theCoreTable="media";
try {
- this.theEntityClass = Class.forName("mircoders.entity.EntityImage");
+ this.theEntityClass = Class.forName("mircoders.entity.EntityImages");
}
catch (Exception e) { throw new StorageObjectException(e.toString()); }
}
public void update(Entity theEntity) throws StorageObjectException
{
- theEntity.setValueForProperty("to_media_type","1");
String date = theEntity.getValue("date");
if (date==null){
date = StringUtil.date2webdbDate(new GregorianCalendar());
* returns the comments that belong to the article (via entityrelation)
* where db-flag is_published is true
*/
- public SimpleList getMediaType(EntityUploadedMedia ent) {
- SimpleList comments=null;
+ public Entity getMediaType(EntityUploadedMedia ent) {
+ Entity type=null;
try {
- comments = relationMediaType.getManyAsSimpleList(ent,"webdb_create","is_published='1'");
+ type = relationMediaType.getOne(ent);
}
catch (StorageObjectException e) {
theLog.printError("DatabaseUploadedMedia :: failed to get media_type");
}
- return comments;
+ return type;
}
}