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.Random;
\r
37 import mir.config.MirPropertiesConfiguration;
\r
38 import mir.log.LoggerWrapper;
\r
39 import mir.session.Request;
\r
40 import mir.session.Session;
\r
41 import mir.session.SessionHandler;
\r
42 import mircoders.entity.EntityComment;
\r
43 import mircoders.entity.EntityContent;
\r
44 import mircoders.global.MirGlobal;
\r
45 import mircoders.global.ProducerEngine;
\r
46 import mircoders.localizer.MirLocalizerExc;
\r
47 import mircoders.localizer.MirLocalizerFailure;
\r
48 import mircoders.localizer.MirOpenPostingLocalizer;
\r
50 public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer {
\r
51 private List afterContentProducerTasks;
\r
52 private List afterCommentProducerTasks;
\r
53 protected LoggerWrapper logger;
\r
54 protected MirPropertiesConfiguration configuration;
\r
57 public MirBasicOpenPostingLocalizer() throws MirLocalizerExc, MirLocalizerFailure {
\r
58 logger = new LoggerWrapper("Localizer.Basic.OpenPosting");
\r
61 configuration = MirPropertiesConfiguration.instance();
\r
63 catch (Throwable e) {
\r
64 throw new MirLocalizerFailure("Can't get configuration: " + e.getMessage(), e);
\r
68 String contentProducers = MirGlobal.config().getString("Mir.Localizer.OpenPosting.ContentProducers");
\r
69 String commentProducers = MirGlobal.config().getString("Mir.Localizer.OpenPosting.CommentProducers");
\r
71 afterContentProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(contentProducers);
\r
72 afterCommentProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(commentProducers);
\r
74 catch (Throwable t) {
\r
75 logger.error("Setting up MirBasicOpenPostingLocalizer failed: " + t.getMessage());
\r
77 throw new MirLocalizerFailure(t);
\r
81 public SessionHandler getOpenSessionHandler(Request aRequest, Session aSession) throws MirLocalizerExc, MirLocalizerFailure {
\r
82 if (aSession.getAttribute("handler")==null)
\r
83 aSession.setAttribute("handler", new MirBasicCommentPostingSessionHandler());
\r
85 return (SessionHandler) aSession.getAttribute("handler");
\r
88 public void afterContentPosting() {
\r
89 MirGlobal.producerEngine().addTasks(afterContentProducerTasks);
\r
92 public void afterContentPosting(EntityContent aContent) {
\r
93 afterContentPosting();
\r
96 public void afterCommentPosting(EntityComment aComment) {
\r
97 afterCommentPosting();
\r
100 public void afterCommentPosting() {
\r
101 MirGlobal.producerEngine().addTasks(afterCommentProducerTasks);
\r
104 public String generateOnetimePassword() {
\r
105 Random r = new Random();
\r
106 int random = r.nextInt();
\r
108 long l = System.currentTimeMillis();
\r
110 l = (l*l*l*l)/random;
\r
114 String returnString = ""+l;
\r
116 return returnString.substring(5);
\r