From 0d512e810fc3838b6787c2a866864481d79c93ca Mon Sep 17 00:00:00 2001 From: rk Date: Thu, 23 Oct 2003 14:55:25 +0000 Subject: [PATCH] some cosmetic change, organzied imports, and made some accesses in a static way --- source/Mir.java | 748 ++--- source/OpenMir.java | 3 +- source/mir/entity/Entity.java | 8 +- source/mir/entity/adapter/EntityAdapterEngine.java | 140 +- source/mir/generator/FreemarkerGenerator.java | 768 ++--- source/mir/generator/Generator.java | 3 +- source/mir/generator/GeneratorHelper.java | 9 +- source/mir/misc/StringUtil.java | 878 +++--- .../mir/producer/EntityDeletingProducerNode.java | 3 - .../mir/producer/EntityModifyingProducerNode.java | 7 +- source/mir/producer/GeneratingProducerNode.java | 211 +- .../mir/producer/ListEnumeratingProducerNode.java | 8 +- source/mir/producer/RDFAggregatorProducerNode.java | 6 +- source/mir/producer/RSSProducerNode.java | 3 +- .../mir/producer/reader/ProducerConfigReader.java | 3 +- source/mir/rss/RSS091Reader.java | 6 +- source/mir/rss/RSSAggregator.java | 4 +- source/mir/rss/RSSTest.java | 3 - source/mir/servlet/AbstractServlet.java | 555 ++-- source/mir/servlet/ServletModule.java | 1086 ++++---- source/mir/session/HTTPAdapters.java | 295 +- source/mir/session/ValidationHelper.java | 3 - source/mir/storage/Database.java | 2919 ++++++++++---------- source/mir/util/DateTimeFunctions.java | 1 - source/mir/util/FileFunctions.java | 4 +- source/mir/util/GeneratorHTMLFunctions.java | 1 - source/mir/util/HTTPRequestParser.java | 3 +- source/mir/util/JDBCStringRoutines.java | 5 +- source/mir/util/ParameterExpander.java | 8 +- source/mir/util/StringRoutines.java | 725 +++-- source/mir/util/StructuredContentParser.java | 5 +- source/mircoders/entity/EntityImages.java | 10 +- source/mircoders/global/Abuse.java | 1738 ++++++------ source/mircoders/global/MirGlobal.java | 540 ++-- .../localizer/MirCachingLocalizerDecorator.java | 2 +- .../localizer/MirOpenPostingLocalizer.java | 179 +- .../basic/MirBasicAdminInterfaceLocalizer.java | 715 +++-- .../basic/MirBasicAntiAbuseFilterTypes.java | 360 +-- .../basic/MirBasicArticlePostingHandler.java | 386 +-- .../basic/MirBasicEmailArticleHandler.java | 13 +- .../basic/MirBasicOpenPostingLocalizer.java | 8 +- .../basic/MirBasicPostingSessionHandler.java | 627 +++-- .../localizer/basic/MirBasicProducerLocalizer.java | 375 +-- source/mircoders/media/ImageProcessor.java | 12 +- source/mircoders/media/MediaHandlerGeneric.java | 31 +- source/mircoders/media/MediaHandlerImages.java | 5 +- .../mircoders/media/MediaHandlerImagesExtern.java | 2 - source/mircoders/module/ModuleTopics.java | 1 - source/mircoders/pdf/PDFGenerator.java | 29 +- .../mircoders/producer/IndexingProducerNode.java | 2 +- .../producer/PDFPreFormattingProducerNode.java | 461 ++-- source/mircoders/servlet/ServletHelper.java | 308 +-- source/mircoders/servlet/ServletModuleAbuse.java | 547 ++-- source/mircoders/servlet/ServletModuleAdmin.java | 207 +- source/mircoders/servlet/ServletModuleAudio.java | 3 +- source/mircoders/servlet/ServletModuleComment.java | 720 ++--- .../servlet/ServletModuleCommentStatus.java | 3 +- source/mircoders/servlet/ServletModuleContent.java | 1119 ++++---- .../mircoders/servlet/ServletModuleFileEdit.java | 5 +- source/mircoders/servlet/ServletModuleHidden.java | 35 +- source/mircoders/servlet/ServletModuleImages.java | 5 +- .../mircoders/servlet/ServletModuleLanguage.java | 3 +- .../mircoders/servlet/ServletModuleLocalizer.java | 436 +-- .../servlet/ServletModuleMediafolder.java | 140 +- source/mircoders/servlet/ServletModuleMessage.java | 155 +- .../mircoders/servlet/ServletModuleOpenIndy.java | 35 +- .../mircoders/servlet/ServletModuleOtherMedia.java | 3 +- .../mircoders/servlet/ServletModuleProducer.java | 419 +-- source/mircoders/servlet/ServletModuleTopics.java | 3 +- .../servlet/ServletModuleUploadedMedia.java | 1116 ++++---- source/mircoders/servlet/ServletModuleUsers.java | 775 +++--- source/mircoders/servlet/ServletModuleVideo.java | 3 +- source/mircoders/storage/DatabaseImages.java | 181 +- source/mircoders/storage/DatabaseVideo.java | 2 +- source/tool/BundleTool.java | 4 +- source/tool/ConfigTool.java | 191 +- 76 files changed, 10175 insertions(+), 10160 deletions(-) diff --git a/source/Mir.java b/source/Mir.java index 3c42ca60..70430462 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -1,372 +1,376 @@ -/* - * 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. - */ - -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Vector; -import javax.servlet.*; -import javax.servlet.ServletException; -import javax.servlet.UnavailableException; -import javax.servlet.http.*; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.struts.util.MessageResources; -import mir.config.MirPropertiesConfiguration; -import mir.servlet.AbstractServlet; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleDispatch; -import mir.servlet.ServletModuleExc; -import mir.servlet.ServletModuleUserExc; -import mir.util.ExceptionFunctions; -import mir.util.StringRoutines; -import mircoders.entity.EntityUsers; -import mircoders.global.MirGlobal; -import mircoders.module.ModuleMessage; -import mircoders.module.ModuleUsers; -import mircoders.servlet.ServletHelper; -import mircoders.storage.DatabaseUsers; - - - - -/** - * Mir.java - main servlet, that dispatches to servletmodules - * - * @author $Author: zapata $ - * @version $Id: Mir.java,v 1.49.2.7 2003/09/04 03:11:42 zapata Exp $ - * - */ -public class Mir extends AbstractServlet { - private static ModuleUsers usersModule = null; - private static ModuleMessage messageModule = null; - private final static Map servletModuleInstanceHash = new HashMap(); - private static Locale fallbackLocale = null; - - private static List loginLanguages = null; - - protected List getLoginLanguages() throws ServletException { - synchronized (Mir.class) { - try { - if (loginLanguages == null) { - MessageResources messageResources = - MessageResources.getMessageResources("bundles.adminlocal"); - MessageResources messageResources2 = - MessageResources.getMessageResources("bundles.admin"); - - List languages = - StringRoutines.splitString(MirGlobal.config().getString("Mir.Login.Languages", "en"), ";"); - - loginLanguages = new Vector(); - - Iterator i = languages.iterator(); - - while (i.hasNext()) { - String code = (String) i.next(); - Locale locale = new Locale(code, ""); - String name = messageResources.getMessage(locale, "languagename"); - - if (name == null) { - name = messageResources2.getMessage(locale, "languagename"); - } - - if (name == null) { - name = code; - } - - Map record = new HashMap(); - record.put("name", name); - record.put("code", code); - loginLanguages.add(record); - } - } - - return loginLanguages; - } - catch (Throwable t) { - throw new ServletException(t.getMessage()); - } - } - } - - public void init(ServletConfig config) throws ServletException { - super.init(config); - - usersModule = new ModuleUsers(DatabaseUsers.getInstance()); - } - - protected String getDefaultLanguage(HttpServletRequest aRequest) { - String defaultlanguage = - MirGlobal.config().getString("Mir.Login.DefaultLanguage", ""); - - if (defaultlanguage.length() == 0) { - Locale locale = aRequest.getLocale(); - defaultlanguage = locale.getLanguage(); - } - - return defaultlanguage; - } - - protected synchronized Locale getFallbackLocale() throws ServletException { - try { - if (fallbackLocale == null) { - fallbackLocale = new Locale(MirPropertiesConfiguration.instance().getString("Mir.Admin.FallbackLanguage", "en"), ""); - } - } - catch (Throwable t) { - throw new ServletException(t.getMessage()); - } - - return fallbackLocale; - } - - public EntityUsers checkCredentials(HttpServletRequest aRequest) throws ServletException { - try { - EntityUsers user = ServletHelper.getUser(aRequest); - - String username = aRequest.getParameter("login"); - String password = aRequest.getParameter("password"); - - if (username != null && password != null) { - user = usersModule.getUserForLogin(username, password); - - if (user!=null) { - ServletHelper.setUser(aRequest, user); - aRequest.getSession().setAttribute("sessiontracker", new SessionTracker(username)); - } - } - - return user; - } - catch (Throwable t) { - t.printStackTrace(); - - throw new ServletException(t.toString()); - } - } - - public void process(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException, UnavailableException { - try { - long startTime = System.currentTimeMillis(); - long sessionConnectTime = 0; - - HttpSession session = aRequest.getSession(true); - setNoCaching(aResponse); - Locale locale = new Locale(getDefaultLanguage(aRequest), ""); - aResponse.setContentType("text/html; charset=" + - configuration. - getString("Mir.DefaultHTMLCharset", "UTF-8")); - - EntityUsers userEntity = checkCredentials(aRequest); - - if (userEntity == null) { - String queryString = aRequest.getQueryString(); - - if ( (queryString != null) && (queryString.length() != 0) && session.getAttribute("login.target") == null && - (aRequest.getParameter("module")==null || - (!aRequest.getParameter("module").equals("login") && !aRequest.getParameter("module").equals("logout")))) { - session.setAttribute("login.target", queryString); - } - - _sendLoginPage(aResponse, aRequest); - } - else { - String moduleName = aRequest.getParameter("module"); - checkLanguage(session, aRequest); - - if ( ( (moduleName == null) || moduleName.equals(""))) { - moduleName="Admin"; - } - - - if (moduleName.equals("login")) { - String target = (String) session.getAttribute("login.target"); - - if (target != null) { - ServletHelper.redirect(aResponse, target); - } - else { - ServletHelper.redirect(aResponse, ""); - } - } - else if (moduleName.equals("logout")) { - logger.info(userEntity.getValue("login") + " has logged out"); - session.invalidate(); - _sendLoginPage(aResponse, aRequest); - return; - } - else { - try { - ServletModule servletModule = getServletModuleForName(moduleName); - ServletModuleDispatch.dispatch(servletModule, aRequest, aResponse); - - sessionConnectTime = System.currentTimeMillis() - startTime; - logger.info("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms"); - } - catch (Throwable e) { - Throwable cause = ExceptionFunctions.traceCauseException(e); - - if (cause instanceof ServletModuleUserExc) - handleUserError(aRequest, aResponse, (ServletModuleUserExc) cause); - else - handleError(aRequest, aResponse, cause); - } - - if (aRequest.getParameter("killsession")!=null) - aRequest.getSession().invalidate(); - } - } - } - catch (Throwable t) { - t.printStackTrace(); - - throw new ServletException(t.toString()); - } - } - - /** - * caching routine to get a module for a module name - * - * @param moduleName the module name - * @return the requested module - * @throws ServletModuleExc - */ - - private static ServletModule getServletModuleForName(String moduleName) throws ServletModuleExc { - // Instance in Map ? - if (!servletModuleInstanceHash.containsKey(moduleName)) { - // was not found in hash... - try { - Class theServletModuleClass = null; - - try { - // first we try to get ServletModule from stern.che3.servlet - theServletModuleClass = - Class.forName("mircoders.servlet.ServletModule" + moduleName); - } - catch (ClassNotFoundException e) { - // on failure, we try to get it from lib-layer - theServletModuleClass = - Class.forName("mir.servlet.ServletModule" + moduleName); - } - - Method m = theServletModuleClass.getMethod("getInstance", null); - ServletModule smod = (ServletModule) m.invoke(null, null); - - // we put it into map for further reference - servletModuleInstanceHash.put(moduleName, smod); - - return smod; - } - catch (Exception e) { - throw new ServletModuleExc("*** error resolving classname for " + moduleName + " -- " + e.getMessage()); - } - } - else { - return (ServletModule) servletModuleInstanceHash.get(moduleName); - } - } - - private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, ServletModuleUserExc anException) { - try { - logger.info("user error: " + anException.getMessage()); - - Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); - - MessageResources messages = MessageResources.getMessageResources("bundles.admin"); - responseData.put("errorstring", messages.getMessage(getLocale(aRequest), anException.getMessage(), anException.getParameters())); - responseData.put("date", new GregorianCalendar().getTime()); - - ServletHelper.generateResponse(aResponse.getWriter(), responseData, MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate")); - } - catch (Throwable e) { - logger.error("Error handling user error" + e.toString()); - } - } - - private void handleError(HttpServletRequest aRequest, HttpServletResponse aResponse, Throwable anException) { - try { - logger.error("error: " + anException); - - Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); - - responseData.put("errorstring", anException.toString()); - responseData.put("date", new GregorianCalendar().getTime()); - - ServletHelper.generateResponse(aResponse.getWriter(), responseData, MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate")); - } - catch (Throwable e) { - logger.error("Error handling error: " + e.toString()); - } - } - - // Redirect-methods - private void _sendLoginPage(HttpServletResponse aResponse, HttpServletRequest aRequest) { - String loginTemplate = configuration.getString("Mir.LoginTemplate"); - - try { - Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); - - responseData.put("defaultlanguage", getDefaultLanguage(aRequest)); - responseData.put("languages", getLoginLanguages()); - - ServletHelper.generateResponse(aResponse.getWriter(), responseData, loginTemplate); - } - catch (Throwable e) { - handleError(aRequest, aResponse, e); - } - } - - public String getServletInfo() { - return "Mir " + configuration.getString("Mir.Version"); - } - - private class SessionTracker implements HttpSessionBindingListener { - private String name; - - public SessionTracker(String aUserName) { - name = aUserName; - } - - public void valueBound(HttpSessionBindingEvent anEvent) { - MirGlobal.registerLogin(name); - } - - public void valueUnbound(HttpSessionBindingEvent anEvent) { - MirGlobal.registerLogout(name); - } - } -} +/* + * 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. + */ + +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Vector; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.UnavailableException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionBindingEvent; +import javax.servlet.http.HttpSessionBindingListener; + +import mir.config.MirPropertiesConfiguration; +import mir.servlet.AbstractServlet; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleDispatch; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleUserExc; +import mir.util.ExceptionFunctions; +import mir.util.StringRoutines; +import mircoders.entity.EntityUsers; +import mircoders.global.MirGlobal; +import mircoders.module.ModuleMessage; +import mircoders.module.ModuleUsers; +import mircoders.servlet.ServletHelper; +import mircoders.storage.DatabaseUsers; + +import org.apache.struts.util.MessageResources; + + + + +/** + * Mir.java - main servlet, that dispatches to servletmodules + * + * @author $Author: rk $ + * @version $Id: Mir.java,v 1.49.2.8 2003/10/23 14:55:26 rk Exp $ + * + */ +public class Mir extends AbstractServlet { + private static ModuleUsers usersModule = null; + private static ModuleMessage messageModule = null; + private final static Map servletModuleInstanceHash = new HashMap(); + private static Locale fallbackLocale = null; + + private static List loginLanguages = null; + + protected List getLoginLanguages() throws ServletException { + synchronized (Mir.class) { + try { + if (loginLanguages == null) { + MessageResources messageResources = + MessageResources.getMessageResources("bundles.adminlocal"); + MessageResources messageResources2 = + MessageResources.getMessageResources("bundles.admin"); + + List languages = + StringRoutines.splitString(MirGlobal.config().getString("Mir.Login.Languages", "en"), ";"); + + loginLanguages = new Vector(); + + Iterator i = languages.iterator(); + + while (i.hasNext()) { + String code = (String) i.next(); + Locale locale = new Locale(code, ""); + String name = messageResources.getMessage(locale, "languagename"); + + if (name == null) { + name = messageResources2.getMessage(locale, "languagename"); + } + + if (name == null) { + name = code; + } + + Map record = new HashMap(); + record.put("name", name); + record.put("code", code); + loginLanguages.add(record); + } + } + + return loginLanguages; + } + catch (Throwable t) { + throw new ServletException(t.getMessage()); + } + } + } + + public void init(ServletConfig config) throws ServletException { + super.init(config); + + usersModule = new ModuleUsers(DatabaseUsers.getInstance()); + } + + protected String getDefaultLanguage(HttpServletRequest aRequest) { + String defaultlanguage = + MirGlobal.config().getString("Mir.Login.DefaultLanguage", ""); + + if (defaultlanguage.length() == 0) { + Locale locale = aRequest.getLocale(); + defaultlanguage = locale.getLanguage(); + } + + return defaultlanguage; + } + + protected synchronized Locale getFallbackLocale() throws ServletException { + try { + if (fallbackLocale == null) { + fallbackLocale = new Locale(MirPropertiesConfiguration.instance().getString("Mir.Admin.FallbackLanguage", "en"), ""); + } + } + catch (Throwable t) { + throw new ServletException(t.getMessage()); + } + + return fallbackLocale; + } + + public EntityUsers checkCredentials(HttpServletRequest aRequest) throws ServletException { + try { + EntityUsers user = ServletHelper.getUser(aRequest); + + String username = aRequest.getParameter("login"); + String password = aRequest.getParameter("password"); + + if (username != null && password != null) { + user = usersModule.getUserForLogin(username, password); + + if (user!=null) { + ServletHelper.setUser(aRequest, user); + aRequest.getSession().setAttribute("sessiontracker", new SessionTracker(username)); + } + } + + return user; + } + catch (Throwable t) { + t.printStackTrace(); + + throw new ServletException(t.toString()); + } + } + + public void process(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException, UnavailableException { + try { + long startTime = System.currentTimeMillis(); + long sessionConnectTime = 0; + + HttpSession session = aRequest.getSession(true); + setNoCaching(aResponse); + Locale locale = new Locale(getDefaultLanguage(aRequest), ""); + aResponse.setContentType("text/html; charset=" + + configuration. + getString("Mir.DefaultHTMLCharset", "UTF-8")); + + EntityUsers userEntity = checkCredentials(aRequest); + + if (userEntity == null) { + String queryString = aRequest.getQueryString(); + + if ( (queryString != null) && (queryString.length() != 0) && session.getAttribute("login.target") == null && + (aRequest.getParameter("module")==null || + (!aRequest.getParameter("module").equals("login") && !aRequest.getParameter("module").equals("logout")))) { + session.setAttribute("login.target", queryString); + } + + _sendLoginPage(aResponse, aRequest); + } + else { + String moduleName = aRequest.getParameter("module"); + checkLanguage(session, aRequest); + + if ( ( (moduleName == null) || moduleName.equals(""))) { + moduleName="Admin"; + } + + + if (moduleName.equals("login")) { + String target = (String) session.getAttribute("login.target"); + + if (target != null) { + ServletHelper.redirect(aResponse, target); + } + else { + ServletHelper.redirect(aResponse, ""); + } + } + else if (moduleName.equals("logout")) { + logger.info(userEntity.getValue("login") + " has logged out"); + session.invalidate(); + _sendLoginPage(aResponse, aRequest); + return; + } + else { + try { + ServletModule servletModule = getServletModuleForName(moduleName); + ServletModuleDispatch.dispatch(servletModule, aRequest, aResponse); + + sessionConnectTime = System.currentTimeMillis() - startTime; + logger.info("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms"); + } + catch (Throwable e) { + Throwable cause = ExceptionFunctions.traceCauseException(e); + + if (cause instanceof ServletModuleUserExc) + handleUserError(aRequest, aResponse, (ServletModuleUserExc) cause); + else + handleError(aRequest, aResponse, cause); + } + + if (aRequest.getParameter("killsession")!=null) + aRequest.getSession().invalidate(); + } + } + } + catch (Throwable t) { + t.printStackTrace(); + + throw new ServletException(t.toString()); + } + } + + /** + * caching routine to get a module for a module name + * + * @param moduleName the module name + * @return the requested module + * @throws ServletModuleExc + */ + + private static ServletModule getServletModuleForName(String moduleName) throws ServletModuleExc { + // Instance in Map ? + if (!servletModuleInstanceHash.containsKey(moduleName)) { + // was not found in hash... + try { + Class theServletModuleClass = null; + + try { + // first we try to get ServletModule from stern.che3.servlet + theServletModuleClass = + Class.forName("mircoders.servlet.ServletModule" + moduleName); + } + catch (ClassNotFoundException e) { + // on failure, we try to get it from lib-layer + theServletModuleClass = + Class.forName("mir.servlet.ServletModule" + moduleName); + } + + Method m = theServletModuleClass.getMethod("getInstance", null); + ServletModule smod = (ServletModule) m.invoke(null, null); + + // we put it into map for further reference + servletModuleInstanceHash.put(moduleName, smod); + + return smod; + } + catch (Exception e) { + throw new ServletModuleExc("*** error resolving classname for " + moduleName + " -- " + e.getMessage()); + } + } + else { + return (ServletModule) servletModuleInstanceHash.get(moduleName); + } + } + + private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, ServletModuleUserExc anException) { + try { + logger.info("user error: " + anException.getMessage()); + + Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); + + MessageResources messages = MessageResources.getMessageResources("bundles.admin"); + responseData.put("errorstring", messages.getMessage(getLocale(aRequest), anException.getMessage(), anException.getParameters())); + responseData.put("date", new GregorianCalendar().getTime()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate")); + } + catch (Throwable e) { + logger.error("Error handling user error" + e.toString()); + } + } + + private void handleError(HttpServletRequest aRequest, HttpServletResponse aResponse, Throwable anException) { + try { + logger.error("error: " + anException); + + Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); + + responseData.put("errorstring", anException.toString()); + responseData.put("date", new GregorianCalendar().getTime()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate")); + } + catch (Throwable e) { + logger.error("Error handling error: " + e.toString()); + } + } + + // Redirect-methods + private void _sendLoginPage(HttpServletResponse aResponse, HttpServletRequest aRequest) { + String loginTemplate = configuration.getString("Mir.LoginTemplate"); + + try { + Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); + + responseData.put("defaultlanguage", getDefaultLanguage(aRequest)); + responseData.put("languages", getLoginLanguages()); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, loginTemplate); + } + catch (Throwable e) { + handleError(aRequest, aResponse, e); + } + } + + public String getServletInfo() { + return "Mir " + configuration.getString("Mir.Version"); + } + + private class SessionTracker implements HttpSessionBindingListener { + private String name; + + public SessionTracker(String aUserName) { + name = aUserName; + } + + public void valueBound(HttpSessionBindingEvent anEvent) { + MirGlobal.registerLogin(name); + } + + public void valueUnbound(HttpSessionBindingEvent anEvent) { + MirGlobal.registerLogout(name); + } + } +} diff --git a/source/OpenMir.java b/source/OpenMir.java index cc9e2605..1daa016a 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -40,14 +40,13 @@ import mir.servlet.AbstractServlet; import mir.servlet.ServletModuleDispatch; import mir.servlet.ServletModuleUserExc; import mir.util.ExceptionFunctions; -import mircoders.global.MirGlobal; import mircoders.servlet.ServletModuleOpenIndy; /** * OpenMir.java - main servlet for open posting and comment feature to articles * * @author RK 1999-2001, the mir-coders group - * @version $Id: OpenMir.java,v 1.35.2.1 2003/06/13 03:54:08 zapata Exp $ + * @version $Id: OpenMir.java,v 1.35.2.2 2003/10/23 14:55:26 rk Exp $ * */ diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index 306c6fb5..d675ad61 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -30,13 +30,13 @@ package mir.entity; import java.util.HashMap; +import java.util.Iterator; import java.util.List; -import java.util.*; +import java.util.Map; import mir.config.MirPropertiesConfiguration; import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import mir.log.LoggerWrapper; -import mir.misc.StringUtil; import mir.storage.StorageObject; import mir.storage.StorageObjectExc; import mir.storage.StorageObjectFailure; @@ -45,7 +45,7 @@ import mir.storage.StorageObjectFailure; * Base class the entities are derived from. Provides base functionality of * an entity. Entities are used to represent rows of a database table.

* - * @version $Id: Entity.java,v 1.21.2.4 2003/09/03 17:49:38 zapata Exp $ + * @version $Id: Entity.java,v 1.21.2.5 2003/10/23 14:55:28 rk Exp $ * @author rk * */ @@ -188,7 +188,7 @@ public class Entity } catch (Throwable t) { logger.error("Entity.setValueForProperty: " + t.toString()); - t.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); throw new StorageObjectFailure(t); } diff --git a/source/mir/entity/adapter/EntityAdapterEngine.java b/source/mir/entity/adapter/EntityAdapterEngine.java index 4237c27f..2ef7c694 100755 --- a/source/mir/entity/adapter/EntityAdapterEngine.java +++ b/source/mir/entity/adapter/EntityAdapterEngine.java @@ -1,71 +1,71 @@ -/* - * 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 mir.entity.adapter; - -import java.util.List; - -import mir.entity.EntityBrowser; -import mir.storage.*; - -/** - *

Title:

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

- * @author not attributable - * @version 1.0 - */ - -public class EntityAdapterEngine { - private EntityAdapterEngine() { - } - - /** - * - * @param aStorage - * @param aDefinition - * @param aQualifier - * @param anOrder - * @param aLimit - * @param anOffset - * @return - */ - static public List retrieveAdapterList(EntityAdapterModel aModel, String aDefinition, String aQualifier, String anOrder, int aLimit, int anOffset) { - try { - EntityBrowser browser = new EntityBrowser(aModel.getMappingForName(aDefinition).getStorage(), aQualifier, anOrder, 30, aLimit, anOffset); - - return new EntityListAdapter(aModel, aDefinition, browser, aLimit); - } - catch (Throwable t) { - throw new StorageObjectFailure(t); - } - } +/* + * 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 mir.entity.adapter; + +import java.util.List; + +import mir.entity.EntityBrowser; +import mir.storage.StorageObjectFailure; + +/** + *

Title:

+ *

Description:

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author not attributable + * @version 1.0 + */ + +public class EntityAdapterEngine { + private EntityAdapterEngine() { + } + + /** + * + * @param aStorage + * @param aDefinition + * @param aQualifier + * @param anOrder + * @param aLimit + * @param anOffset + * @return + */ + static public List retrieveAdapterList(EntityAdapterModel aModel, String aDefinition, String aQualifier, String anOrder, int aLimit, int anOffset) { + try { + EntityBrowser browser = new EntityBrowser(aModel.getMappingForName(aDefinition).getStorage(), aQualifier, anOrder, 30, aLimit, anOffset); + + return new EntityListAdapter(aModel, aDefinition, browser, aLimit); + } + catch (Throwable t) { + throw new StorageObjectFailure(t); + } + } } \ No newline at end of file diff --git a/source/mir/generator/FreemarkerGenerator.java b/source/mir/generator/FreemarkerGenerator.java index 8b5ec61d..8ca243bd 100755 --- a/source/mir/generator/FreemarkerGenerator.java +++ b/source/mir/generator/FreemarkerGenerator.java @@ -1,383 +1,385 @@ -/* - * 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 mir.generator; - -import java.io.PrintWriter; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import org.apache.commons.beanutils.MethodUtils; -import org.apache.commons.beanutils.PropertyUtils; -import freemarker.template.FileTemplateCache; -import freemarker.template.SimpleScalar; -import freemarker.template.Template; -import freemarker.template.TemplateHashModel; -import freemarker.template.TemplateListModel; -import freemarker.template.TemplateMethodModel; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; -import freemarker.template.TemplateModelRoot; -import freemarker.template.TemplateScalarModel; -import mir.log.LoggerWrapper; -import mir.util.GeneratorFormatAdapters; -import mir.util.RewindableIterator; - - -public class FreemarkerGenerator implements Generator { - private Template template; - - public FreemarkerGenerator(Template aTemplate) { - template = aTemplate; - } - - public void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure { - if (!(anOutputWriter instanceof PrintWriter)) - throw new GeneratorExc("Writer for a FreemarkerGenerator must be a PrintWriter"); - - try { - template.process((TemplateModelRoot) makeMapAdapter(aValues), (PrintWriter) anOutputWriter); - } - catch (Throwable t) { - t.printStackTrace(); - aLogger.error("Exception occurred: "+t.getMessage()); - t.printStackTrace(aLogger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - throw new GeneratorFailure( t ); - } - } - - private static TemplateScalarModel makeStringAdapter(String aString) { - return new SimpleScalar(aString); - } - - private static TemplateHashModel makeMapAdapter(Map aMap) { - return new MapAdapter(aMap); - } - - private static TemplateListModel makeIteratorAdapter(Iterator anIterator) { - return new IteratorAdapter(anIterator); - } - - private static TemplateMethodModel makeFunctionAdapter(Generator.GeneratorFunction aFunction) { - return new FunctionAdapter(aFunction); - } - - private static TemplateHashModel makeBeanAdapter(Object anObject) { - return new BeanAdapter(anObject); - } - - public static TemplateModel makeAdapter(Object anObject) throws TemplateModelException { - if (anObject == null) - return null; - - if (anObject instanceof TemplateModel) - return (TemplateModel) anObject; - else if (anObject instanceof Generator.GeneratorFunction) - return makeFunctionAdapter((Generator.GeneratorFunction) anObject); - else if (anObject instanceof Integer) - return makeStringAdapter(((Integer) anObject).toString()); - else if (anObject instanceof Boolean) { - if (((Boolean) anObject).booleanValue()) - return makeStringAdapter("1"); - else - return makeStringAdapter("0"); - } - else if (anObject instanceof String) - return makeStringAdapter((String) anObject); - else if (anObject instanceof Map) - return makeMapAdapter((Map) anObject); - else if (anObject instanceof Iterator) - return makeIteratorAdapter((Iterator) anObject); - else if (anObject instanceof List) - return makeIteratorAdapter(((List) anObject).iterator()); - else if (anObject instanceof Number) - return makeAdapter(new GeneratorFormatAdapters.NumberFormatAdapter((Number) anObject)); - else if (anObject instanceof Date) - return makeAdapter(new GeneratorFormatAdapters.DateFormatAdapter((Date) anObject)); - else - return makeBeanAdapter(anObject); - } - - private static class MapAdapter implements TemplateModelRoot { - private Map map; - private Map valuesCache; - - private MapAdapter(Map aMap) { - map = aMap; - valuesCache = new HashMap(); - } - - public void put(String aKey, TemplateModel aModel) { - valuesCache.put(aKey, aModel); - } - - public void remove(String aKey) { - } - - public boolean isEmpty() { - return map.isEmpty(); - } - - public TemplateModel get(String aKey) throws TemplateModelException { - try { - if (!valuesCache.containsKey(aKey)) { - Object value = map.get(aKey); - - if (value == null && !map.containsKey(aKey)) { - throw new TemplateModelException("MapAdapter: no key "+aKey+" available"); - } - - valuesCache.put(aKey, makeAdapter(value)); - } - - return (TemplateModel) valuesCache.get(aKey); - } - catch (TemplateModelException e) { - throw e; - } - catch (Throwable t) { - throw new TemplateModelException(t.getMessage()); - } - } - } - - private static class IteratorAdapter implements TemplateListModel { - private Iterator iterator; - private List valuesCache; - private int position; - - private IteratorAdapter(Iterator anIterator) { - iterator = anIterator; - - valuesCache = new Vector(); - position=0; - - - if (iterator instanceof RewindableIterator) { - ((RewindableIterator) iterator).rewind(); - } - } - - public boolean isEmpty() { - return valuesCache.isEmpty() && !iterator.hasNext(); - } - - private void getUntil(int anIndex) throws TemplateModelException { - while (valuesCache.size()<=anIndex && iterator.hasNext()) - { - valuesCache.add(makeAdapter(iterator.next())); - } - }; - - public TemplateModel get(int anIndex) throws TemplateModelException { - TemplateModel result; - - getUntil(anIndex); - - if (anIndex=valuesCache.size() && i=valuesCache.size() && i\r?\n
){1,}"); - re_mail = new RE("\\b([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)\\b"); - re_url = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])"); - re_tags = new RE("<[^>]*>",RE.REG_ICASE); - re_tables = new RE("<[ \t\r\n/]*(table|td|tr)[ \t\r\n]*>",RE.REG_ICASE); - re_forbiddenTags = new RE("<[ \t\r\n/]*(html|meta|body|head|script)[ \t\r\n]*>",RE.REG_ICASE); - } - catch (REException e){ - System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString()); - } - } - - /** - * Formats a number with the specified minimum and maximum number of digits. - **/ - public static synchronized String zeroPaddingNumber(long value, int minDigits, - int maxDigits) - { - NumberFormat numberFormat = NumberFormat.getInstance(); - numberFormat.setMinimumIntegerDigits(minDigits); - numberFormat.setMaximumIntegerDigits(maxDigits); - return numberFormat.format(value); - } - - /** - * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd) - * @param theDate - * @return 8-ziffriger String (yyyymmdd) - */ - - public static final String date2webdbDate (GregorianCalendar theDate) { - StringBuffer webdbDate = new StringBuffer(); - webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); - webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); - webdbDate.append(pad2(theDate.get(Calendar.DATE))); - return webdbDate.toString(); - } - - /** - * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm) - * @param theDate - * @return 12-ziffriger String (yyyymmdd) - */ - - public static final String date2webdbDateTime (GregorianCalendar theDate) { - StringBuffer webdbDate = new StringBuffer(); - webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); - webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); - webdbDate.append(pad2(theDate.get(Calendar.DATE))); - webdbDate.append(pad2(theDate.get(Calendar.HOUR))); - webdbDate.append(pad2(theDate.get(Calendar.MINUTE))); - return webdbDate.toString(); - } - - /** - * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ) - * @param theDate - * @return w3approved datetime - */ - - public static final String date2w3DateTime (GregorianCalendar theDate) { - StringBuffer webdbDate = new StringBuffer(); - webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); - webdbDate.append("-"); - webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); - webdbDate.append("-"); - webdbDate.append(pad2(theDate.get(Calendar.DATE))); - webdbDate.append("T"); - webdbDate.append(pad2(theDate.get(Calendar.HOUR_OF_DAY))); - webdbDate.append(":"); - webdbDate.append(pad2(theDate.get(Calendar.MINUTE))); - webdbDate.append(":"); - webdbDate.append(pad2(theDate.get(Calendar.SECOND))); - //assumes you are an hour-multiple away from UTC.... - int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000)); - if (offset < 0){ - webdbDate.append("-"); - } - else{ - webdbDate.append("+"); - } - webdbDate.append(pad2(Math.abs(offset))); - webdbDate.append(":00"); - return webdbDate.toString(); - } - - /** - * wandelt Calendar in dd.mm.yyyy / hh.mm um - * @param theDate - * @return String mit (dd.mm.yyyy / hh.mm um) - */ - public static String date2readableDateTime (GregorianCalendar theDate) { - String readable = ""; - int hour; - readable += pad2(theDate.get(Calendar.DATE)); - readable += "." + pad2(theDate.get(Calendar.MONTH) + 1); - readable += "." + String.valueOf(theDate.get(Calendar.YEAR)); - hour = theDate.get(Calendar.HOUR); - if (theDate.get(Calendar.AM_PM) == Calendar.PM) - hour += 12; - readable += " / " + pad2(hour); - readable += ":" + pad2(theDate.get(Calendar.MINUTE)); - return readable; - } - - /** - * deleteForbiddenTags - * this method deletes all