From 53a936ecab884cd854446b8a43656d2cecb6b9cc Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 2 Oct 2001 00:33:12 +0000 Subject: [PATCH] more media.. media is now available in article ( content) pages. the reflection stuff is getting out of hand, I'll wrap it in a helper class maybe with some sort of caching, of handlers or singletons.. --- dbscripts/create_pg.sql | 3 +- source/config.properties-dist | 6 ++ source/mir/media/MediaHandlerAudio.java | 10 +++- source/mir/media/MediaHandlerGeneric.java | 17 ++++++ source/mir/media/MediaHandlerImages.java | 13 +++++ source/mir/media/MirMedia.java | 3 +- source/mir/misc/StringUtil.java | 64 +++++++++++++++++++--- source/mir/module/AbstractModule.java | 3 - source/mircoders/producer/ProducerContent.java | 46 ++++++++++++++-- .../mircoders/servlet/ServletModuleOpenIndy.java | 1 - .../mircoders/storage/DatabaseUploadedMedia.java | 1 - templates-dist/producer/content.template | 12 ++-- 12 files changed, 152 insertions(+), 27 deletions(-) diff --git a/dbscripts/create_pg.sql b/dbscripts/create_pg.sql index 7092165f..530591e8 100755 --- a/dbscripts/create_pg.sql +++ b/dbscripts/create_pg.sql @@ -326,7 +326,8 @@ CREATE TABLE "media" ( CREATE TABLE "uploaded_media" ( "icon_is_produced" boolean DEFAULT '0' NOT NULL, - "icon_path" character varying(255) + "icon_path" character varying(255), + "size" integer ) INHERITS ("media"); CREATE TABLE "images" ( diff --git a/source/config.properties-dist b/source/config.properties-dist index 82c6c43d..69a81083 100755 --- a/source/config.properties-dist +++ b/source/config.properties-dist @@ -109,6 +109,12 @@ Producer.Icon.TinyAudio=audio_small.gif Producer.Icon.TinyVideo=video_small.gif Producer.Icon.TinyText=text_small.gif +#Medium sized icons used at various places +Producer.Icon.BigImage=photo_big.gif +Producer.Icon.BigAudio=audio_big.gif +Producer.Icon.BigVideo=video_big.gif +Producer.Icon.BigText=text_big.gif + # diff --git a/source/mir/media/MediaHandlerAudio.java b/source/mir/media/MediaHandlerAudio.java index 20fd12dd..dc3e08b1 100755 --- a/source/mir/media/MediaHandlerAudio.java +++ b/source/mir/media/MediaHandlerAudio.java @@ -24,9 +24,17 @@ import mir.storage.*; public class MediaHandlerAudio extends MediaHandlerGeneric implements MirMedia { + private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio"); + private static String bigIcon = MirConfig.getProp("Producer.Icon.BigAudio"); + public String getTinyIcon() { - return MirConfig.getProp("Producer.Icon.TinyAudio"); + return tinyIcon; + } + + public String getBigIcon() + { + return bigIcon; } public String getIconAlt() diff --git a/source/mir/media/MediaHandlerGeneric.java b/source/mir/media/MediaHandlerGeneric.java index edd7ff18..471f06c1 100755 --- a/source/mir/media/MediaHandlerGeneric.java +++ b/source/mir/media/MediaHandlerGeneric.java @@ -24,6 +24,7 @@ import mir.storage.*; public class MediaHandlerGeneric implements MirMedia { + private static String imageRoot = MirConfig.getProp("Producer.ImageRoot"); 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"); @@ -32,6 +33,7 @@ public class MediaHandlerGeneric implements MirMedia String mediaFname = ent.getId()+"."+ext; String date = ent.getValue("date"); String datePath = StringUtil.webdbDate2path(date); + Integer size = new Integer(uploadedData.length); //hack: make it a config option to use "dated" dirs //we can't cause of stallman -mh //if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) { @@ -44,6 +46,7 @@ public class MediaHandlerGeneric implements MirMedia //ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); ent.setValueForProperty("publish_path", mediaFname); ent.setValueForProperty("publish_server", mediaHost); + ent.setValueForProperty("size", size.toString()); ent.update(); } catch (StorageObjectException e) { theLog.printError("StorageObjectException: "+e.toString()); @@ -99,11 +102,25 @@ public class MediaHandlerGeneric implements MirMedia return MirConfig.getProp("Producer.Icon.TinyText"); } + public String getBigIcon() + { + return MirConfig.getProp("Producer.Icon.BigText"); + } + public String getIconAlt() { return "Generic media"; } + public String getURL(Entity ent, Entity mediaTypeEnt) + { + String title = ent.getValue("title")+ + " - "+mediaTypeEnt.getValue("name")+" "+ + ent.getValue("size")+" Bytes"; + return StringUtil.createURLLinks(ent.getValue("publish_server")+ + ent.getValue("publish_path"), title, imageRoot, getBigIcon()); + } + public boolean isVideo() { return false; diff --git a/source/mir/media/MediaHandlerImages.java b/source/mir/media/MediaHandlerImages.java index d1f96f84..52293d8f 100755 --- a/source/mir/media/MediaHandlerImages.java +++ b/source/mir/media/MediaHandlerImages.java @@ -86,6 +86,14 @@ public class MediaHandlerImages return icon_data; } + public String getURL(Entity ent, Entity mediaTypeEnt) + { + String title = ent.getValue("title"); + return StringUtil.createIMGLinks(ent.getValue("publish_server")+ + ent.getValue("publish_path"), title, ent.getValue("img_height"), + ent.getValue("img_width")); + } + public String getStoragePath() { return MirConfig.getProp("Producer.Image.Path"); @@ -106,6 +114,11 @@ public class MediaHandlerImages return MirConfig.getProp("Producer.Icon.TinyImage"); } + public String getBigIcon () + { + return MirConfig.getProp("Producer.Icon.BigImage"); + } + public String getIconAlt () { return "Image"; diff --git a/source/mir/media/MirMedia.java b/source/mir/media/MirMedia.java index f57b45c1..f6c59b7e 100755 --- a/source/mir/media/MirMedia.java +++ b/source/mir/media/MirMedia.java @@ -26,10 +26,11 @@ public interface MirMedia{ public abstract boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ); public abstract byte[] get (Entity ent, Entity mediaTypeEnt); public abstract byte[] getIcon (Entity ent); - //public abstract String getURL (Entity ent); + public abstract String getURL (Entity ent, Entity mediaTypeEnt); public String getStoragePath (); public String getIconStoragePath (); public String getPublishHost (); + public String getBigIcon (); public String getTinyIcon (); public String getIconAlt (); public boolean isVideo (); diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index 2b700115..54d70c62 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -743,8 +743,8 @@ public final class StringUtil { return Math.min(i, j); } - /** - * Diese Routine macht aus links in reinem text browsbare links + /** + * This routine makes html links (href) out of text browseable urls * @param text * @return Konvertierter String */ @@ -847,21 +847,69 @@ public final class StringUtil { } /** - * createURLLinks wandelt text im url-format - * in einen klickbaren link um - * nur sinnvoll, wenn text nicht im html-format eingegeben + * this routine takes text in url format and makes + * a clickaeble "" link removing any "illegal" html tags + * @param haystack, the url + * @param title, the href link text + * @param imagRoot, the place to find icons + * @param extImage, the url of the icon to show next to the link + * @return a String containing the url */ - public static String createURLLinks(String haystack,String imageRoot,String extImage,String intImage) { + public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) { try { //dieser Ausdruck brauch dringend fachliche Beratung RE regex = new RE("((https://)|(http://)|(ftp://))+([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>]+[^ \t\r\n.,<>])"); - return regex.substituteAll(haystack," $0"); + if (title == null) { + return regex.substituteAll(haystack," $0"); + } else { + title = removeHTMLTags(title); + return regex.substituteAll(haystack," "+title+""); + } } catch(REException ex){ return null; } } /** + * this routine takes text in url format and makes + * a clickaeble "" link removing any "illegal" html tags + * @param haystack, the url + * @param imageRoot, the place to find icons + * @param extImage, the url of the icon to show next to the link + * @param intImage, unused + * @return a String containing the url + */ + public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) { + return createURLLinks(haystack, title, imageRoot, extImage); + } + + /** + * this routine takes text in url format and makes + * an image link removing any "illegal" html tags + * @param haystack, the url + * @param title, the image alt text, can be null + * @param height, height of the image + * @param width, width of the image + * @return a String containing the url + */ + public static String createIMGLinks(String haystack, String title, String height,String width) { + try { + //dieser Ausdruck brauch dringend fachliche Beratung + RE regex = new RE("((https://)|(http://)|(ftp://))+([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>]+[^ \t\r\n.,<>])"); + if (title != null) { + title = removeHTMLTags(title); + return regex.substituteAll(haystack,"\""+title+"\"/ 
"+title+""); + } else { + return regex.substituteAll(haystack,"\"\"/ "); + } + } catch(REException ex){ + return null; + } + } + + + + /** * deleteForbiddenTags * this method deletes all