From 07406c649982d8496617dfbf92097a27705303c2 Mon Sep 17 00:00:00 2001 From: idfx Date: Tue, 18 Sep 2001 16:45:32 +0000 Subject: [PATCH] mutlifile-upload in openmir --- source/mir/misc/Configuration.java | 24 +- source/mir/misc/MirConfig.java | 33 +- source/mir/misc/MpRequest.java | 43 ++ source/mir/misc/WebdbMultipartRequest.java | 26 +- source/mir/servlet/ServletModuleDispatch.java | 98 ++-- source/mircoders/producer/ProducerContent.java | 14 +- source/mircoders/servlet/ServletModuleImages.java | 588 +++++++++++---------- .../mircoders/servlet/ServletModuleOpenIndy.java | 146 ++--- .../mircoders/storage/DatabaseContentToMedia.java | 84 +-- templates-dist/de/open/posting.template | 24 +- templates-dist/en/open/posting.template | 24 +- templates-dist/producer/content.template | 14 +- templates-dist/producer/startpage.template | 15 +- 13 files changed, 609 insertions(+), 524 deletions(-) create mode 100755 source/mir/misc/MpRequest.java diff --git a/source/mir/misc/Configuration.java b/source/mir/misc/Configuration.java index 43bd06ff..d7e208a9 100755 --- a/source/mir/misc/Configuration.java +++ b/source/mir/misc/Configuration.java @@ -1,8 +1,3 @@ -/* - * put your module comment here - */ - - package mir.misc; import java.net.*; @@ -16,9 +11,7 @@ import java.lang.*; * */ public class Configuration { - - private static int instances=0; - + private static HashMap confs = new HashMap(); // key: conffilename, confHash private String confFilename; @@ -31,7 +24,7 @@ public class Configuration { } protected static Enumeration getResourceKeys() { - return conf.getKeys(); + return conf.getKeys(); } @@ -106,22 +99,11 @@ public class Configuration { } /** - * Liefert Hashtabel mit den Konfigurationen + * Liefert Hashtable mit den Konfigurationen * @return */ public static HashMap getConfs(){ return confs; } - - /** - * Finalize Methode - */ - protected void finalize(){ - instances --; - try { - super.finalize(); - } catch (Throwable t) {} - } - } //end of class diff --git a/source/mir/misc/MirConfig.java b/source/mir/misc/MirConfig.java index 2aa322c5..07676e77 100755 --- a/source/mir/misc/MirConfig.java +++ b/source/mir/misc/MirConfig.java @@ -1,8 +1,3 @@ -/* - * put your module comment here - */ - - package mir.misc; import javax.servlet.http.*; @@ -14,7 +9,7 @@ import com.javaexchange.dbConnectionBroker.*; /** * Title: Mir - * Description: Class that allows access to all Mir + * Description: Class that allows access to all Mir * config values * Copyright: Copyright (c) 2001 * Company: Indymedia @@ -25,7 +20,7 @@ import com.javaexchange.dbConnectionBroker.*; /** * This class is a layer above the Configuration - * It manages access to config variables that are + * It manages access to config variables that are * both generated on the fly and found in the config file. */ @@ -33,27 +28,26 @@ public class MirConfig extends Configuration { private static HashMap configHash = new HashMap(); private static HashMap brokerHash = new HashMap(); - private static int instances=0; /** * Initializes Configuration hash that contains all values. - * loads the config.properties file and any other values - * @param Uri, the root Uri of the install - * @param Home, The absolute path if the install root. - * @param Name, The name of the servlet (usually "Mir") + * loads the properties-file and any other values + * @param uri, the root Uri of the install + * @param home, The absolute path if the install root. + * @param name, The name of the servlet (usually "Mir") * @param confName, the name of the config file to load. */ - public static void initConfig(String Home, String Uri, String Name, String confName) { + public static void initConfig(String home, String uri, String name, String confName) { initConfResource(confName); - configHash.put("Home", Home); - configHash.put("RootUri", Uri); - configHash.put("ServletName", Name); + configHash.put("Home", home); + configHash.put("RootUri", uri); + configHash.put("ServletName", name); - Enumeration ResKeys = getResourceKeys(); - while(ResKeys.hasMoreElements()) { - String keyNm = (String)ResKeys.nextElement(); + Enumeration resKeys = getResourceKeys(); + while(resKeys.hasMoreElements()) { + String keyNm = (String)resKeys.nextElement(); configHash.put(keyNm, getProperty(keyNm)); } } @@ -136,5 +130,4 @@ public class MirConfig extends Configuration { } catch (Throwable t) {} } - } diff --git a/source/mir/misc/MpRequest.java b/source/mir/misc/MpRequest.java new file mode 100755 index 00000000..fc191e2e --- /dev/null +++ b/source/mir/misc/MpRequest.java @@ -0,0 +1,43 @@ + /** + * Datamodel of a MulitpartRequest + * (inner class) + */ + +package mir.misc; + + +public class MpRequest{ + byte[] uploadData=null; + String fileName=null; + String fileContentType=null; + + public MpRequest(byte[] i_uploadData, String i_fileName, String i_contentType){ + setFilename(i_fileName); + setContentType(i_contentType); + setMedia(i_uploadData); + } + + public byte[] getMedia() { + return uploadData; + } + + public String getFilename() { + return fileName; + } + + public String getContentType() { + return fileContentType; + } + + public void setMedia(byte[] i_uploadData) { + uploadData=i_uploadData; + } + + public void setFilename(String i_fileName) { + fileName=i_fileName; + } + + public void setContentType(String i_contentType) { + fileContentType=i_contentType; + } +} diff --git a/source/mir/misc/WebdbMultipartRequest.java b/source/mir/misc/WebdbMultipartRequest.java index c889c919..8e61acda 100755 --- a/source/mir/misc/WebdbMultipartRequest.java +++ b/source/mir/misc/WebdbMultipartRequest.java @@ -21,14 +21,13 @@ public class WebdbMultipartRequest HttpServletRequest req=null; HashMap parameters = new HashMap(); MultipartParser mp=null; - byte[] uploadData=null; - String fileName=null; - String fileContentType=null; + public static ArrayList requestList; public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException { req=theReq; mp = new MultipartParser(req, 1024*8192); // maximum eight megabyte + requestList = new ArrayList(); _evaluateRequest(); } @@ -37,21 +36,11 @@ public class WebdbMultipartRequest return parameters; } - public byte[] getMedia() { - return uploadData; - } - - public String getFilename() { - return fileName; - } - - public String getContentType() { - return fileContentType; - } private void _evaluateRequest() throws IOException{ Part part; + int i = 0; while ((part = mp.readNextPart()) != null) { String name = part.getName(); if (part.isParam()) { @@ -63,14 +52,15 @@ public class WebdbMultipartRequest else if (part.isFile()) { // nur das erste uploadfile beruecksichtigen FilePart filePart = (FilePart) part; - fileName = filePart.getFileName(); - fileContentType = filePart.getContentType(); - if (fileName != null) { + String fn = filePart.getFileName(); + if (filePart.getFileName() != null) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); filePart.writeTo(byteStream); - uploadData=byteStream.toByteArray(); + requestList.add(i,new MpRequest(byteStream.toByteArray(),filePart.getFileName(),filePart.getContentType())); + i++; } } } // while */ } + } diff --git a/source/mir/servlet/ServletModuleDispatch.java b/source/mir/servlet/ServletModuleDispatch.java index 8490f10c..a8efff34 100755 --- a/source/mir/servlet/ServletModuleDispatch.java +++ b/source/mir/servlet/ServletModuleDispatch.java @@ -16,60 +16,60 @@ import mir.misc.*; */ public final class ServletModuleDispatch { - static Logfile theLog; + static Logfile theLog; - static { - theLog = Logfile.getInstance("/tmp/smod.dispatch"); - } + static { + theLog = Logfile.getInstance("/tmp/smod.dispatch"); + } - /** - * privater Konstruktor, um versehentliche Instantiierung zu verhindern - */ - private ServletModuleDispatch () { - } + /** + * privater Konstruktor, um versehentliche Instantiierung zu verhindern + */ + private ServletModuleDispatch () { + } - /** - * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule - * mit dem per HttpServletRequest angegebenen Paramter do auf. - * Ist kein Parameter angegeben, so wird versucht, in die defaultAction - * des ServletModules zu springen. - * - * @param req Http-Request, das vom Dispatcher an die Methode des - * ServletModules durchgereicht wird - * @param res Http-Response, die vom Dispatcher an die Methode des - * ServletModules durchgereicht wird - * @param sMod ServletModule, an das dispatched wird. - * @param mod Name des Modules als String (für Logfile) - */ + /** + * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule + * mit dem per HttpServletRequest angegebenen Paramter do auf. + * Ist kein Parameter angegeben, so wird versucht, in die defaultAction + * des ServletModules zu springen. + * + * @param req Http-Request, das vom Dispatcher an die Methode des + * ServletModules durchgereicht wird + * @param res Http-Response, die vom Dispatcher an die Methode des + * ServletModules durchgereicht wird + * @param sMod ServletModule, an das dispatched wird. + * @param mod Name des Modules als String (für Logfile) + */ - public static void dispatch(ServletModule sMod, HttpServletRequest req, - HttpServletResponse res) throws ServletModuleException - { - //sMod.predeliver(req,res); + public static void dispatch(ServletModule sMod, HttpServletRequest req, + HttpServletResponse res) throws ServletModuleException + { + //sMod.predeliver(req,res); - String doParam = req.getParameter("do"); - theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam); - if (doParam == null) { - if (sMod.defaultAction() != null) doParam = sMod.defaultAction(); - else throw new ServletModuleException("no parameter do supplied!"); - } + String doParam = req.getParameter("do"); + theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam); + if (doParam == null) { + if (sMod.defaultAction() != null) doParam = sMod.defaultAction(); + else throw new ServletModuleException("no parameter do supplied!"); + } - Class[] params= { HttpServletRequest.class, HttpServletResponse.class}; + Class[] params= { HttpServletRequest.class, HttpServletResponse.class}; - try { - Method method = sMod.getClass().getMethod(doParam,params); - if (method != null) { - method.invoke(sMod,new Object[] {req,res} ); - return; - } - else theLog.printDebugInfo("method lookup unsuccesful"); - } - catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());} - catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());} - catch ( InvocationTargetException e) {throw new ServletModuleException("target method exception!" + e.getTargetException().toString());} - catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());} -// catch ( Exception e ) { throw new ServletModuleException(e.toString()); } + try { + Method method = sMod.getClass().getMethod(doParam,params); + if (method != null) { + method.invoke(sMod,new Object[] {req,res} ); + return; + } + else theLog.printDebugInfo("method lookup unsuccesful"); + } + catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());} + catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());} + catch ( InvocationTargetException e) {e.printStackTrace();throw new ServletModuleException("target method exception!" + e.getTargetException().toString());} + catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());} +// catch ( Exception e ) { throw new ServletModuleException(e.toString()); } - throw new ServletModuleException("delivery failed! -- "); - } -} \ No newline at end of file + throw new ServletModuleException("delivery failed! -- "); + } +} diff --git a/source/mircoders/producer/ProducerContent.java b/source/mircoders/producer/ProducerContent.java index ceb8e7f9..2d58b076 100755 --- a/source/mircoders/producer/ProducerContent.java +++ b/source/mircoders/producer/ProducerContent.java @@ -137,18 +137,18 @@ public class ProducerContent extends Producer { SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues); // get the images - EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(currentContent); - if (currentMedia!=null && currentMedia.getCount()>=1) { - SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia); - mergeData.put("to_media", mediaList); - } - /** + EntityList currentMedia = DatabaseContentToMedia.getInstance().getImages(currentContent); + if (currentMedia!=null && currentMedia.getCount()>=1) { + SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia); + mergeData.put("to_media", mediaList); + } + /** currentMediaId = currentContent.getValue("to_media"); if (currentMediaId!=null && !currentMediaId.equals("")) { imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId))); } mergeData.put("images", imageHash); - */ + */ // get the comments for the article mergeData.put("comments", currentContent.getComments()); diff --git a/source/mircoders/servlet/ServletModuleImages.java b/source/mircoders/servlet/ServletModuleImages.java index 8e4d19e3..8ead0ef4 100755 --- a/source/mircoders/servlet/ServletModuleImages.java +++ b/source/mircoders/servlet/ServletModuleImages.java @@ -32,297 +32,303 @@ import mircoders.module.*; public class ServletModuleImages extends mir.servlet.ServletModule { - private static ModuleMediafolder mediafolderModule; - private static DatabaseRights dbRights; - private static DatabaseImageFormat dbImageFormat; - private static DatabaseImageType dbImageType; - private static DatabaseImageColor dbImageColor; - private static DatabaseImageLayout dbImageLayout; - - // Singelton / Kontruktor - private static ServletModuleImages instance = new ServletModuleImages(); - public static ServletModule getInstance() { return instance; } - - - private ServletModuleImages() { - theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Bilder.Logfile")); - templateListString = MirConfig.getProp("ServletModule.Bilder.ListTemplate"); - templateObjektString = MirConfig.getProp("ServletModule.Bilder.ObjektTemplate"); - templateConfirmString = MirConfig.getProp("ServletModule.Bilder.ConfirmTemplate"); - try { - mainModule = new ModuleImages(DatabaseImages.getInstance()); - mediafolderModule = new ModuleMediafolder(DatabaseMediafolder.getInstance()); - dbRights = DatabaseRights.getInstance(); - dbImageFormat = DatabaseImageFormat.getInstance(); - dbImageColor = DatabaseImageColor.getInstance(); - dbImageType = DatabaseImageType.getInstance(); - dbImageLayout = DatabaseImageLayout.getInstance(); - } - catch (StorageObjectException e) { - theLog.printDebugInfo("servletmodulebilder konnte nicht initialisiert werden"); - } - } - - - public void insert(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - try { - WebdbMultipartRequest mp = new WebdbMultipartRequest(req); - HashMap parameters = mp.getParameters(); - byte[] imageData=mp.getMedia(); - String fileName=mp.getFilename(); - - EntityUsers user = _getUser(req); - parameters.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); - parameters.put("to_publisher", user.getId()); - parameters.put("is_produced", "0"); - if (!parameters.containsKey("is_published")) - parameters.put("is_published","0"); - - String id = mainModule.add(parameters); - EntityImage entImage = (EntityImage)mainModule.getById(id); - - if (imageData!=null && fileName!=null) { - int fileType = -1; - if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; - if (fileName.toLowerCase().endsWith(".gif")) fileType=1; - if (fileType>=0) - entImage.setImage(imageData, fileType); - else - theLog.printError("Wrong file uploaded!"); - } - _edit(id, req, res); - } - catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());} - catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());} - - } - - public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - - try { - WebdbMultipartRequest mp = new WebdbMultipartRequest(req); - HashMap parameters = mp.getParameters(); - byte[] imageData=mp.getMedia(); - String fileName=mp.getFilename(); - - EntityUsers user = _getUser(req); - parameters.put("to_publisher", user.getId()); - parameters.put("is_produced", "0"); - if (!parameters.containsKey("is_published")) - parameters.put("is_published","0"); - - String id = mainModule.set(parameters); - EntityImage entImage = (EntityImage)mainModule.getById(id); - - if (imageData!=null && fileName!=null) { - int fileType = -1; - if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; - if (fileName.toLowerCase().endsWith(".gif")) fileType=1; - if (fileType>=0) - entImage.setImage(imageData, fileType); - else - theLog.printError("Wrong file uploaded!"); - } - _edit(id, req, res); - } - catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());} - catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());} - - } - - - public void showimg(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - String idParam = req.getParameter("id"); - if (idParam!=null && !idParam.equals("")) { - try { - EntityImage entImage =(EntityImage)mainModule.getById(idParam); - res.setContentType("image/jpeg"); // testweise - ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist - - byte[] outbytes = entImage.getImage(); - out.write(outbytes); - out.close(); - } - - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (ModuleException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} - } - else theLog.printDebugInfo("id nicht angeben."); - // darf keine exception werfen - } - - public void showicon(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - String idParam = req.getParameter("id"); - if (idParam!=null && !idParam.equals("")) { - try { - EntityImage entImage =(EntityImage)mainModule.getById(idParam); - res.setContentType("image/jpeg"); // testweise - ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist - - byte[] outbytes = entImage.getIcon(); - out.write(outbytes); - out.close(); - } - - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (ModuleException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} - } - else throw new ServletModuleException("id nicht angeben."); - } - - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - // Parameter auswerten - SimpleHash mergeData = new SimpleHash(); - String query_text = req.getParameter("query_text"); - mergeData.put("query_text",query_text); - if (query_text!=null) mergeData.put("query_text_encoded",URLEncoder.encode(query_text)); - String query_field = req.getParameter("query_field"); - mergeData.put("query_field",query_field); - String query_is_published = req.getParameter("query_is_published"); - mergeData.put("query_is_published",query_is_published); - String query_media_folder = req.getParameter("query_media_folder"); - mergeData.put("query_media_folder",query_media_folder); - String offset = req.getParameter("offset"); - if (offset==null || offset.equals("")) offset="0"; - mergeData.put("offset",offset); - - String order = req.getParameter("order"); - if (order==null) order="webdb_lastchange desc"; - - // if in connection mode to content - String cid = req.getParameter("cid"); - mergeData.put("cid",cid); - - - // sql basteln - String whereClause=""; boolean isFirst=true; - if (query_text!=null && !query_text.equalsIgnoreCase("")) { - whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;} - if (query_is_published != null && !query_is_published.equals("")) { - if (isFirst==false) whereClause+=" and "; - whereClause += "is_published='"+query_is_published+"'"; - isFirst=false; - } - if (query_media_folder != null && !query_media_folder.equals("")) { - if (isFirst==false) whereClause+=" and "; - whereClause += "to_media_folder='"+query_media_folder+"'"; - } - //theLog.printDebugInfo("sql-whereclause: " + whereClause + " order: " + order + " offset: " + offset); - - // fetch und ausliefern - try { - mergeData.put("mediafolderPopupData", mediafolderModule.getPopupData()); - mergeData.put("mediafolderHashdata", mediafolderModule.getHashData()); - if (query_text!=null || query_is_published!=null || query_media_folder!=null) { - EntityList theList = mainModule.getByWhereClause(whereClause, order, (new Integer(offset)).intValue(),10); - if (theList != null) { - mergeData.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList)); - if(theList.getOrder()!=null) { - mergeData.put("order", theList.getOrder()); - mergeData.put("order_encoded", URLEncoder.encode(theList.getOrder())); - } - mergeData.put("count", (new Integer(theList.getCount())).toString()); - mergeData.put("from", (new Integer(theList.getFrom())).toString()); - mergeData.put("to", (new Integer(theList.getTo())).toString()); - if (theList.hasNextBatch()) - mergeData.put("next", (new Integer(theList.getNextBatch())).toString()); - if (theList.hasPrevBatch()) - mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString()); - } - } - // raus damit - HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); - } - catch (ModuleException e) {throw new ServletModuleException(e.toString());} - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} - } - - - public void add(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - try { - SimpleHash mergeData = new SimpleHash(); - mergeData.put("new", "1"); - mergeData.put("mediafolderPopupData", mediafolderModule.getPopupData()); - deliver(req, res, mergeData, templateObjektString); - } - catch (Exception e) { throw new ServletModuleException(e.toString());} - } - - public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - String idParam = req.getParameter("id"); - _edit(idParam, req, res); - } - - private void _edit(String idParam, HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { - if (idParam!=null && !idParam.equals("")) { - try { - SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(mainModule.getById(idParam)); - mergeData.put("mediafolderPopupData", mediafolderModule.getPopupData()); - mergeData.put("rightsHashdata", dbRights.getHashData()); - mergeData.put("imgformatHashdata", dbImageFormat.getHashData()); - mergeData.put("imgcolorHashdata", dbImageColor.getHashData()); - mergeData.put("imgtypeHashdata", dbImageType.getHashData()); - mergeData.put("imglayoutHashdata", dbImageLayout.getHashData()); - deliver(req, res, mergeData, templateObjektString); - } - catch (ModuleException e) { throw new ServletModuleException(e.toString());} - } - else throw new ServletModuleException("ServletmoduleImage :: _edit without id"); - } - - - /** @todo should be in ServletModule.java */ - private EntityUsers _getUser(HttpServletRequest req) - { - HttpSession session=req.getSession(false); - return (EntityUsers)session.getAttribute("login.uid"); - } - - - // deprecated - public void upload(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - //theLog.printDebugInfo("-- trying to upload"); - String idParam = req.getParameter("id"); - if (idParam!=null && !idParam.equals("")) { - try { - - WebdbMultipartRequest mp = new WebdbMultipartRequest(req); - HashMap withValues = mp.getParameters(); - byte[] imageData=mp.getMedia(); - String fileName=mp.getFilename(); - - int fileType = -1; - if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; - if (fileName.toLowerCase().endsWith(".gif")) fileType=1; - if (fileType>=0) { - EntityImage entImage = (EntityImage)mainModule.getById(idParam); - entImage.setImage(imageData, fileType); - } - else - theLog.printError("Wrong file uploaded!"); - } - catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());} - catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());} - } - else // keine id - throw new ServletModuleException("Keine id angegeben"); - edit(req,res); - } + private static ModuleMediafolder mediafolderModule; + private static DatabaseRights dbRights; + private static DatabaseImageFormat dbImageFormat; + private static DatabaseImageType dbImageType; + private static DatabaseImageColor dbImageColor; + private static DatabaseImageLayout dbImageLayout; + + // Singelton / Kontruktor + private static ServletModuleImages instance = new ServletModuleImages(); + public static ServletModule getInstance() { return instance; } + + + private ServletModuleImages() { + theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Bilder.Logfile")); + templateListString = MirConfig.getProp("ServletModule.Bilder.ListTemplate"); + templateObjektString = MirConfig.getProp("ServletModule.Bilder.ObjektTemplate"); + templateConfirmString = MirConfig.getProp("ServletModule.Bilder.ConfirmTemplate"); + try { + mainModule = new ModuleImages(DatabaseImages.getInstance()); + mediafolderModule = new ModuleMediafolder(DatabaseMediafolder.getInstance()); + dbRights = DatabaseRights.getInstance(); + dbImageFormat = DatabaseImageFormat.getInstance(); + dbImageColor = DatabaseImageColor.getInstance(); + dbImageType = DatabaseImageType.getInstance(); + dbImageLayout = DatabaseImageLayout.getInstance(); + } + catch (StorageObjectException e) { + theLog.printDebugInfo("servletmodulebilder konnte nicht initialisiert werden"); + } + } + + + public void insert(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + try { + WebdbMultipartRequest mp = new WebdbMultipartRequest(req); + HashMap parameters = mp.getParameters(); + MpRequest mpReq = (MpRequest)mp.requestList.get(0); + byte[] imageData=mpReq.getMedia(); + String fileName=mpReq.getFilename(); + String contentType= mpReq.getContentType(); + + EntityUsers user = _getUser(req); + parameters.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); + parameters.put("to_publisher", user.getId()); + parameters.put("is_produced", "0"); + if (!parameters.containsKey("is_published")) + parameters.put("is_published","0"); + + String id = mainModule.add(parameters); + EntityImage entImage = (EntityImage)mainModule.getById(id); + + if (imageData!=null && fileName!=null) { + int fileType = -1; + if (contentType.equals("image/jpeg")) fileType=0; + if (contentType.equals("image/gif")) fileType=1; + if (fileType>=0) + entImage.setImage(imageData, fileType); + else + theLog.printError("Wrong file uploaded!"); + } + _edit(id, req, res); + } + catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());} + catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());} + + } + + public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + + try { + WebdbMultipartRequest mp = new WebdbMultipartRequest(req); + HashMap parameters = mp.getParameters(); + MpRequest mpReq = (MpRequest)mp.requestList.get(0); + byte[] imageData=mpReq.getMedia(); + String fileName=mpReq.getFilename(); + String contentType=mpReq.getContentType(); + + EntityUsers user = _getUser(req); + parameters.put("to_publisher", user.getId()); + parameters.put("is_produced", "0"); + if (!parameters.containsKey("is_published")) + parameters.put("is_published","0"); + + String id = mainModule.set(parameters); + EntityImage entImage = (EntityImage)mainModule.getById(id); + + if (imageData!=null && fileName!=null) { + int fileType = -1; + if (contentType.equals("image/jpeg")) fileType=0; + if (contentType.equals("image/gif")) fileType=1; + if (fileType>=0) + entImage.setImage(imageData, fileType); + else + theLog.printError("Wrong file uploaded!"); + } + _edit(id, req, res); + } + catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());} + catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());} + + } + + + public void showimg(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { + String idParam = req.getParameter("id"); + if (idParam!=null && !idParam.equals("")) { + try { + EntityImage entImage =(EntityImage)mainModule.getById(idParam); + res.setContentType("image/jpeg"); // testweise + ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist + + byte[] outbytes = entImage.getImage(); + out.write(outbytes); + out.close(); + } + + catch (IOException e) {throw new ServletModuleException(e.toString());} + catch (ModuleException e) {throw new ServletModuleException(e.toString());} + catch (Exception e) {throw new ServletModuleException(e.toString());} + } + else theLog.printDebugInfo("id nicht angeben."); + // darf keine exception werfen + } + + public void showicon(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { + String idParam = req.getParameter("id"); + if (idParam!=null && !idParam.equals("")) { + try { + EntityImage entImage =(EntityImage)mainModule.getById(idParam); + res.setContentType("image/jpeg"); // testweise + ServletOutputStream out = res.getOutputStream(); // wichtig, dass vorher kein res.getwriter() gelaufen ist + + byte[] outbytes = entImage.getIcon(); + out.write(outbytes); + out.close(); + } + + catch (IOException e) {throw new ServletModuleException(e.toString());} + catch (ModuleException e) {throw new ServletModuleException(e.toString());} + catch (Exception e) {throw new ServletModuleException(e.toString());} + } + else throw new ServletModuleException("id nicht angeben."); + } + + public void list(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { + // Parameter auswerten + SimpleHash mergeData = new SimpleHash(); + String query_text = req.getParameter("query_text"); + mergeData.put("query_text",query_text); + if (query_text!=null) mergeData.put("query_text_encoded",URLEncoder.encode(query_text)); + String query_field = req.getParameter("query_field"); + mergeData.put("query_field",query_field); + String query_is_published = req.getParameter("query_is_published"); + mergeData.put("query_is_published",query_is_published); + String query_media_folder = req.getParameter("query_media_folder"); + mergeData.put("query_media_folder",query_media_folder); + String offset = req.getParameter("offset"); + if (offset==null || offset.equals("")) offset="0"; + mergeData.put("offset",offset); + + String order = req.getParameter("order"); + if (order==null) order="webdb_lastchange desc"; + + // if in connection mode to content + String cid = req.getParameter("cid"); + mergeData.put("cid",cid); + + + // sql basteln + String whereClause=""; boolean isFirst=true; + if (query_text!=null && !query_text.equalsIgnoreCase("")) { + whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;} + if (query_is_published != null && !query_is_published.equals("")) { + if (isFirst==false) whereClause+=" and "; + whereClause += "is_published='"+query_is_published+"'"; + isFirst=false; + } + if (query_media_folder != null && !query_media_folder.equals("")) { + if (isFirst==false) whereClause+=" and "; + whereClause += "to_media_folder='"+query_media_folder+"'"; + } + //theLog.printDebugInfo("sql-whereclause: " + whereClause + " order: " + order + " offset: " + offset); + + // fetch und ausliefern + try { + mergeData.put("mediafolderPopupData", mediafolderModule.getPopupData()); + mergeData.put("mediafolderHashdata", mediafolderModule.getHashData()); + if (query_text!=null || query_is_published!=null || query_media_folder!=null) { + EntityList theList = mainModule.getByWhereClause(whereClause, order, (new Integer(offset)).intValue(),10); + if (theList != null) { + mergeData.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList)); + if(theList.getOrder()!=null) { + mergeData.put("order", theList.getOrder()); + mergeData.put("order_encoded", URLEncoder.encode(theList.getOrder())); + } + mergeData.put("count", (new Integer(theList.getCount())).toString()); + mergeData.put("from", (new Integer(theList.getFrom())).toString()); + mergeData.put("to", (new Integer(theList.getTo())).toString()); + if (theList.hasNextBatch()) + mergeData.put("next", (new Integer(theList.getNextBatch())).toString()); + if (theList.hasPrevBatch()) + mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString()); + } + } + // raus damit + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter()); + } + catch (ModuleException e) {throw new ServletModuleException(e.toString());} + catch (IOException e) {throw new ServletModuleException(e.toString());} + catch (Exception e) {throw new ServletModuleException(e.toString());} + } + + + public void add(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { + try { + SimpleHash mergeData = new SimpleHash(); + mergeData.put("new", "1"); + mergeData.put("mediafolderPopupData", mediafolderModule.getPopupData()); + deliver(req, res, mergeData, templateObjektString); + } + catch (Exception e) { throw new ServletModuleException(e.toString());} + } + + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + String idParam = req.getParameter("id"); + _edit(idParam, req, res); + } + + private void _edit(String idParam, HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { + if (idParam!=null && !idParam.equals("")) { + try { + SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(mainModule.getById(idParam)); + mergeData.put("mediafolderPopupData", mediafolderModule.getPopupData()); + mergeData.put("rightsHashdata", dbRights.getHashData()); + mergeData.put("imgformatHashdata", dbImageFormat.getHashData()); + mergeData.put("imgcolorHashdata", dbImageColor.getHashData()); + mergeData.put("imgtypeHashdata", dbImageType.getHashData()); + mergeData.put("imglayoutHashdata", dbImageLayout.getHashData()); + deliver(req, res, mergeData, templateObjektString); + } + catch (ModuleException e) { throw new ServletModuleException(e.toString());} + } + else throw new ServletModuleException("ServletmoduleImage :: _edit without id"); + } + + + /** @todo should be in ServletModule.java */ + private EntityUsers _getUser(HttpServletRequest req) + { + HttpSession session=req.getSession(false); + return (EntityUsers)session.getAttribute("login.uid"); + } + + + // deprecated + public void upload(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + //theLog.printDebugInfo("-- trying to upload"); + String idParam = req.getParameter("id"); + if (idParam!=null && !idParam.equals("")) { + try { + + WebdbMultipartRequest mp = new WebdbMultipartRequest(req); + HashMap withValues = mp.getParameters(); + MpRequest mpReq = (MpRequest)mp.requestList.get(0); + byte[] imageData=mpReq.getMedia(); + String fileName=mpReq.getFilename(); + String contentType=mpReq.getContentType(); + + int fileType = -1; + if (contentType.equals("image/jpeg")) fileType=0; + if (contentType.equals("image/gif")) fileType=1; + if (fileType>=0) { + EntityImage entImage = (EntityImage)mainModule.getById(idParam); + entImage.setImage(imageData, fileType); + } + else + theLog.printError("Wrong file uploaded!"); + } + catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());} + catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());} + } + else // keine id + throw new ServletModuleException("Keine id angegeben"); + edit(req,res); + } } diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index be5d5a93..cc4e9267 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -51,7 +51,6 @@ public class ServletModuleOpenIndy extends ServletModule postingFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingTemplate"); postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate"); directOp = MirConfig.getProp("DirectOpenposting").toLowerCase(); - //directOp="yes"; mainModule = new ModuleComment(DatabaseComment.getInstance()); contentModule = new ModuleContent(DatabaseContent.getInstance()); imageModule = new ModuleImages(DatabaseImages.getInstance()); @@ -103,7 +102,7 @@ public class ServletModuleOpenIndy extends ServletModule // sync the server int exitValue = Helper.rsync(); - theLog.printDebugInfo("rsync:"+exitValue); + theLog.printDebugInfo("rsync:"+exitValue); // redirecting to url // should implement back to article @@ -125,6 +124,21 @@ public class ServletModuleOpenIndy extends ServletModule public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { SimpleHash mergeData = new SimpleHash(); + String numOfMedia = req.getParameter("medianum"); + if(numOfMedia==null||numOfMedia.equals("")){ + numOfMedia="1"; + } + + int mediaNum = Integer.parseInt(numOfMedia); + SimpleList mediaFields = new SimpleList(); + for(int i =0; i=0) { - entImage.setImage(mediaData, fileType); - setMedia=true; - } - else - theLog.printDebugInfo("Wrong file uploaded!" + fileName); - } - } - withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date"))); withValues.put("is_produced", "0"); @@ -201,7 +170,6 @@ public class ServletModuleOpenIndy extends ServletModule withValues.put("is_published","1"); // if op direct article-type == newswire if (directOp.equals("yes")) withValues.put("to_article_type","1"); - theLog.printDebugInfo("direct op: "+directOp); // owner is openposting user withValues.put("to_publisher","1"); @@ -209,25 +177,71 @@ public class ServletModuleOpenIndy extends ServletModule withValues.put("creator","Anonym"); // inserting content into database - String id = contentModule.add(withValues); + String cid = contentModule.add(withValues); - // inserting content and media id in table content_x_media - try{ - DatabaseContentToMedia.getInstance().setMedia(id,mediaId); - theLog.printError("setting content_x_topic success"); - } catch (Exception e) { - theLog.printError("setting content_x_topic failed"); + // if op contains uploaddata + String mediaId=null; + 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) + mediaTitle = (String)withValues.get("title"); + mediaValues.put("title",mediaTitle); + + if (fileName.toLowerCase().endsWith("rm")) { + // this is video !! + //theLog.printDebugInfo("--GOT VIDEO"); + EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance()); + entVideo.setValues(mediaValues); + mediaId = entVideo.insert(); + entVideo.setVideoData(mediaData); + } + else if (contentType.equals("image/jpeg") || contentType.equals("image/gif")) { + // this is image !! + mediaId = imageModule.add(mediaValues); + EntityImage entImage = (EntityImage)imageModule.getById(mediaId); + + int fileType = -1; + if (contentType.equals("image/jpeg")) fileType=0; + if (contentType.equals("image/gif")) fileType=1; + if (fileType>=0) { + entImage.setImage(mediaData, fileType); + // inserting content and media id in table content_x_media + try{ + DatabaseContentToMedia.getInstance().addMedia(cid,mediaId); + theLog.printError("setting content_x_topic success"); + } catch (Exception e) { + theLog.printError("setting content_x_topic failed"); + } + + // producing new page + if(mediaId!=null){ + new ProducerImages().handle(null, null, false, false, mediaId); + } + } else { + theLog.printDebugInfo("Wrong file uploaded!" + fileName); + } + } + } } - - // producing new page - if(mediaId!=null){ - new ProducerImages().handle(null, null, false, false, mediaId); - } // producing openpostinglist new ProducerOpenPosting().handle(null,null,false,false); // producing new page - new ProducerContent().handle(null, null, false, false,id); + new ProducerContent().handle(null, null, false, false,cid); //if direct op producing startpage if (directOp.equals("yes")) new ProducerStartPage().handle(null,null); @@ -235,12 +249,12 @@ public class ServletModuleOpenIndy extends ServletModule // sync the server //should be configureable int exitValue = Helper.rsync(); - theLog.printDebugInfo("rsync: "+exitValue); + theLog.printDebugInfo("rsync: "+exitValue); } - catch (IOException e) { throw new ServletModuleException(e.toString());} - catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} - catch (ModuleException e) { throw new ServletModuleException(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());} deliver(req, res, mergeData, postingFormDoneTemplate); } diff --git a/source/mircoders/storage/DatabaseContentToMedia.java b/source/mircoders/storage/DatabaseContentToMedia.java index e154fcb6..2f5b3b57 100755 --- a/source/mircoders/storage/DatabaseContentToMedia.java +++ b/source/mircoders/storage/DatabaseContentToMedia.java @@ -39,8 +39,11 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ this.hasTimestamp = false; this.theTable="content_x_media"; } - - + + /** + * get all the media-files belonging to a content entity + * + */ public EntityList getMedia(EntityContent content) { EntityList returnList=null; if (content != null) { @@ -57,6 +60,27 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ } return returnList; } + + /** + * get all the images belonging to a content entity + * + */ + public EntityList getImages(EntityContent content) { + EntityList returnList=null; + if (content != null) { + // get all to_topic from media_x_topic + String id = content.getId(); + //this is not supported by mysql + String subselect = "id in (select media_id from " + theTable + " where content_id=" + id+")"; + + try { + returnList = DatabaseImages.getInstance().selectByWhereClause(subselect,-1); + } catch (Exception e) { + theLog.printDebugInfo("-- get images failed " + e.toString()); + } + } + return returnList; + } public void setMedia(String contentId, String[] mediaId) { @@ -120,7 +144,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ freeConnection(con,stmt); } } - + public void setMedia(String contentId, String mediaId) { if (contentId == null && mediaId == null) { return; @@ -199,8 +223,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ freeConnection(con,stmt); } } - - public void delete(String contentId, String mediaId) { + + public void delete(String contentId, String mediaId) { if (mediaId == null || contentId==null) { theLog.printDebugInfo("-- delete media failed -- missing parameter"); return; @@ -254,39 +278,39 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ } return returnList; } - + /** * Returns a EntityList with all content-objects having a relation to a media */ - + public EntityList getContent() { EntityList returnList=null; String select = "select distinct content_id from " + theTable; - // execute select statement - Connection con=null;Statement stmt=null; - try { - con = getPooledCon(); - // should be a preparedStatement because is faster - stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,select); - if (rs!=null) { - String mediaSelect= "id IN ("; - boolean first=true; - while (rs.next()) { - if (first==false) mediaSelect+=","; - mediaSelect += rs.getString(1); - first=false; - } - mediaSelect+=")"; - if (first==false) - returnList = DatabaseContent.getInstance().selectByWhereClause(mediaSelect,"webdb_lastchange desc"); - } - } - catch (Exception e) {theLog.printDebugInfo("-- get content failed");} - finally { freeConnection(con,stmt);} + // execute select statement + Connection con=null;Statement stmt=null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + ResultSet rs = executeSql(stmt,select); + if (rs!=null) { + String mediaSelect= "id IN ("; + boolean first=true; + while (rs.next()) { + if (first==false) mediaSelect+=","; + mediaSelect += rs.getString(1); + first=false; + } + mediaSelect+=")"; + if (first==false) + returnList = DatabaseContent.getInstance().selectByWhereClause(mediaSelect,"webdb_lastchange desc"); + } + } + catch (Exception e) {theLog.printDebugInfo("-- get content failed");} + finally { freeConnection(con,stmt);} - return returnList; + return returnList; } } diff --git a/templates-dist/de/open/posting.template b/templates-dist/de/open/posting.template index 01063879..3b44d534 100755 --- a/templates-dist/de/open/posting.template +++ b/templates-dist/de/open/posting.template @@ -56,10 +56,15 @@ +
+ + Anzahl der Medien +   + +
-
Veröffentlichungsformular
@@ -161,19 +166,24 @@ Hier kannst Du ein Medien zu Deinem Artikel hochladen (bislang nur jpg-Bilder)
- (optional) + + + + + Bild ${m} + + (optional) - Medienunterschrift: + Medienunterschrift ${m}: - (optional) + (optional) - - - + +
diff --git a/templates-dist/en/open/posting.template b/templates-dist/en/open/posting.template index 01063879..3b44d534 100755 --- a/templates-dist/en/open/posting.template +++ b/templates-dist/en/open/posting.template @@ -56,10 +56,15 @@ + + + Anzahl der Medien +   + +
-
Veröffentlichungsformular
@@ -161,19 +166,24 @@ Hier kannst Du ein Medien zu Deinem Artikel hochladen (bislang nur jpg-Bilder)
- (optional) + + + + + Bild ${m} + + (optional) - Medienunterschrift: + Medienunterschrift ${m}: - (optional) + (optional) - - - + +
diff --git a/templates-dist/producer/content.template b/templates-dist/producer/content.template index ca8d8eff..13583dcf 100755 --- a/templates-dist/producer/content.template +++ b/templates-dist/producer/content.template @@ -54,10 +54,16 @@

${title}

${creator}, ${webdb_create_formatted}

-

${description}

-

- - ${s.description}

+

${description} + + +

+ + ${images[ +
${images["title"]} +

+ +

${content_data}

diff --git a/templates-dist/producer/startpage.template b/templates-dist/producer/startpage.template index 89a77a8e..7501769e 100755 --- a/templates-dist/producer/startpage.template +++ b/templates-dist/producer/startpage.template @@ -61,7 +61,8 @@
-
+ +
@@ -76,7 +77,9 @@

-
+ + + @@ -85,11 +88,15 @@
-

[Text] +

+ + [Text] ${n.title}
${n.webdb_create_formatted}

-

+ + +

-- 2.11.0