2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with the com.oreilly.servlet library, any library
\r
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
\r
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
\r
24 * the above that use the same license as the above), and distribute linked
\r
25 * combinations including the two. You must obey the GNU General Public
\r
26 * License in all respects for all of the code used other than the above
\r
27 * mentioned libraries. If you modify this file, you may extend this exception
\r
28 * to your version of the file, but you are not obligated to do so. If you do
\r
29 * not wish to do so, delete this exception statement from your version.
\r
32 package mircoders.localizer.basic;
\r
34 import java.util.List;
\r
35 import java.util.Locale;
\r
37 import javax.servlet.http.HttpServletRequest;
\r
39 import mir.log.LoggerWrapper;
\r
40 import mir.servlet.*;
\r
41 import mir.config.*;
\r
42 import mir.session.Request;
\r
43 import mir.session.Response;
\r
44 import mir.session.*;
\r
46 import mircoders.entity.EntityComment;
\r
47 import mircoders.entity.EntityContent;
\r
48 import mircoders.global.MirGlobal;
\r
49 import mircoders.global.ProducerEngine;
\r
50 import mircoders.localizer.*;
\r
52 public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer {
\r
53 private List afterContentProducerTasks;
\r
54 private List afterCommentProducerTasks;
\r
55 protected LoggerWrapper logger;
\r
56 protected MirPropertiesConfiguration configuration;
\r
59 public MirBasicOpenPostingLocalizer() throws MirLocalizerExc, MirLocalizerFailure {
\r
60 logger = new LoggerWrapper("Localizer.Basic.OpenPosting");
\r
63 configuration = MirPropertiesConfiguration.instance();
\r
65 catch (Throwable e) {
\r
66 throw new MirLocalizerFailure("Can't get configuration: " + e.getMessage(), e);
\r
70 String contentProducers = MirGlobal.config().getString("Mir.Localizer.OpenPosting.ContentProducers");
\r
71 String commentProducers = MirGlobal.config().getString("Mir.Localizer.OpenPosting.CommentProducers");
\r
73 afterContentProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(contentProducers);
\r
74 afterCommentProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(commentProducers);
\r
76 catch (Throwable t) {
\r
77 logger.error("Setting up MirBasicOpenPostingLocalizer failed: " + t.getMessage());
\r
79 throw new MirLocalizerFailure(t);
\r
83 public SessionHandler getOpenSessionHandler(Request aRequest, Session aSession) throws MirLocalizerExc, MirLocalizerFailure {
\r
84 if (aSession.getAttribute("handler")==null)
\r
85 aSession.setAttribute("handler", new MirBasicCommentPostingSessionHandler());
\r
87 return (SessionHandler) aSession.getAttribute("handler");
\r
90 public void afterContentPosting() {
\r
91 MirGlobal.producerEngine().addTasks(afterContentProducerTasks);
\r
94 public void afterContentPosting(EntityContent aContent) {
\r
95 afterContentPosting();
\r
98 public void afterCommentPosting(EntityComment aComment) {
\r
99 afterCommentPosting();
\r
102 public void afterCommentPosting() {
\r
103 MirGlobal.producerEngine().addTasks(afterCommentProducerTasks);
\r
106 public String generateOnetimePassword() {
\r
107 Random r = new Random();
\r
108 int random = r.nextInt();
\r
110 long l = System.currentTimeMillis();
\r
112 l = (l*l*l*l)/random;
\r
116 String returnString = ""+l;
\r
118 return returnString.substring(5);
\r