( 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..
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" (
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
+
#
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()
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");
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)) {
//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());
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;
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");
return MirConfig.getProp("Producer.Icon.TinyImage");
}
+ public String getBigIcon ()
+ {
+ return MirConfig.getProp("Producer.Icon.BigImage");
+ }
+
public String getIconAlt ()
{
return "Image";
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 ();
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
*/
}
/**
- * 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 "<href>" 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,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">$0</a>");
+ if (title == null) {
+ return regex.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">$0</a>");
+ } else {
+ title = removeHTMLTags(title);
+ return regex.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">"+title+"</a>");
+ }
} catch(REException ex){
return null;
}
}
/**
+ * this routine takes text in url format and makes
+ * a clickaeble "<href>" 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,"<img src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\""+title+"\"/> <br><i>"+title+"</i>");
+ } else {
+ return regex.substituteAll(haystack,"<img src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\"\"/> ");
+ }
+ } catch(REException ex){
+ return null;
+ }
+ }
+
+
+
+ /**
* deleteForbiddenTags
* this method deletes all <script>, <body> and <head>-tags
*/
content=convertNewline2Break(content);
content=convertNewline2P(content);
content=createMailLinks(content,producerDocRoot,mailImage);
- content=createURLLinks(content,producerDocRoot,extImage,intImage);
+ content=createURLLinks(content,null,producerDocRoot,extImage,intImage);
return content;
}
*/
public class AbstractModule {
protected StorageObject theStorage;
- protected Logfile theLog;
public void setStorage(StorageObject storage) {
this.theStorage = storage;
try {
if (theStorage == null)
throw new ModuleException("Kein StorageObject gesetzt");
- theLog = Logfile.getInstance(MirConfig.getProp("Home") + "log/media.log");
- theLog.printError("aboot to run getByWhere...");
return theStorage.selectByWhereClause(whereClause, offset);
}
catch (StorageObjectException e){
import java.io.*;
import java.lang.*;
+import java.lang.reflect.*;
import java.util.*;
import freemarker.template.*;
import mir.misc.*;
+import mir.media.*;
import mir.storage.*;
import mir.module.*;
import mir.entity.*;
HashMap currentContentValues;
SimpleHash imageHash = new SimpleHash();
EntityUsers userEntity=null;
+ Entity mediaType;
+ Entity upMedia;
+ SimpleHash upMediaSimpleHash;
+ Class mediaHandlerClass;
+ Class mediaStorageClass;
+ String mediaStorageName;
+ String mediaHandlerName=null;
+ MirMedia mediaHandler=null;
+ Database mediaStorage=null;
//create the freemarker-model
SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
- // get the images
- EntityList currentMedia = DatabaseContentToMedia.getInstance().getImages(currentContent);
- if (currentMedia!=null && currentMedia.getCount()>=1) {
- SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia);
+ // get the uploaded media
+ EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
+ if (currentMediaList!=null && currentMediaList.getCount()>=1) {
+ SimpleList mediaList = new SimpleList();
+ for (int n=0; n < currentMediaList.size();n++) {
+ upMedia = currentMediaList.elementAt(n);
+ upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
+ mediaType = ((EntityUploadedMedia)upMedia).getMediaType();
+ //must be a non-existant to_media_type entry..
+ if (mediaType != null) {
+ try {
+ mediaHandlerName = mediaType.getValue("classname");
+ mediaStorageName = mediaType.getValue("tablename");
+ mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
+ mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+ mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
+ if(!mediaStorageName.equals(new String("UploadedMedia"))) {
+ Method m = mediaStorageClass.getMethod("getInstance", null);
+ mediaStorage = (Database)m.invoke(null, null);
+ //we most likely need further info
+ upMedia = mediaStorage.selectById(upMedia.getId());
+ }
+ } catch (Exception e) {
+ theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName);
+ } //end catch
+ upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
+ mediaList.add(upMediaSimpleHash);
+ } //end if media_type != null
+ } //end for
mergeData.put("to_media", mediaList);
- }
+ } //end if currentMediaList != null
// get the comments for the article
mergeData.put("comments", currentContent.getComments());
mediaEnt.setValues(mediaValues);
mediaId = mediaEnt.insert();
- theLog.printError("done inserting!!! ");
Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
MirMedia mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
mediaHandler.set(mpReq.getMedia(), mediaEnt,mediaTypesList.elementAt(0));
public Entity getMediaType(Entity ent) {
Entity type=null;
try {
- theLog.printError("about to run relationMediaType");
type = relationMediaType.getOne(ent);
}
catch (StorageObjectException e) {
<h2>${title}</h2>
<h4><i>${creator}, ${webdb_create_formatted}</i></h4>
<p><b>${description}</b>
- <!-- images -->
- <list to_media as images>
+ <!-- media -->
+ <list to_media as media>
<p>
- <if images && images["is_published"]=="1">
- <img src="${imageHost}/${images["id"]}.jpg" width="${images["img_width"]}" height="${images["img_height"]}" alt="${images["title"]}">
- </if><br><i>${images["title"]}</i>
+ <if media && media["is_published"]=="1">
+ ${media["url"]}
+ </if>
</p>
</list>
- <!-- images -->
+ <!-- media -->
<p>${content_data}</p>
<if creator_main_url || creator_email>
<table width="100%" bgcolor="#FFFFFF">