X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleOpenIndy.java;h=53694f2a82ef0f43c8a6c6190757cde5da9b5d32;hb=574a7677790a9cdafda0bbeba4d262abfbf3470e;hp=be5d5a93ce6a0f9f5743c73ae49617f2e31472e3;hpb=86b6f499b413c722acc895346ac5186405b0c44c;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index be5d5a93..53694f2a 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -3,6 +3,8 @@ package mircoders.servlet; import java.io.*; import java.sql.*; import java.util.*; +import java.net.*; +import java.lang.reflect.*; import javax.servlet.*; import javax.servlet.http.*; @@ -15,6 +17,7 @@ import mir.module.*; import mir.misc.*; import mir.entity.*; import mir.storage.*; +import mir.media.*; import mircoders.entity.*; import mircoders.storage.*; @@ -33,10 +36,11 @@ import mircoders.producer.*; public class ServletModuleOpenIndy extends ServletModule { - private String commentFormTemplate, commentFormDoneTemplate; + private String commentFormTemplate, commentFormDoneTemplate, commentFormDupeTemplate; private String postingFormTemplate, postingFormDoneTemplate; private ModuleContent contentModule; private ModuleImages imageModule; + private ModuleTopics themenModule; private String directOp ="yes"; // Singelton / Kontruktor @@ -48,12 +52,13 @@ public class ServletModuleOpenIndy extends ServletModule theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.OpenIndy.Logfile")); commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate"); commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate"); + commentFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDupeTemplate"); 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()); + themenModule = new ModuleTopics(DatabaseTopics.getInstance()); imageModule = new ModuleImages(DatabaseImages.getInstance()); defaultAction="addposting"; } @@ -95,20 +100,28 @@ public class ServletModuleOpenIndy extends ServletModule HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance()); withValues.put("is_published","1"); - // inserting into database - String id = mainModule.add(withValues); - - // producing new page - new ProducerContent().handle(null, null, true, false, aid); - - // sync the server - int exitValue = Helper.rsync(); - theLog.printDebugInfo("rsync:"+exitValue); - - // redirecting to url - // should implement back to article - SimpleHash mergeData = new SimpleHash(); - deliver(req, res, mergeData, commentFormDoneTemplate); + // Dupe detection +// EntityList com = mainModule.getByWhereClause("description='"+req.getParameter("description")+"' AND to_media='"+aid+"' AND creator='"+req.getParameter("creator")+"'", 0); +// if (com.getCount() > 0) { +// theLog.printDebugInfo("Comment dupe dropped for article "+aid); +// deliver(req, res, (TemplateModelRoot) null, commentFormDupeTemplate); +// } else { + + // inserting into database + String id = mainModule.add(withValues); + + // producing new page + new ProducerContent().handle(null, null, true, false, aid); + + // sync the server + int exitValue = Helper.rsync(); + theLog.printDebugInfo("rsync:"+exitValue); + + // redirecting to url + // should implement back to article + SimpleHash mergeData = new SimpleHash(); + deliver(req, res, mergeData, commentFormDoneTemplate); +// } } catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} catch (ModuleException e) { throw new ServletModuleException(e.toString());} @@ -125,6 +138,22 @@ 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 +185,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 +192,147 @@ public class ServletModuleOpenIndy extends ServletModule withValues.put("creator","Anonym"); // inserting content into database - String id = 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"); - } + String cid = contentModule.add(withValues); + + String[] to_topicsArr = mp.getParameterValues("to_topic"); + if (to_topicsArr != null && to_topicsArr.length > 0) { + try{ + DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr); + theLog.printError("setting content_x_topic success"); + } catch (Exception e) { + theLog.printError("setting content_x_topic failed"); + } //end try + } //end if + + // if op contains uploaddata + String mediaId=null; + int i=1; + for(Iterator it = mp.requestList.iterator(); it.hasNext();){ + MpRequest mpReq = (MpRequest)it.next(); + String fileName = mpReq.getFilename(); + String contentType = FileUtil.guessContentTypeFromName(fileName); + HashMap mediaValues = new HashMap(); + theLog.printError("CONTENT TYPE IS: "+contentType); - // producing new page - if(mediaId!=null){ - new ProducerImages().handle(null, null, false, false, mediaId); + 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("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 (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); + 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) { + 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_media success"); + } catch (Exception e) { + theLog.printError("setting content_x_media failed"); + } + + // producing new page + if(mediaId!=null){ + new ProducerImages().handle(null, null, false, false, mediaId); + } + } else { + theLog.printDebugInfo("Wrong file uploaded!" + fileName); + } + } + }*/ } + // 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 +340,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); }