From d6e5c9b71d135010afcfbab2173ccf5e6a643bdb Mon Sep 17 00:00:00 2001 From: zapata Date: Tue, 21 Jan 2003 18:03:09 +0000 Subject: [PATCH] fixed 2 problems with john's code: publish_path shouldn't be used, and the text on back/forward buttons from search results can now be internationalized. --- .../mircoders/producer/IndexingProducerNode.java | 40 +++-- .../mircoders/servlet/ServletModuleOpenIndy.java | 181 +++++++++++---------- 2 files changed, 110 insertions(+), 111 deletions(-) diff --git a/source/mircoders/producer/IndexingProducerNode.java b/source/mircoders/producer/IndexingProducerNode.java index d207dfe8..650c5285 100755 --- a/source/mircoders/producer/IndexingProducerNode.java +++ b/source/mircoders/producer/IndexingProducerNode.java @@ -39,17 +39,15 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.store.FSDirectory; -import freemarker.template.*; - import mir.util.*; +import mir.misc.*; import mir.log.*; +import mir.entity.*; +import mir.entity.adapter.*; import mir.producer.*; -//import mir.generator.*; import mircoders.global.*; import mircoders.localizer.*; -import mir.entity.*; -import mir.entity.adapter.*; import mircoders.entity.*; import mircoders.storage.*; import mircoders.search.*; @@ -74,9 +72,9 @@ public class IndexingProducerNode implements ProducerNode { long endTime; startTime = System.currentTimeMillis(); - - - + + + try { index = ParameterExpander.expandExpression(aValueMap, indexPath); data = ParameterExpander.findValueForKey( aValueMap, contentKey ); @@ -92,9 +90,9 @@ public class IndexingProducerNode implements ProducerNode { // create an index here if one did not already exist if (! (IndexReader.indexExists(index))){ - aLogger.error("Didn't find existing index, so I'm making one in "+index); - IndexWriter indexCreator = new IndexWriter(index,new StandardAnalyzer(),true); - indexCreator.close(); + aLogger.error("Didn't find existing index, so I'm making one in "+index); + IndexWriter indexCreator = new IndexWriter(index,new StandardAnalyzer(),true); + indexCreator.close(); } IndexUtil.unindexEntity((EntityContent) entity,index); @@ -106,14 +104,14 @@ public class IndexingProducerNode implements ProducerNode { // Text is tokenized,stored, indexed // Unindexed is not tokenized or indexed, only stored // Unstored is tokenized and indexed, but not stored - + //this initialization should go somewhere global like an xml file.... (new KeywordSearchTerm("id","","id","","id")).index(theDoc,entity); - + (new KeywordSearchTerm("webdb_create_formatted","search_date","webdb_create_formatted","webdb_create_formatted","webdb_create_formatted")).index(theDoc,entity); - - (new UnIndexedSearchTerm("","","","where","where")).indexValue(theDoc,entity.getValue("publish_path")+entity.getValue("id")+".shtml"); + + (new UnIndexedSearchTerm("","","","where","where")).indexValue(theDoc, StringUtil.webdbDate2path(entity.getValue("date"))+entity.getValue("id")+".shtml"); (new TextSearchTerm("creator","search_creator","creator","creator","creator")).index(theDoc,entity); (new TextSearchTerm("title","search_title","title","title","title")).index(theDoc,entity); @@ -121,17 +119,17 @@ public class IndexingProducerNode implements ProducerNode { (new UnIndexedSearchTerm("webdb_create","search_irrelevant","creationDate","creationDate","creationDate")).index(theDoc,entity); (new ContentSearchTerm("content_data","search_content","content","","")).indexValue(theDoc, - entity.getValue("content_data")+ " " - + entity.getValue("description")+ " " - + entity.getValue("title") - ); + entity.getValue("content_data")+ " " + + entity.getValue("description")+ " " + + entity.getValue("title") + ); (new TopicSearchTerm()).index(theDoc,entity); (new ImagesSearchTerm()).index(theDoc,entity); - + (new AudioSearchTerm()).index(theDoc,entity); - + (new VideoSearchTerm()).index(theDoc,entity); diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 70edefbc..58a79a63 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -87,7 +87,7 @@ import mircoders.search.*; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.55 2003/01/19 14:13:34 john Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.56 2003/01/21 18:03:09 zapata Exp $ * */ @@ -444,126 +444,126 @@ public class ServletModuleOpenIndy extends ServletModule /* * Method for preparing and sending a content as an email message */ - + public void mail(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException, ServletModuleUserException { String aid = req.getParameter("mail_aid"); if (aid == null){ throw new ServletModuleUserException("An article id must be specified in requests to email an article. Something therefore went badly wrong...."); } - + String to = req.getParameter("mail_to"); String from = req.getParameter("mail_from"); String from_name = req.getParameter("mail_from_name"); String comment = req.getParameter("mail_comment"); String mail_language = req.getParameter("mail_language"); - + SimpleHash mergeData = new SimpleHash(); - + if (to == null || from == null || from_name == null|| to.equals("") || from.equals("") || from_name.equals("") || mail_language == null || mail_language.equals("")){ for (Enumeration theParams = req.getParameterNames(); theParams.hasMoreElements() ;) { - String pName=(String)theParams.nextElement(); - if (pName.startsWith("mail_")){ - mergeData.put(pName,new SimpleScalar(req.getParameter(pName))); - } + String pName=(String)theParams.nextElement(); + if (pName.startsWith("mail_")){ + mergeData.put(pName,new SimpleScalar(req.getParameter(pName))); + } } - deliver(req,res,mergeData,prepareMailTemplate); + deliver(req,res,mergeData,prepareMailTemplate); } else { //run checks on to and from and mail_language to make sure no monkey business occurring if (mail_language.indexOf('.') != -1 || mail_language.indexOf('/') != -1 ){ - throw new ServletModuleUserException("Sorry, you've entered an illegal character into the language field. Go back and try again, asshole."); + throw new ServletModuleUserException("Sorry, you've entered an illegal character into the language field. Go back and try again, asshole."); } - if (to.indexOf('\n') != -1 - || to.indexOf('\r') != -1 - || to.indexOf(',') != -1 - || from.indexOf('\n') != -1 - || from.indexOf('\r') != -1 - || from.indexOf(',') != -1 ){ - throw new ServletModuleUserException("Sorry, you've entered an illegal character into the from or to field. Go back and try again."); + if (to.indexOf('\n') != -1 + || to.indexOf('\r') != -1 + || to.indexOf(',') != -1 + || from.indexOf('\n') != -1 + || from.indexOf('\r') != -1 + || from.indexOf(',') != -1 ){ + throw new ServletModuleUserException("Sorry, you've entered an illegal character into the from or to field. Go back and try again."); } EntityContent contentEnt; try{ - contentEnt = (EntityContent)contentModule.getById(aid); + contentEnt = (EntityContent)contentModule.getById(aid); } - catch (ModuleException e){ - throw new ServletModuleUserException("Couldn't get content for article "+aid); + catch (ModuleException e){ + throw new ServletModuleUserException("Couldn't get content for article "+aid); } String producerStorageRoot=MirConfig.getProp("Producer.StorageRoot"); String producerDocRoot=MirConfig.getProp("Producer.DocRoot"); - String publishPath = contentEnt.getValue("publish_path"); - String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language + - publishPath + "/" + aid + ".txt"; - + String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date")); + String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language + + publishPath + "/" + aid + ".txt"; + File inputFile = new File(txtFilePath); String content; - + try{ - FileReader in = new FileReader(inputFile); - StringWriter out = new StringWriter(); - int c; - while ((c = in.read()) != -1) - out.write(c); - in.close(); - content= out.toString(); + FileReader in = new FileReader(inputFile); + StringWriter out = new StringWriter(); + int c; + while ((c = in.read()) != -1) + out.write(c); + in.close(); + content= out.toString(); } catch (FileNotFoundException e){ - throw new ServletModuleUserException("No text file found in " + txtFilePath); + throw new ServletModuleUserException("No text file found in " + txtFilePath); } catch (IOException e){ - throw new ServletModuleUserException("Problem reading file in " + txtFilePath); + throw new ServletModuleUserException("Problem reading file in " + txtFilePath); } // add some headers content = "To: " + to + "\nReply-To: "+ from + "\n" + content; // put in the comment where it should go - if (comment != null) { - String commentTextToInsert = "\n\nAttached comment from " + from_name + ":\n" + comment; - try { - content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",commentTextToInsert); - } - catch (Exception e){ - throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); - } + if (comment != null) { + String commentTextToInsert = "\n\nAttached comment from " + from_name + ":\n" + comment; + try { + content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",commentTextToInsert); + } + catch (Exception e){ + throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); + } } else{ - try { - content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",""); - } - catch (Exception e){ - throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); - } + try { + content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",""); + } + catch (Exception e){ + throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); + } } - + SMTPClient client=new SMTPClient(); try { - int reply; - client.connect(MirConfig.getProp("ServletModule.OpenIndy.SMTPServer")); - System.out.print(client.getReplyString()); - - reply = client.getReplyCode(); - - if(!SMTPReply.isPositiveCompletion(reply)) { - client.disconnect(); - throw new ServletModuleUserException("SMTP server refused connection."); - } - - client.sendSimpleMessage(MirConfig.getProp("ServletModule.OpenIndy.EmailIsFrom"),to,content); - - client.disconnect(); - //mission accomplished - deliver(req,res,mergeData,sentMailTemplate); + int reply; + client.connect(MirConfig.getProp("ServletModule.OpenIndy.SMTPServer")); + System.out.print(client.getReplyString()); + + reply = client.getReplyCode(); + + if(!SMTPReply.isPositiveCompletion(reply)) { + client.disconnect(); + throw new ServletModuleUserException("SMTP server refused connection."); + } + + client.sendSimpleMessage(MirConfig.getProp("ServletModule.OpenIndy.EmailIsFrom"),to,content); + + client.disconnect(); + //mission accomplished + deliver(req,res,mergeData,sentMailTemplate); } catch(IOException e) { - if(client.isConnected()) { - try { - client.disconnect(); - } catch(IOException f) { - // do nothing - } - } - throw new ServletModuleUserException(e.toString()); + if(client.isConnected()) { + try { + client.disconnect(); + } catch(IOException f) { + // do nothing + } + } + throw new ServletModuleUserException(e.toString()); } } } @@ -610,9 +610,10 @@ public class ServletModuleOpenIndy extends ServletModule logger.debug("Can't get topics: " + e.toString()); } - String searchSubmitValue = req.getParameter("search_submit"); + String searchBackValue = req.getParameter("search_back"); + String searchForwardValue = req.getParameter("search_forward"); - if (searchSubmitValue != null && searchSubmitValue.equals("Back")){ + if (searchBackValue != null){ int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue(); int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()-increment; if (newPosition < 0 || newPosition >= totalHits){ @@ -622,7 +623,7 @@ public class ServletModuleOpenIndy extends ServletModule } else { - if (searchSubmitValue != null && searchSubmitValue.equals("Forward")){ + if (searchForwardValue != null){ int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue(); int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()+increment; if (newPosition < 0 || newPosition >= totalHits){ @@ -840,7 +841,7 @@ public class ServletModuleOpenIndy extends ServletModule throws ServletModuleException, ServletModuleUserException { String ID_REQUEST_PARAM = "id"; String language = req.getParameter("language"); - + String generateFO=MirConfig.getProp("GenerateFO"); String generatePDF=MirConfig.getProp("GeneratePDF"); @@ -862,18 +863,18 @@ public class ServletModuleOpenIndy extends ServletModule if (idParam != null) { EntityContent contentEnt = (EntityContent)contentModule.getById(idParam); - String publishPath = contentEnt.getValue("publish_path"); + String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date")); String foFile; - - if (language == null){ - foFile = producerStorageRoot + producerDocRoot + "/" - + publishPath + idParam + ".fo"; - } - else{ - foFile = producerStorageRoot + producerDocRoot + "/" - + language + publishPath + idParam + ".fo"; - } - logger.debug("USING FILES" + foFile + " and " + xslSheet); + + if (language == null){ + foFile = producerStorageRoot + producerDocRoot + "/" + + publishPath + idParam + ".fo"; + } + else{ + foFile = producerStorageRoot + producerDocRoot + "/" + + language + publishPath + idParam + ".fo"; + } + logger.debug("USING FILES" + foFile + " and " + xslSheet); XSLTInputHandler input = new XSLTInputHandler(new File(foFile), new File(xslSheet)); @@ -894,7 +895,7 @@ public class ServletModuleOpenIndy extends ServletModule throw new ServletModuleUserException("Missing id parameter."); } } catch (Exception ex) { - logger.error(ex.toString()); + logger.error(ex.toString()); throw new ServletModuleException(ex.toString()); } } else { -- 2.11.0