X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleOpenIndy.java;h=be5d5a93ce6a0f9f5743c73ae49617f2e31472e3;hb=86b6f499b413c722acc895346ac5186405b0c44c;hp=5d14c4af46b4abd2d4c40225259988c97a3f0e78;hpb=3a661e8f0f659ab5ed2ac0e4d982ac0b398d11f1;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 5d14c4af..be5d5a93 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -33,189 +33,217 @@ import mircoders.producer.*; public class ServletModuleOpenIndy extends ServletModule { - private String commentFormTemplate, commentFormDoneTemplate; - private String postingFormTemplate, postingFormDoneTemplate; - private ModuleContent contentModule; - private ModuleImages imageModule; - - // Singelton / Kontruktor - private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy(); - public static ServletModule getInstance() { return instance; } - - private ServletModuleOpenIndy() { - try { - theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.OpenIndy.Logfile")); - commentFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentTemplate"); - commentFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.CommentDoneTemplate"); - postingFormTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingTemplate"); - postingFormDoneTemplate = Configuration.getProperty("ServletModule.OpenIndy.PostingDoneTemplate"); - - mainModule = new ModuleComment(DatabaseComment.getInstance()); - contentModule = new ModuleContent(DatabaseContent.getInstance()); - imageModule = new ModuleImages(DatabaseImages.getInstance()); + private String commentFormTemplate, commentFormDoneTemplate; + private String postingFormTemplate, postingFormDoneTemplate; + private ModuleContent contentModule; + private ModuleImages imageModule; + private String directOp ="yes"; + + // Singelton / Kontruktor + private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy(); + public static ServletModule getInstance() { return instance; } + + private ServletModuleOpenIndy() { + try { + theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.OpenIndy.Logfile")); + commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate"); + commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate"); + 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()); defaultAction="addposting"; - } - catch (StorageObjectException e) { - theLog.printError("servletmoduleopenindy could not be initialized"); - } - } - - - /** - * Method for making a comment - */ - - public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - String aid = req.getParameter("aid"); // the article id the comment will belong to - if (aid!=null && !aid.equals("")) - { - SimpleHash mergeData = new SimpleHash(); - // ok, article - mergeData.put("aid", aid); - deliver(req, res, mergeData, commentFormTemplate); - } - else throw new ServletModuleException("aid not set!"); - } - - /** - * Method for inserting a comment into the Database and delivering - * the commentDone Page - */ - - public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - String aid = req.getParameter("to_media"); // the article id the comment will belong to - if (aid!=null && !aid.equals("")) - { - // ok, collecting data from form - try { - 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(); - - // 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());} - - } - else throw new ServletModuleException("aid not set!"); - - } - - /** - * Method for delivering the form-Page for open posting - */ - - public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException - { - SimpleHash mergeData = new SimpleHash(); - /** @todo popups missing */ - deliver(req, res, mergeData, postingFormTemplate); - } - - /** - * Method for inserting an open posting into the Database and delivering - * the postingDone Page - */ - - public void insposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - SimpleHash mergeData = new SimpleHash(); - - try { - - WebdbMultipartRequest mp = new WebdbMultipartRequest(req); - HashMap withValues = mp.getParameters(); - byte[] mediaData=mp.getMedia(); - String fileName=mp.getFilename(); - - // if op contains imagedata - String mediaId=null; - 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"); - 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 (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) { - // this is image !! - mediaId = imageModule.add(mediaValues); - EntityImage entImage = (EntityImage)imageModule.getById(mediaId); - - int fileType = -1; - if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; - if (fileName.toLowerCase().endsWith(".gif")) fileType=1; - if (fileType>=0) { - entImage.setImage(mediaData, fileType); - withValues.put("to_media",mediaId); - } - 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"); - // op-articles are immediatly published - withValues.put("is_published","1"); - // owner is openposting user - withValues.put("to_publisher","1"); + } + catch (StorageObjectException e) { + theLog.printError("servletmoduleopenindy could not be initialized"); + } + } + + + /** + * Method for making a comment + */ + + public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + String aid = req.getParameter("aid"); // the article id the comment will belong to + if (aid!=null && !aid.equals("")) + { + SimpleHash mergeData = new SimpleHash(); + // ok, article + mergeData.put("aid", aid); + deliver(req, res, mergeData, commentFormTemplate); + } + else throw new ServletModuleException("aid not set!"); + } + + /** + * Method for inserting a comment into the Database and delivering + * the commentDone Page + */ + + public void inscomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + String aid = req.getParameter("to_media"); // the article id the comment will belong to + if (aid!=null && !aid.equals("")) + { + // ok, collecting data from form + try { + 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); + } + catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} + catch (ModuleException e) { throw new ServletModuleException(e.toString());} + + } + else throw new ServletModuleException("aid not set!"); + + } + + /** + * Method for delivering the form-Page for open posting + */ + + public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + SimpleHash mergeData = new SimpleHash(); + /** @todo popups missing */ + try{ + mergeData.put("languagePopUpData",DatabaseLanguage.getInstance().getPopupData()); + } catch (Exception e) { + theLog.printError("languagePopUpData failed"); + } + deliver(req, res, mergeData, postingFormTemplate); + } + + /** + * Method for inserting an open posting into the Database and delivering + * the postingDone Page + */ + + public void insposting(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { + SimpleHash mergeData = new SimpleHash(); + boolean setMedia=false; + + try { + + WebdbMultipartRequest mp = new WebdbMultipartRequest(req); + HashMap withValues = mp.getParameters(); + byte[] mediaData=mp.getMedia(); + String fileName=mp.getFilename(); + + theLog.printDebugInfo("ContentType: "+mp.getContentType()); + + // if op contains imagedata + String mediaId=null; + 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"); + 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 (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".gif")) { + // this is image !! + mediaId = imageModule.add(mediaValues); + EntityImage entImage = (EntityImage)imageModule.getById(mediaId); + + int fileType = -1; + if (fileName.toLowerCase().endsWith(".jpg")) fileType=0; + if (fileName.toLowerCase().endsWith(".gif")) fileType=1; + if (fileType>=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"); + // op-articles are immediatly published + 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"); if (withValues.get("creator").toString().equals("")) - withValues.put("creator","Anonym"); - - // inserting content into database - String id = contentModule.add(withValues); - - - // 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); - - // sync the server - int exitValue = Helper.rsync(); - - } - catch (IOException e) { throw new ServletModuleException(e.toString());} - catch (StorageObjectException e) { throw new ServletModuleException(e.toString());} - catch (ModuleException e) { throw new ServletModuleException(e.toString());} - - deliver(req, res, mergeData, postingFormDoneTemplate); - } + 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"); + } + + + // 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); + //if direct op producing startpage + if (directOp.equals("yes")) new ProducerStartPage().handle(null,null); + + + // sync the server + //should be configureable + int exitValue = Helper.rsync(); + 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());} + + deliver(req, res, mergeData, postingFormDoneTemplate); + } }