fixed 2 problems with john's code: publish_path shouldn't be used, and the
authorzapata <zapata>
Tue, 21 Jan 2003 18:03:09 +0000 (18:03 +0000)
committerzapata <zapata>
Tue, 21 Jan 2003 18:03:09 +0000 (18:03 +0000)
text on back/forward buttons from search results can now be internationalized.

source/mircoders/producer/IndexingProducerNode.java
source/mircoders/servlet/ServletModuleOpenIndy.java

index d207dfe..650c528 100755 (executable)
@@ -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);
 
 
index 70edefb..58a79a6 100755 (executable)
@@ -87,7 +87,7 @@ import mircoders.search.*;
  *    open-postings to the newswire\r
  *\r
  * @author mir-coders group\r
- * @version $Id: ServletModuleOpenIndy.java,v 1.55 2003/01/19 14:13:34 john Exp $\r
+ * @version $Id: ServletModuleOpenIndy.java,v 1.56 2003/01/21 18:03:09 zapata Exp $\r
  *\r
  */\r
 \r
@@ -444,126 +444,126 @@ public class ServletModuleOpenIndy extends ServletModule
     /*\r
    * Method for preparing and sending a content as an email message\r
    */\r
-  \r
+\r
   public void mail(HttpServletRequest req, HttpServletResponse res)\r
     throws ServletModuleException, ServletModuleUserException {\r
     String aid = req.getParameter("mail_aid");\r
     if (aid == null){\r
       throw new ServletModuleUserException("An article id must be specified in requests to email an article.  Something therefore went badly wrong....");\r
     }\r
-    \r
+\r
     String to = req.getParameter("mail_to");\r
     String from = req.getParameter("mail_from");\r
     String from_name = req.getParameter("mail_from_name");\r
     String comment = req.getParameter("mail_comment");\r
     String mail_language = req.getParameter("mail_language");\r
-    \r
+\r
     SimpleHash mergeData = new SimpleHash();\r
-    \r
+\r
     if (to == null || from == null || from_name == null|| to.equals("") || from.equals("") || from_name.equals("") || mail_language == null || mail_language.equals("")){\r
 \r
       for (Enumeration theParams = req.getParameterNames(); theParams.hasMoreElements() ;) {\r
-       String pName=(String)theParams.nextElement();\r
-       if (pName.startsWith("mail_")){\r
-         mergeData.put(pName,new SimpleScalar(req.getParameter(pName)));\r
-       }\r
+        String pName=(String)theParams.nextElement();\r
+        if (pName.startsWith("mail_")){\r
+          mergeData.put(pName,new SimpleScalar(req.getParameter(pName)));\r
+        }\r
       }\r
-      deliver(req,res,mergeData,prepareMailTemplate); \r
+      deliver(req,res,mergeData,prepareMailTemplate);\r
     }\r
     else {\r
       //run checks on to and from and mail_language to make sure no monkey business occurring\r
       if (mail_language.indexOf('.') != -1 || mail_language.indexOf('/') != -1 ){\r
-       throw new ServletModuleUserException("Sorry, you've entered an illegal character into the language field.  Go back and try again, asshole.");\r
+        throw new ServletModuleUserException("Sorry, you've entered an illegal character into the language field.  Go back and try again, asshole.");\r
       }\r
-      if (to.indexOf('\n') != -1 \r
-         || to.indexOf('\r') != -1 \r
-         || to.indexOf(',') != -1 \r
-         || from.indexOf('\n') != -1 \r
-         || from.indexOf('\r') != -1 \r
-         || from.indexOf(',') != -1 ){\r
-       throw new ServletModuleUserException("Sorry, you've entered an illegal character into the from or to field.  Go back and try again.");\r
+      if (to.indexOf('\n') != -1\r
+          || to.indexOf('\r') != -1\r
+          || to.indexOf(',') != -1\r
+          || from.indexOf('\n') != -1\r
+          || from.indexOf('\r') != -1\r
+          || from.indexOf(',') != -1 ){\r
+        throw new ServletModuleUserException("Sorry, you've entered an illegal character into the from or to field.  Go back and try again.");\r
       }\r
       EntityContent contentEnt;\r
       try{\r
-       contentEnt = (EntityContent)contentModule.getById(aid);\r
+        contentEnt = (EntityContent)contentModule.getById(aid);\r
       }\r
-      catch (ModuleException e){ \r
-       throw new ServletModuleUserException("Couldn't get content for article "+aid);\r
+      catch (ModuleException e){\r
+        throw new ServletModuleUserException("Couldn't get content for article "+aid);\r
       }\r
       String producerStorageRoot=MirConfig.getProp("Producer.StorageRoot");\r
       String producerDocRoot=MirConfig.getProp("Producer.DocRoot");\r
-      String publishPath = contentEnt.getValue("publish_path");\r
-      String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language + \r
-        publishPath + "/" + aid + ".txt";\r
-      \r
+      String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date"));\r
+      String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language +\r
+         publishPath + "/" + aid + ".txt";\r
+\r
 \r
       File inputFile = new File(txtFilePath);\r
       String content;\r
-      \r
+\r
       try{\r
-       FileReader in = new FileReader(inputFile);\r
-       StringWriter out = new StringWriter();\r
-       int c;\r
-       while ((c = in.read()) != -1)\r
-         out.write(c);\r
-       in.close();\r
-       content= out.toString();\r
+        FileReader in = new FileReader(inputFile);\r
+        StringWriter out = new StringWriter();\r
+        int c;\r
+        while ((c = in.read()) != -1)\r
+          out.write(c);\r
+        in.close();\r
+        content= out.toString();\r
       }\r
       catch (FileNotFoundException e){\r
-       throw new ServletModuleUserException("No text file found in " + txtFilePath);\r
+        throw new ServletModuleUserException("No text file found in " + txtFilePath);\r
       }\r
       catch (IOException e){\r
-       throw new ServletModuleUserException("Problem reading file in " + txtFilePath);\r
+        throw new ServletModuleUserException("Problem reading file in " + txtFilePath);\r
       }\r
       // add some headers\r
       content = "To: " + to + "\nReply-To: "+ from + "\n" + content;\r
       // put in the comment where it should go\r
-      if (comment != null) { \r
-       String commentTextToInsert = "\n\nAttached comment from " + from_name + ":\n" + comment;\r
-       try {\r
-         content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",commentTextToInsert);\r
-       }\r
-       catch (Exception e){\r
-         throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString());\r
-       }\r
+      if (comment != null) {\r
+        String commentTextToInsert = "\n\nAttached comment from " + from_name + ":\n" + comment;\r
+        try {\r
+          content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",commentTextToInsert);\r
+        }\r
+        catch (Exception e){\r
+          throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString());\r
+        }\r
       }\r
       else{\r
-       try {\r
-         content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!","");\r
-       }\r
-       catch (Exception e){\r
-         throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString());\r
-       }\r
+        try {\r
+          content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!","");\r
+        }\r
+        catch (Exception e){\r
+          throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString());\r
+        }\r
       }\r
-      \r
+\r
       SMTPClient client=new SMTPClient();\r
       try {\r
-       int reply;\r
-       client.connect(MirConfig.getProp("ServletModule.OpenIndy.SMTPServer"));\r
-       System.out.print(client.getReplyString());\r
-       \r
-       reply = client.getReplyCode();\r
-       \r
-       if(!SMTPReply.isPositiveCompletion(reply)) {\r
-         client.disconnect();\r
-         throw new ServletModuleUserException("SMTP server refused connection.");\r
-       }\r
-       \r
-       client.sendSimpleMessage(MirConfig.getProp("ServletModule.OpenIndy.EmailIsFrom"),to,content);\r
-       \r
-       client.disconnect();\r
-       //mission accomplished\r
-       deliver(req,res,mergeData,sentMailTemplate); \r
+        int reply;\r
+        client.connect(MirConfig.getProp("ServletModule.OpenIndy.SMTPServer"));\r
+        System.out.print(client.getReplyString());\r
+\r
+        reply = client.getReplyCode();\r
+\r
+        if(!SMTPReply.isPositiveCompletion(reply)) {\r
+          client.disconnect();\r
+          throw new ServletModuleUserException("SMTP server refused connection.");\r
+        }\r
+\r
+        client.sendSimpleMessage(MirConfig.getProp("ServletModule.OpenIndy.EmailIsFrom"),to,content);\r
+\r
+        client.disconnect();\r
+        //mission accomplished\r
+        deliver(req,res,mergeData,sentMailTemplate);\r
 \r
       } catch(IOException e) {\r
-       if(client.isConnected()) {\r
-         try {\r
-           client.disconnect();\r
-         } catch(IOException f) {\r
-           // do nothing\r
-         }\r
-       }\r
-       throw new ServletModuleUserException(e.toString());\r
+        if(client.isConnected()) {\r
+          try {\r
+            client.disconnect();\r
+          } catch(IOException f) {\r
+            // do nothing\r
+          }\r
+        }\r
+        throw new ServletModuleUserException(e.toString());\r
       }\r
     }\r
   }\r
@@ -610,9 +610,10 @@ public class ServletModuleOpenIndy extends ServletModule
         logger.debug("Can't get topics: " + e.toString());\r
       }\r
 \r
-      String searchSubmitValue = req.getParameter("search_submit");\r
+      String searchBackValue = req.getParameter("search_back");\r
+      String searchForwardValue = req.getParameter("search_forward");\r
 \r
-      if (searchSubmitValue != null && searchSubmitValue.equals("Back")){\r
+      if (searchBackValue != null){\r
         int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue();\r
         int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()-increment;\r
         if (newPosition < 0 || newPosition >= totalHits){\r
@@ -622,7 +623,7 @@ public class ServletModuleOpenIndy extends ServletModule
 \r
       }\r
       else {\r
-        if (searchSubmitValue != null && searchSubmitValue.equals("Forward")){\r
+        if (searchForwardValue != null){\r
           int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue();\r
           int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()+increment;\r
           if (newPosition < 0 || newPosition >= totalHits){\r
@@ -840,7 +841,7 @@ public class ServletModuleOpenIndy extends ServletModule
     throws ServletModuleException, ServletModuleUserException {\r
     String ID_REQUEST_PARAM = "id";\r
     String language = req.getParameter("language");\r
-    \r
+\r
     String generateFO=MirConfig.getProp("GenerateFO");\r
     String generatePDF=MirConfig.getProp("GeneratePDF");\r
 \r
@@ -862,18 +863,18 @@ public class ServletModuleOpenIndy extends ServletModule
         if (idParam != null) {\r
           EntityContent contentEnt =\r
             (EntityContent)contentModule.getById(idParam);\r
-          String publishPath = contentEnt.getValue("publish_path");\r
+          String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date"));\r
           String foFile;\r
-         \r
-         if (language == null){\r
-           foFile = producerStorageRoot + producerDocRoot + "/"\r
-             + publishPath  + idParam + ".fo";\r
-         }\r
-         else{\r
-           foFile = producerStorageRoot + producerDocRoot + "/"\r
-             + language + publishPath  + idParam + ".fo";\r
-         }\r
-         logger.debug("USING FILES" + foFile + " and " + xslSheet);\r
+\r
+          if (language == null){\r
+            foFile = producerStorageRoot + producerDocRoot + "/"\r
+              + publishPath  + idParam + ".fo";\r
+          }\r
+          else{\r
+            foFile = producerStorageRoot + producerDocRoot + "/"\r
+              + language + publishPath  + idParam + ".fo";\r
+          }\r
+          logger.debug("USING FILES" + foFile + " and " + xslSheet);\r
           XSLTInputHandler input = new XSLTInputHandler(new File(foFile),\r
                                                         new File(xslSheet));\r
 \r
@@ -894,7 +895,7 @@ public class ServletModuleOpenIndy extends ServletModule
           throw new ServletModuleUserException("Missing id parameter.");\r
         }\r
       } catch (Exception ex) {\r
-       logger.error(ex.toString());\r
+        logger.error(ex.toString());\r
         throw new ServletModuleException(ex.toString());\r
       }\r
     } else {\r