search is simple, functional, soon to be broken again
[mir.git] / source / mircoders / servlet / ServletModuleOpenIndy.java
1 /*
2  * Copyright (C) 2001, 2002  The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with the com.oreilly.servlet library, any library
22  * licensed under the Apache Software License, The Sun (tm) Java Advanced
23  * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24  * the above that use the same license as the above), and distribute linked
25  * combinations including the two.  You must obey the GNU General Public
26  * License in all respects for all of the code used other than the above
27  * mentioned libraries.  If you modify this file, you may extend this exception
28  * to your version of the file, but you are not obligated to do so.  If you do
29  * not wish to do so, delete this exception statement from your version.
30  */
31
32 package mircoders.servlet;
33
34 import java.io.*;
35 import java.lang.*;
36 import java.sql.*;
37 import java.util.*;
38 import java.net.*;
39 import java.lang.reflect.*;
40 import javax.servlet.*;
41 import javax.servlet.http.*;
42
43 import freemarker.template.*;
44 import com.oreilly.servlet.multipart.*;
45 import com.oreilly.servlet.*;
46
47 import org.xml.sax.InputSource;
48 import org.xml.sax.XMLReader;
49
50 import org.apache.fop.apps.Driver;
51 import org.apache.fop.apps.Version;
52 import org.apache.fop.apps.XSLTInputHandler;
53
54 import org.apache.lucene.analysis.standard.StandardAnalyzer;
55 import org.apache.lucene.search.*;
56 import org.apache.lucene.document.Document;
57 import org.apache.lucene.document.Field;
58 import org.apache.lucene.analysis.standard.*;
59 import org.apache.lucene.queryParser.*;
60
61 import org.apache.log.*;
62
63 import mir.servlet.*;
64 import mir.module.*;
65 import mir.misc.*;
66 import mir.entity.*;
67 import mir.storage.*;
68 import mir.media.*;
69
70 import mircoders.entity.*;
71 import mircoders.storage.*;
72 import mircoders.module.*;
73 import mircoders.producer.*;
74 import mircoders.media.MediaRequest;
75 import mircoders.global.*;
76 import mircoders.localizer.*;
77 import mircoders.search.*;
78
79 /*
80  *  ServletModuleOpenIndy -
81  *   is the open-access-servlet, which is responsible for
82  *    adding comments to articles &
83  *    open-postings to the newswire
84  *
85  * @author mir-coders group
86  * @version $Id: ServletModuleOpenIndy.java,v 1.44 2002/11/27 15:28:52 john Exp $
87  *
88  */
89
90 public class ServletModuleOpenIndy extends ServletModule
91 {
92
93   private String        commentFormTemplate, commentFormDoneTemplate,
94     commentFormDupeTemplate;
95   private String        postingFormTemplate, postingFormDoneTemplate,
96     postingFormDupeTemplate;
97   private String        searchResultsTemplate;
98   private ModuleContent contentModule;
99   private ModuleComment commentModule;
100   private ModuleImages  imageModule;
101   private ModuleTopics  themenModule;
102   private String        directOp ="yes";
103   private String        passwdProtection ="yes";
104   // Singelton / Kontruktor
105   private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy();
106   public static ServletModule getInstance() { return instance; }
107
108   private ServletModuleOpenIndy() {
109     try {
110       theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.OpenIndy.Logfile"));
111       commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate");
112       commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate");
113       commentFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDupeTemplate");
114       postingFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingTemplate");
115       postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate");
116       postingFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDupeTemplate");
117       searchResultsTemplate = MirConfig.getProp("ServletModule.OpenIndy.SearchResultsTemplate");
118       directOp = MirConfig.getProp("DirectOpenposting").toLowerCase();
119       passwdProtection = MirConfig.getProp("PasswdProtection").toLowerCase();
120       mainModule = new ModuleComment(DatabaseComment.getInstance());
121       contentModule = new ModuleContent(DatabaseContent.getInstance());
122       themenModule = new ModuleTopics(DatabaseTopics.getInstance());
123       imageModule = new ModuleImages(DatabaseImages.getInstance());
124       defaultAction="addposting";
125
126     }
127     catch (StorageObjectException e) {
128       theLog.printError("servletmoduleopenindy could not be initialized");
129     }
130   }
131
132
133   /**
134    *  Method for making a comment
135    */
136
137   public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
138   {
139     String aid = req.getParameter("aid"); // the article id the comment will belong to
140     String language = req.getParameter("language");
141
142     if (aid!=null && !aid.equals(""))
143       {
144         SimpleHash mergeData = new SimpleHash();
145
146         // onetimepasswd
147         if(passwdProtection.equals("yes")){
148           String passwd = this.createOneTimePasswd();
149           System.out.println(passwd);
150           HttpSession session = req.getSession(false);
151           session.setAttribute("passwd",passwd);
152           mergeData.put("passwd", passwd);
153         }
154
155         if (language!=null) {
156           HttpSession session = req.getSession(false);
157           session.setAttribute("Locale", new Locale(language, ""));
158           session.setAttribute("passwd",language);
159         }
160
161         mergeData.put("aid", aid);
162         deliver(req, res, mergeData, commentFormTemplate);
163       }
164     else throw new ServletModuleException("aid not set!");
165   }
166
167   /**
168    *  Method for inserting a comment into the Database and delivering
169    *  the commentDone Page
170    */
171
172   public void inscomment(HttpServletRequest req, HttpServletResponse res)
173     throws ServletModuleException,ServletModuleUserException
174   {
175     String aid = req.getParameter("to_media"); // the article id the comment will belong to
176     if (aid!=null && !aid.equals(""))
177       {
178         // ok, collecting data from form
179         try {
180           HashMap withValues = getIntersectingValues(req, DatabaseComment.getInstance());
181
182           //no html in comments(for now)
183           for (Iterator i=withValues.keySet().iterator(); i.hasNext(); ){
184             String k=(String)i.next();
185             String v=(String)withValues.get(k);
186
187             withValues.put(k,StringUtil.removeHTMLTags(v));
188           }
189           withValues.put("is_published","1");
190
191           //checking the onetimepasswd
192           if(passwdProtection.equals("yes")){
193             HttpSession session = req.getSession(false);
194             String sessionPasswd = (String)session.getAttribute("passwd");
195             if ( sessionPasswd == null){
196               throw new ServletModuleUserException("Lost password");
197             }
198             String passwd = req.getParameter("passwd");
199             if ( passwd == null || (!sessionPasswd.equals(passwd))) {
200               throw new ServletModuleUserException("Missing password");
201             }
202             session.invalidate();
203           }
204
205           // inserting into database
206           String id = mainModule.add(withValues);
207           theLog.printDebugInfo("id: "+id);
208           //insert was not successfull
209           if(id==null){
210             deliver(req, res, new SimpleHash(), commentFormDupeTemplate);
211           } else {
212             DatabaseContent.getInstance().setUnproduced("id="+aid);
213
214             try {
215               EntityComment comment = (EntityComment) DatabaseComment.getInstance().selectById(id);
216               MirGlobal.localizer().openPostings().afterCommentPosting(comment);
217             }
218             catch (Throwable t) {
219               throw new ServletModuleException(t.getMessage());
220             }
221           
222           
223           
224           }
225
226           // redirecting to url
227           // should implement back to article
228           SimpleHash mergeData = new SimpleHash();
229           deliver(req, res, mergeData, commentFormDoneTemplate);
230         }
231         catch (StorageObjectException e) { throw new ServletModuleException(e.toString());}
232         catch (ModuleException e) { throw new ServletModuleException(e.toString());}
233
234       }
235     else throw new ServletModuleException("aid not set!");
236
237   }
238
239   /**
240    *  Method for delivering the form-Page for open posting
241    */
242
243   public void addposting(HttpServletRequest req, HttpServletResponse res)
244     throws ServletModuleException {
245     SimpleHash mergeData = new SimpleHash();
246
247     // onetimepasswd
248     if(passwdProtection.equals("yes")){
249       String passwd = this.createOneTimePasswd();
250       System.out.println(passwd);
251       HttpSession session = req.getSession(false);
252       session.setAttribute("passwd",passwd);
253       mergeData.put("passwd", passwd);
254     }
255
256     String maxMedia = MirConfig.getProp("ServletModule.OpenIndy.MaxMediaUploadItems");
257     String numOfMedia = req.getParameter("medianum");
258     if(numOfMedia==null||numOfMedia.equals("")){
259       numOfMedia="1";
260     } else if(Integer.parseInt(numOfMedia) > Integer.parseInt(maxMedia)) {
261       numOfMedia = maxMedia;
262     }
263
264     int mediaNum = Integer.parseInt(numOfMedia);
265     SimpleList mediaFields = new SimpleList();
266     for(int i =0; i<mediaNum;i++){
267       Integer mNum = new Integer(i+1);
268       mediaFields.add(mNum.toString());
269     }
270     mergeData.put("medianum",numOfMedia);
271     mergeData.put("mediafields",mediaFields);
272
273
274     SimpleHash extraInfo = new SimpleHash();
275     try{
276       SimpleList popUpData = DatabaseLanguage.getInstance().getPopupData();
277       extraInfo.put("languagePopUpData", popUpData );
278       extraInfo.put("themenPopupData", themenModule.getTopicsAsSimpleList());
279
280       extraInfo.put("topics", themenModule.getTopicsList());
281
282     } catch (Exception e) {
283       theLog.printError("languagePopUpData or getTopicslist failed "
284                         +e.toString());
285       throw new ServletModuleException("OpenIndy -- failed getting language or topics: "+e.toString());
286     }
287
288
289
290     deliver(req, res, mergeData, extraInfo, postingFormTemplate);
291   }
292
293   /**
294    *  Method for inserting an open posting into the Database and delivering
295    *  the postingDone Page
296    */
297
298   public void insposting(HttpServletRequest req, HttpServletResponse res)
299     throws ServletModuleException, ServletModuleUserException
300   {
301     SimpleHash mergeData = new SimpleHash();
302     boolean setMedia=false;
303     boolean setTopic = false;
304
305     try {
306
307       WebdbMultipartRequest mp = null;
308       EntityList mediaList = null;
309       try {
310         // new MediaRequest, "1" is the id for the openPosting user
311         MediaRequest mediaReq = new MediaRequest("1", true, true);
312         mp = new WebdbMultipartRequest(req, (FileHandler)mediaReq);
313         mediaList = mediaReq.getEntityList();
314       } catch (FileHandlerUserException e) {
315         throw new ServletModuleUserException(e.getMsg());
316       }
317           
318       HashMap withValues = mp.getParameters();
319
320       //checking the onetimepasswd
321       if(passwdProtection.equals("yes")){
322         HttpSession session = req.getSession(false);
323         String sessionPasswd = (String)session.getAttribute("passwd");
324         if ( sessionPasswd == null){
325           throw new ServletModuleUserException("Lost password");
326         }
327         String passwd = (String)withValues.get("passwd");
328         if ( passwd == null || (!sessionPasswd.equals(passwd))) {
329           throw new ServletModuleUserException("Missing password");
330         }
331         session.invalidate();
332       }
333
334       if ((((String)withValues.get("title")).length() == 0) ||
335           (((String)withValues.get("description")).length() == 0) ||
336           (((String)withValues.get("content_data")).length() == 0))
337         throw new ServletModuleUserException("Missing field");
338
339       // call the routines that escape html
340
341       for (Iterator i=withValues.keySet().iterator(); i.hasNext(); ){
342         String k=(String)i.next();
343         String v=(String)withValues.get(k);
344
345         if (k.equals("content_data")){
346           //this doesn't quite work yet, so for now, all html goes
347           //withValues.put(k,StringUtil.approveHTMLTags(v));
348           //withValues.put(k,StringUtil.removeHTMLTags(v));
349         } else {
350           withValues.put(k,StringUtil.removeHTMLTags(v));
351         }
352
353       }
354
355       withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
356       withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date")));
357       withValues.put("is_produced", "0");
358       // by default stuff is published, they can be un-published through the
359       // admin interface.
360       withValues.put("is_published","1");
361       // if op direct article-type == newswire
362       if (directOp.equals("yes")) withValues.put("to_article_type","1");
363
364       withValues.put("to_publisher","1");
365
366       // owner is openposting user
367       //      ML: this is not multi-language friendly and this can be done in a template
368       //      if (withValues.get("creator").toString().equals(""))
369       //        withValues.put("creator","Anonym");
370
371       // inserting  content into database
372       String cid = contentModule.add(withValues);
373       theLog.printDebugInfo("id: "+cid);
374       //insert was not successfull
375       if(cid==null){
376         //How do we know that it was not succesful cause of a
377         //dupe, what if it failed cause of "No space left on device"?
378         //Or is there something I am missing? Wouldn't it be better
379         //to have an explicit dupe check and then insert? I have no
380         //idea what I am talking about. this comment is in case
381         //I forget to explicitely ask. -mh
382         deliver(req, res, mergeData, postingFormDupeTemplate);
383       }
384
385       String[] to_topicsArr = mp.getParameterValues("to_topic");
386
387       if (to_topicsArr != null && to_topicsArr.length > 0) {
388         try{
389           DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr);
390           setTopic = true;
391         } catch (Exception e) {
392           theLog.printError("setting content_x_topic failed");
393           contentModule.deleteById(cid);
394           throw new ServletModuleException("smod - openindy :: insposting: setting content_x_topic failed: "+e.toString());
395         } //end try
396       } //end if
397        
398       //if we're here all is ok... associate the media to the article
399       for(int i=0;i<mediaList.size();i++) {
400         Entity mediaEnt = (Entity)mediaList.elementAt(i);
401         DatabaseContentToMedia.getInstance().addMedia(cid,mediaEnt.getId());
402       }
403
404       try {
405         MirGlobal.localizer().openPostings().afterContentPosting(
406                                                                  (EntityContent)contentModule.getById(cid));
407       }
408       catch (Throwable t) {
409         throw new ServletModuleException(t.getMessage());
410       }
411     }
412     catch (FileHandlerException e) { throw new ServletModuleException("MediaException: "+ e.toString());}
413     catch (IOException e) { throw new ServletModuleException("IOException: "+ e.toString());}
414     catch (StorageObjectException e) { throw new ServletModuleException("StorageObjectException" + e.toString());}
415     catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.toString());}
416
417     deliver(req, res, mergeData, postingFormDoneTemplate);
418   }
419
420   /*
421    * Method for querying a lucene index
422    */
423   public void search(HttpServletRequest req, HttpServletResponse res)
424     throws ServletModuleException, ServletModuleUserException {
425     
426     String queryString="";
427     
428     SimpleHash mergeData = new SimpleHash();
429     
430     //make the query available to subsequent iterations
431
432     for (Enumeration theParams = req.getParameterNames(); theParams.hasMoreElements() ;) {
433       String pName=(String)theParams.nextElement();
434       if (pName.startsWith("search_")){
435         mergeData.put(pName,new SimpleScalar(req.getParameter(pName)));
436       }
437     }
438     
439     try{
440       mergeData.put("topics", themenModule.getTopicsAsSimpleList());
441     }
442     catch(ModuleException e) {
443       theLog.printDebugInfo("Can't get topics: " + e.toString());
444     }
445
446     //String indexPath=MirConfig.getProp("IndexPath");
447     String indexPath="/tmp/index";
448     
449     KeywordSearchTerm dateTerm = new KeywordSearchTerm("date_formatted","search_date","webdb_create_formatted","webdbcreate_formatted","webdb_create_formatted");
450     
451     UnIndexedSearchTerm whereTerm = new UnIndexedSearchTerm("","","","where","where");
452     
453     TextSearchTerm creatorTerm = new TextSearchTerm("creator","search_creator","creator","creator","creator");
454     TextSearchTerm titleTerm = new TextSearchTerm("title","search_content","title","title","title");
455     TextSearchTerm descriptionTerm =  new TextSearchTerm("description","search_content","description","description","description");
456
457     ContentSearchTerm contentTerm = new ContentSearchTerm("content_data","search_content","content","","");
458
459     TopicSearchTerm topicTerm = new TopicSearchTerm();
460     
461     ImagesSearchTerm imagesTerm = new ImagesSearchTerm();
462       
463     AudioSearchTerm audioTerm = new AudioSearchTerm();
464       
465     VideoSearchTerm videoTerm = new VideoSearchTerm();
466
467     String creatorFragment = creatorTerm.makeTerm(req);
468     if (creatorFragment != null){
469       queryString = queryString + " +" + creatorFragment;
470     }
471     
472     // search title, description, and content for something
473     // the contentTerm uses "search_boolean" to combine its terms
474     String contentFragment = contentTerm.makeTerm(req);
475     if (contentFragment != null){
476       theLog.printDebugInfo("contentFragment: " + contentFragment);
477       queryString = queryString + " +" + contentFragment;
478     }
479     
480     String topicFragment = topicTerm.makeTerm(req);
481     if (topicFragment != null){
482       queryString = queryString + " +" + topicFragment;
483     }
484
485     String imagesFragment = imagesTerm.makeTerm(req);
486     if (imagesFragment != null){
487       queryString = queryString + " +" + imagesFragment;
488     }
489     
490     String audioFragment = audioTerm.makeTerm(req);
491     if (audioFragment != null){
492       queryString = queryString + " +" + audioFragment;
493     }
494     
495     String videoFragment = videoTerm.makeTerm(req);
496     if (videoFragment != null){
497       queryString = queryString + " +" + videoFragment;
498     }
499
500     if (queryString == null || queryString == ""){
501       queryString = "";
502     }
503     else{
504         
505       try{
506         Searcher searcher = null;
507         try {
508           searcher = new IndexSearcher(indexPath);
509         } 
510         catch(IOException e) {
511           theLog.printDebugInfo("Can't open indexPath: " + indexPath);
512           throw new ServletModuleUserException("Problem with Search Index!");
513         }
514             
515         // parse the query String.
516         Query query = null;
517         try {
518           query = QueryParser.parse(queryString, "content", new StandardAnalyzer());
519         } 
520         catch(Exception e) {
521           searcher.close();
522           theLog.printDebugInfo("Query don't parse: " + queryString);
523           throw new ServletModuleUserException("Problem with Query String! (was '"+queryString+"')");
524         }
525             
526         Hits hits = null;
527         try {
528           hits = searcher.search(query);
529         } catch(IOException e) {
530           searcher.close();
531           theLog.printDebugInfo("Can't get hits: " + e.toString());
532           throw new ServletModuleUserException("Problem getting hits!");
533         }
534         
535
536         // this is what needs to change in order to get sorting by date
537         // iterate over the results
538         // the results are an array of document
539         // associate this with session so we don't need to reduplicate searches
540         // make a map from date to position
541         // make an list of dates
542         // sort list by date
543         // grab low+n entries from the list of dates,
544         // iterate over these, using hash to get hit position,
545         // and hit position to get hit
546         // shove hit into SimpleList of SimpleHashes
547         
548
549         
550         try {
551           int start = 0;
552           int end = hits.length();
553           mergeData.put("numberOfHits", (new Integer(end)).toString());
554           SimpleList theHits = new SimpleList();
555           for(int i = start; i < end; i++) {
556             SimpleHash h = new SimpleHash();
557             Document theHit = hits.doc(i);
558             whereTerm.returnMeta(h,theHit);
559             creatorTerm.returnMeta(h,theHit);
560             titleTerm.returnMeta(h,theHit);
561             descriptionTerm.returnMeta(h,theHit);
562             dateTerm.returnMeta(h,theHit);
563             imagesTerm.returnMeta(h,theHit);
564             audioTerm.returnMeta(h,theHit);
565             videoTerm.returnMeta(h,theHit);  
566             theHits.add(h);
567           }
568           mergeData.put("hits",theHits);
569         }
570         catch (Exception e) {
571           searcher.close();
572           theLog.printDebugInfo("Can't iterate over hits: " + e.toString());
573           throw new ServletModuleUserException("Problem getting hits!");
574         }
575         searcher.close();
576       }
577       catch (IOException e){
578         theLog.printDebugInfo("Can't close searcher: " + e.toString());
579         throw new ServletModuleUserException("Problem closing searcher!");
580       }
581     }
582     mergeData.put("queryString",queryString);
583     deliver(req,res,mergeData,searchResultsTemplate);
584   }
585     
586   /*
587    * Method for dynamically generating a pdf from a fo file
588    */
589   public void getpdf(HttpServletRequest req, HttpServletResponse res)
590     throws ServletModuleException, ServletModuleUserException {
591     String ID_REQUEST_PARAM = "id";
592     
593     String generateFO=MirConfig.getProp("GenerateFO");
594     String generatePDF=MirConfig.getProp("GeneratePDF");
595
596     //don't do anything if we are not making FO files, or if we are
597     //pregenerating PDF's
598     if (generateFO.equals("yes") && generatePDF.equals("no")){
599       //fop complains unless you do the logging this way
600       Logger log = null;
601       Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
602       log = hierarchy.getLoggerFor("fop");
603       log.setPriority(Priority.WARN);
604     
605       String producerStorageRoot=MirConfig.getProp("Producer.StorageRoot");
606       String producerDocRoot=MirConfig.getProp("Producer.DocRoot");
607       String templateDir=MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");
608       String xslSheet=templateDir + "/" 
609         + MirConfig.getProp("Producer.PrintableContent.html2foStyleSheetName");
610       try {
611         String idParam = req.getParameter(ID_REQUEST_PARAM);
612         if (idParam != null) {
613           EntityContent contentEnt =
614             (EntityContent)contentModule.getById(idParam);
615           String publishPath = contentEnt.getValue("publish_path");
616           String foFile = producerStorageRoot + producerDocRoot + "/" 
617             + publishPath + "/" + idParam + ".fo";
618           XSLTInputHandler input = new XSLTInputHandler(new File(foFile), 
619                                                         new File(xslSheet));
620           
621           ByteArrayOutputStream out = new ByteArrayOutputStream();
622           res.setContentType("application/pdf");
623
624           Driver driver = new Driver();
625           driver.setLogger(log);
626           driver.setRenderer(Driver.RENDER_PDF);
627           driver.setOutputStream(out);
628           driver.render(input.getParser(), input.getInputSource());
629
630           byte[] content = out.toByteArray();
631           res.setContentLength(content.length);
632           res.getOutputStream().write(content);
633           res.getOutputStream().flush();
634         } else {
635           throw new ServletModuleUserException("Missing id parameter.");
636         }
637       } catch (Exception ex) {
638         throw new ServletModuleException(ex.toString());
639       }
640     } else {
641       throw new ServletModuleUserException("Can't generate a PDF because the config tells me not to.");
642     }
643   }
644   
645   private void _throwBadContentType (String fileName, String contentType)
646     throws ServletModuleUserException {
647
648     theLog.printDebugInfo("Wrong file type uploaded!: " + fileName+" "
649                           +contentType);
650     throw new ServletModuleUserException("The file you uploaded is of the "
651                                          +"following mime-type: "+contentType
652                                          +", we do not support this mime-type. "
653                                          +"Error One or more files of unrecognized type. Sorry");
654   }
655
656   protected String createOneTimePasswd(){
657     Random r = new Random();
658     int random = r.nextInt();
659     long l = System.currentTimeMillis();
660     l = (l*l*l*l)/random;
661     if(l<0) l = l * -1;
662     String returnString = ""+l;
663     return returnString.substring(5);
664   }
665
666
667   /* this is an overwritten method of ServletModule in order
668      to use different bundles for open and admin */
669   public void deliver(HttpServletRequest req, HttpServletResponse res,
670                       TemplateModelRoot rtm, TemplateModelRoot popups,
671                       String templateFilename)
672     throws ServletModuleException {
673     if (rtm == null) rtm = new SimpleHash();
674     try {
675       PrintWriter out = res.getWriter();
676       HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out,
677                                     getLocale(req), "bundles.open");
678       out.close();
679     }   catch (HTMLParseException e) {
680       throw new ServletModuleException(e.toString());
681     } catch (IOException e) {
682       throw new ServletModuleException(e.toString());
683     }
684   }
685 }
686
687
688