X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Flocalizer%2Fbasic%2FMirBasicPostingSessionHandler.java;h=786fd6268b1f32c6b68fffec067427e9a6fa3e0a;hb=04bf29aa1f1abf43e96d0272b2a286f0c1f9fea8;hp=86c24f2c89add273f70f516a047dca1942c35c9f;hpb=314b6a22bd19592c88720a079a6fdf763e123be4;p=mir.git diff --git a/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java b/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java index 86c24f2c..786fd626 100755 --- a/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java +++ b/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java @@ -1,314 +1,313 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mircoders.localizer.basic; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Vector; - -import mir.config.MirPropertiesConfiguration; -import mir.log.LoggerWrapper; -import mir.session.Request; -import mir.session.Response; -import mir.session.Session; -import mir.session.SessionExc; -import mir.session.SessionFailure; -import mir.session.SessionHandler; -import mir.session.UploadedFile; -import mir.session.ValidationError; -import mir.session.ValidationHelper; -import mir.storage.StorageObject; -import mir.util.ExceptionFunctions; -import mircoders.global.MirGlobal; -import mircoders.module.ModuleMediaType; - -/** - * - *

Title: Experimental session handler for comment postings

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

- * @author not attributable - * @version 1.0 - */ - -public abstract class MirBasicPostingSessionHandler implements SessionHandler { - protected LoggerWrapper logger; - protected MirPropertiesConfiguration configuration; - - private String normalResponseGenerator; - private String dupeResponseGenerator; - private String unsupportedMediaTypeResponseGenerator; - private String finalResponseGenerator; - - - public MirBasicPostingSessionHandler() { - logger = new LoggerWrapper("Localizer.OpenPosting"); - try { - configuration = MirPropertiesConfiguration.instance(); - } - catch (Throwable t) { - logger.fatal("Cannot load configuration: " + t.toString()); - - throw new RuntimeException("Cannot load configuration: " + t.toString()); - } - } - - protected void setNormalResponseGenerator(String aGenerator) { - normalResponseGenerator = aGenerator; - } - - protected void setResponseGenerators(String aNormalResponseGenerator, String aDupeResponseGenerator, - String anUnsupportedMediaTypeResponseGenerator, String aFinalResponseGenerator) { - setNormalResponseGenerator(aNormalResponseGenerator); - dupeResponseGenerator = aDupeResponseGenerator; - unsupportedMediaTypeResponseGenerator = anUnsupportedMediaTypeResponseGenerator; - finalResponseGenerator = aFinalResponseGenerator; - } - - public void processRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { - if (MirGlobal.abuse().getOpenPostingDisabled()) { - makeOpenPostingDisabledResponse(aRequest, aSession, aResponse); - aSession.terminate(); - } - else { - if (aSession.getAttribute("initialRequest") == null) { - initialRequest(aRequest, aSession, aResponse); - aSession.setAttribute("initialRequest", "no"); - } - else { - subsequentRequest(aRequest, aSession, aResponse); - } - } - }; - - protected void initialRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { - initializeSession(aRequest, aSession); - initializeResponseData(aRequest, aSession, aResponse); - makeInitialResponse(aRequest, aSession, aResponse); - } - - public void subsequentRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { - try { - try { - List validationErrors = new Vector(); - - if (!shouldProcessRequest(aRequest, aSession, validationErrors)) { - initializeResponseData(aRequest, aSession, aResponse); - makeResponse(aRequest, aSession, aResponse, validationErrors); - } - else { - preProcessRequest(aRequest, aSession); - Iterator i = aRequest.getUploadedFiles().iterator(); - while (i.hasNext()) { - processUploadedFile(aRequest, aSession, (UploadedFile) i.next()); - } - postProcessRequest(aRequest, aSession); - initializeResponseData(aRequest, aSession, aResponse); - makeFinalResponse(aRequest, aSession, aResponse); - aSession.terminate(); - } - } - catch (Throwable t) { - initializeResponseData(aRequest, aSession, aResponse); - makeErrorResponse(aRequest, aSession, aResponse, t); - aSession.terminate(); - } - } - catch (Throwable t) { - aSession.terminate(); - - throw new SessionFailure(t); - } - } - - protected void initializeSession(Request aRequest, Session aSession) throws SessionExc, SessionFailure { - if (MirGlobal.abuse().getOpenPostingPassword()) { - String password = (String) aSession.getAttribute("password"); - if (password==null) { - password = generateOnetimePassword(); - aSession.setAttribute("password", password); - } - } - else { - aSession.deleteAttribute("password"); - } - - logger.debug("referrer = " + aRequest.getHeader("Referer")); - - aSession.setAttribute("referer", aRequest.getHeader("Referer")); - } - - protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { - int nrMediaItems = configuration.getInt("ServletModule.OpenIndy.DefaultMediaUploadItems", 5); - - if (aSession.getAttribute("nrmediaitems")!=null) { - nrMediaItems = ((Integer) aSession.getAttribute("nrmediaitems")).intValue(); - } - try { - nrMediaItems = Math.min(configuration.getInt("ServletModule.OpenIndy.MaxMediaUploadItems"), Integer.parseInt(aRequest.getParameter("nrmediaitems"))); - } - catch (Throwable t) { - } - aSession.setAttribute("nrmediaitems", new Integer(nrMediaItems)); - - List mediaItems = new Vector(); - int i=0; - - while (iTitle: Experimental session handler for comment postings

+ *

Description:

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author not attributable + * @version 1.0 + */ + +public abstract class MirBasicPostingSessionHandler implements SessionHandler { + protected LoggerWrapper logger; + protected MirPropertiesConfiguration configuration; + + private String normalResponseGenerator; + private String dupeResponseGenerator; + private String unsupportedMediaTypeResponseGenerator; + private String finalResponseGenerator; + + + public MirBasicPostingSessionHandler() { + logger = new LoggerWrapper("Localizer.OpenPosting"); + try { + configuration = MirPropertiesConfiguration.instance(); + } + catch (Throwable t) { + logger.fatal("Cannot load configuration: " + t.toString()); + + throw new RuntimeException("Cannot load configuration: " + t.toString()); + } + } + + protected void setNormalResponseGenerator(String aGenerator) { + normalResponseGenerator = aGenerator; + } + + protected void setResponseGenerators(String aNormalResponseGenerator, String aDupeResponseGenerator, + String anUnsupportedMediaTypeResponseGenerator, String aFinalResponseGenerator) { + setNormalResponseGenerator(aNormalResponseGenerator); + dupeResponseGenerator = aDupeResponseGenerator; + unsupportedMediaTypeResponseGenerator = anUnsupportedMediaTypeResponseGenerator; + finalResponseGenerator = aFinalResponseGenerator; + } + + public void processRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { + if (MirGlobal.abuse().getOpenPostingDisabled()) { + makeOpenPostingDisabledResponse(aRequest, aSession, aResponse); + aSession.terminate(); + } + else { + if (aSession.getAttribute("initialRequest") == null) { + initialRequest(aRequest, aSession, aResponse); + aSession.setAttribute("initialRequest", "no"); + } + else { + subsequentRequest(aRequest, aSession, aResponse); + } + } + }; + + protected void initialRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { + initializeSession(aRequest, aSession); + initializeResponseData(aRequest, aSession, aResponse); + makeInitialResponse(aRequest, aSession, aResponse); + } + + public void subsequentRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { + try { + try { + List validationErrors = new Vector(); + + if (!shouldProcessRequest(aRequest, aSession, validationErrors)) { + initializeResponseData(aRequest, aSession, aResponse); + makeResponse(aRequest, aSession, aResponse, validationErrors); + } + else { + preProcessRequest(aRequest, aSession); + Iterator i = aRequest.getUploadedFiles().iterator(); + while (i.hasNext()) { + processUploadedFile(aRequest, aSession, (UploadedFile) i.next()); + } + postProcessRequest(aRequest, aSession); + initializeResponseData(aRequest, aSession, aResponse); + makeFinalResponse(aRequest, aSession, aResponse); + aSession.terminate(); + } + } + catch (Throwable t) { + initializeResponseData(aRequest, aSession, aResponse); + makeErrorResponse(aRequest, aSession, aResponse, t); + aSession.terminate(); + } + } + catch (Throwable t) { + aSession.terminate(); + + throw new SessionFailure(t); + } + } + + protected void initializeSession(Request aRequest, Session aSession) throws SessionExc, SessionFailure { + if (MirGlobal.abuse().getOpenPostingPassword()) { + String password = (String) aSession.getAttribute("password"); + if (password==null) { + password = generateOnetimePassword(); + aSession.setAttribute("password", password); + } + } + else { + aSession.deleteAttribute("password"); + } + + logger.debug("referrer = " + aRequest.getHeader("Referer")); + + aSession.setAttribute("referer", aRequest.getHeader("Referer")); + } + + protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { + int nrMediaItems = configuration.getInt("ServletModule.OpenIndy.DefaultMediaUploadItems", 5); + + if (aSession.getAttribute("nrmediaitems")!=null) { + nrMediaItems = ((Integer) aSession.getAttribute("nrmediaitems")).intValue(); + } + try { + nrMediaItems = Math.min(configuration.getInt("ServletModule.OpenIndy.MaxMediaUploadItems"), Integer.parseInt(aRequest.getParameter("nrmediaitems"))); + } + catch (Throwable t) { + } + aSession.setAttribute("nrmediaitems", new Integer(nrMediaItems)); + + List mediaItems = new Vector(); + int i=0; + + while (i