X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleOpenIndy.java;h=b244ac97d27af29cf65cfd309b010fd62f973a92;hb=e42ecea2db8ff123f268edf48190d6b9b28fcedb;hp=2b8e4630d1b62d0eff1d4a3e74d1c4acf3f2e27e;hpb=7d85887f4fca0c14ac049ef357e83f7eb5738216;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 2b8e4630..b244ac97 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -34,6 +34,8 @@ import mircoders.storage.*; import mircoders.module.*; import mircoders.producer.*; import mircoders.media.MediaRequest; +import mircoders.global.*; +import mircoders.localizer.*; /* * ServletModuleOpenIndy - @@ -42,9 +44,12 @@ import mircoders.media.MediaRequest; * open-postings to the newswire * * @author $Author: mh $ - * @version $Revision: 1.38 $ $Date: 2002/07/21 22:50:14 $ + * @version $Revision: 1.39 $ $Date: 2002/08/25 19:00:11 $ * * $Log: ServletModuleOpenIndy.java,v $ + * Revision 1.39 2002/08/25 19:00:11 mh + * merge of localization branch into HEAD. mh and zap + * * Revision 1.38 2002/07/21 22:50:14 mh * cleanup coding style of getpdf() method * @@ -65,6 +70,7 @@ public class ServletModuleOpenIndy extends ServletModule private String postingFormTemplate, postingFormDoneTemplate, postingFormDupeTemplate; private ModuleContent contentModule; + private ModuleComment commentModule; private ModuleImages imageModule; private ModuleTopics themenModule; private String directOp ="yes"; @@ -83,13 +89,13 @@ public class ServletModuleOpenIndy extends ServletModule postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate"); postingFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDupeTemplate"); directOp = MirConfig.getProp("DirectOpenposting").toLowerCase(); - passwdProtection = MirConfig.getProp("PasswdProtection").toLowerCase(); + passwdProtection = MirConfig.getProp("PasswdProtection").toLowerCase(); mainModule = new ModuleComment(DatabaseComment.getInstance()); contentModule = new ModuleContent(DatabaseContent.getInstance()); themenModule = new ModuleTopics(DatabaseTopics.getInstance()); imageModule = new ModuleImages(DatabaseImages.getInstance()); defaultAction="addposting"; - + } catch (StorageObjectException e) { theLog.printError("servletmoduleopenindy could not be initialized"); @@ -104,19 +110,27 @@ public class ServletModuleOpenIndy extends ServletModule public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { String aid = req.getParameter("aid"); // the article id the comment will belong to + String language = req.getParameter("language"); + if (aid!=null && !aid.equals("")) { - SimpleHash mergeData = new SimpleHash(); - - // onetimepasswd - if(passwdProtection.equals("yes")){ - String passwd = this.createOneTimePasswd(); - System.out.println(passwd); - HttpSession session = req.getSession(false); - session.setAttribute("passwd",passwd); - mergeData.put("passwd", passwd); - } - + SimpleHash mergeData = new SimpleHash(); + + // onetimepasswd + if(passwdProtection.equals("yes")){ + String passwd = this.createOneTimePasswd(); + System.out.println(passwd); + HttpSession session = req.getSession(false); + session.setAttribute("passwd",passwd); + mergeData.put("passwd", passwd); + } + + if (language!=null) { + HttpSession session = req.getSession(false); + session.setAttribute("Locale", new Locale(language, "")); + session.setAttribute("passwd",language); + } + mergeData.put("aid", aid); deliver(req, res, mergeData, commentFormTemplate); } @@ -129,7 +143,7 @@ public class ServletModuleOpenIndy extends ServletModule */ public void inscomment(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException,ServletModuleUserException + throws ServletModuleException,ServletModuleUserException { String aid = req.getParameter("to_media"); // the article id the comment will belong to if (aid!=null && !aid.equals("")) @@ -137,44 +151,50 @@ public class ServletModuleOpenIndy extends ServletModule // ok, collecting data from form try { HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance()); - + //no html in comments(for now) for (Iterator i=withValues.keySet().iterator(); i.hasNext(); ){ String k=(String)i.next(); String v=(String)withValues.get(k); - + withValues.put(k,StringUtil.removeHTMLTags(v)); } withValues.put("is_published","1"); - - //checking the onetimepasswd - if(passwdProtection.equals("yes")){ - HttpSession session = req.getSession(false); - String sessionPasswd = (String)session.getAttribute("passwd"); - if ( sessionPasswd == null){ - throw new ServletModuleUserException("Lost password"); - } - String passwd = req.getParameter("passwd"); - if ( passwd == null || (!sessionPasswd.equals(passwd))) { - throw new ServletModuleUserException("Missing password"); - } - session.invalidate(); - } - + + //checking the onetimepasswd + if(passwdProtection.equals("yes")){ + HttpSession session = req.getSession(false); + String sessionPasswd = (String)session.getAttribute("passwd"); + if ( sessionPasswd == null){ + throw new ServletModuleUserException("Lost password"); + } + String passwd = req.getParameter("passwd"); + if ( passwd == null || (!sessionPasswd.equals(passwd))) { + throw new ServletModuleUserException("Missing password"); + } + session.invalidate(); + } + // inserting into database String id = mainModule.add(withValues); theLog.printDebugInfo("id: "+id); //insert was not successfull if(id==null){ deliver(req, res, new SimpleHash(), commentFormDupeTemplate); + } else { + DatabaseContent.getInstance().setUnproduced("id="+aid); + + try { + EntityComment comment = (EntityComment) DatabaseComment.getInstance().selectById(id); + MirGlobal.localizer().openPostings().afterCommentPosting(comment); + } + catch (Throwable t) { + throw new ServletModuleException(t.getMessage()); + } + + + } - - // 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 @@ -196,16 +216,16 @@ public class ServletModuleOpenIndy extends ServletModule public void addposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { SimpleHash mergeData = new SimpleHash(); - - // onetimepasswd - if(passwdProtection.equals("yes")){ - String passwd = this.createOneTimePasswd(); - System.out.println(passwd); - HttpSession session = req.getSession(false); - session.setAttribute("passwd",passwd); - mergeData.put("passwd", passwd); - } - + + // onetimepasswd + if(passwdProtection.equals("yes")){ + String passwd = this.createOneTimePasswd(); + System.out.println(passwd); + HttpSession session = req.getSession(false); + session.setAttribute("passwd",passwd); + mergeData.put("passwd", passwd); + } + String maxMedia = MirConfig.getProp("ServletModule.OpenIndy.MaxMediaUploadItems"); String numOfMedia = req.getParameter("medianum"); if(numOfMedia==null||numOfMedia.equals("")){ @@ -213,7 +233,7 @@ public class ServletModuleOpenIndy extends ServletModule } else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) { numOfMedia = maxMedia; } - + int mediaNum = Integer.parseInt(numOfMedia); SimpleList mediaFields = new SimpleList(); for(int i =0; i 0) { + + if (to_topicsArr != null && to_topicsArr.length > 0) { try{ DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr); setTopic = true; @@ -345,22 +371,13 @@ public class ServletModuleOpenIndy extends ServletModule DatabaseContentToMedia.getInstance().addMedia(cid,mediaEnt.getId()); } - // producing openpostinglist - new ProducerOpenPosting().handle(null,null,false,false); - // producing new page - new ProducerContent().handle(null, null, false, false,cid); - //if direct op producing startpage - if (directOp.equals("yes")) new ProducerStartPage().handle(null,null); - - //produce the topicPages if set - //should be more intelligent - //if(setTopic==true) new ProducerTopics().handle(null,null); - - // sync the server - //should be configureable - int exitValue = Helper.rsync(); - theLog.printDebugInfo("rsync: "+exitValue); - + try { + MirGlobal.localizer().openPostings().afterContentPosting( + (EntityContent)contentModule.getById(cid)); + } + catch (Throwable t) { + throw new ServletModuleException(t.getMessage()); + } } catch (MirMediaException e) { throw new ServletModuleException("MediaException: "+ e.toString());} catch (IOException e) { throw new ServletModuleException("IOException: "+ e.toString());} @@ -439,17 +456,17 @@ public class ServletModuleOpenIndy extends ServletModule +", we do not support this mime-type. " +"Error One or more files of unrecognized type. Sorry"); } - - protected String createOneTimePasswd(){ - Random r = new Random(); - int random = r.nextInt(); - long l = System.currentTimeMillis(); - l = (l*l*l*l)/random; - if(l<0) l = l * -1; - String returnString = ""+l; - return returnString.substring(5); - } - + + protected String createOneTimePasswd(){ + Random r = new Random(); + int random = r.nextInt(); + long l = System.currentTimeMillis(); + l = (l*l*l*l)/random; + if(l<0) l = l * -1; + String returnString = ""+l; + return returnString.substring(5); + } + }