From: zapata Date: Sun, 9 Jan 2005 20:37:06 +0000 (+0000) Subject: * anti-abuse upgrade: filters now stored in the database (experimental) X-Git-Tag: LATEST_MERGED_1_1~160 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=213122e7c65211f549722f05aa8e0135f15af35c;hp=9459916c419db72849e328bb30e0047dc5130420;p=mir.git * anti-abuse upgrade: filters now stored in the database (experimental) * count(*) queries used less often --- diff --git a/bundles/admin_en.properties b/bundles/admin_en.properties index 6e7f4faf..162e8535 100755 --- a/bundles/admin_en.properties +++ b/bundles/admin_en.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: english -# $Id: admin_en.properties,v 1.48.2.23 2004/11/21 22:07:12 zapata Exp $ +# $Id: admin_en.properties,v 1.48.2.24 2005/01/09 20:37:06 zapata Exp $ languagename=English @@ -480,7 +480,7 @@ abuse.articleaction=Action for blocked article abuse.commentaction=Action for blocked comment abuse.showlog=Show the IP log -abuse.showfilters=Manage filters +abuse.showfiltergroups=Manage filters abuse.log.time=Time abuse.log.address=IP number @@ -490,30 +490,41 @@ abuse.log.filtertype=Filter type abuse.log.filterexpression=Expression abuse.filters = Filters -abuse.filters.movedown = down -abuse.filters.moveup = up -abuse.filters.movebottom = bottom -abuse.filters.movetop = top - -abuse.filter.type = Type -abuse.filter.expression = Expression -abuse.filter.articleaction = Article -abuse.filter.commentaction = Comment -abuse.filter.comments = Comments (internal usage) -abuse.filter.lasthit = Last hit -abuse.filter.htmltitle = Edit filter - -abuse.filtertype.ip = IP Number -abuse.filtertype.regexp = Regular expression -abuse.filtertype.useragent= User Agent -abuse.filtertype.throttle = Throttle -abuse.filtertype.hostname = Host name - -abuse.filtererror.title = Error: -abuse.filtererror.invalidtype = Invalid filter type -abuse.filtererror.invalidexpression = Invalid expression for this type - -abuse.filters.htmltitle = Anti-abuse filter rules +filters.movedown = down +filters.moveup = up +filters.movebottom = bottom +filters.movetop = top + +filter.type = Type +filter.expression = Expression +filter.articleaction = Article +filter.commentaction = Comment +filter.comment = Comments (internal usage) +filter.last_hit = Last hit +filter.htmltitle = Edit filter +filter.tag = tag + +filtertype.ip = IP Number +filtertype.regexp = Regular expression +filtertype.useragent= User Agent +filtertype.throttle = Throttle +filtertype.hostname = Host name + +filtererror.title = Error: +filtererror.invalidtype = Invalid filter type +filtererror.invalidexpression = Invalid expression for this type + +filterlist.htmltitle = Filter rules + +filtergroup.name = Name +filtergroup.moveup = up +filtergroup.movedown = down +filtergroup.listfilters = filters +filtergroup.delete = delete +filtergrouplist.htmltitle = Filter groups + + + abuse.log.htmltitle = Anti-abuse open posting log # head diff --git a/dbscripts/create_pg.sql b/dbscripts/create_pg.sql index 31fba74c..27269390 100755 --- a/dbscripts/create_pg.sql +++ b/dbscripts/create_pg.sql @@ -393,3 +393,36 @@ CREATE TABLE "messages" ( "webdb_create" timestamp with time zone NOT NULL ); + +-- +-- filter +-- + +CREATE SEQUENCE "filter_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + +CREATE TABLE "filter" ( + "id" integer DEFAULT nextval('filter_id_seq'::text) NOT NULL, + "priority" integer, + "filter_group_id" integer, + "type" character varying(255) NOT NULL, + "expression" character varying(255) NOT NULL, + "tag" character varying(255) NOT NULL, + "comment" text, + "articleaction" character varying(255) NOT NULL, + "commentaction" character varying(255) NOT NULL, + "last_hit" timestamp with time zone +); + +-- +-- filter_group +-- + +CREATE SEQUENCE "filter_group_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + +CREATE TABLE "filter_group" ( + "id" integer DEFAULT nextval('filter_group_id_seq'::text) NOT NULL, + "name" character varying(255), + "priority" integer +); + + diff --git a/dbscripts/updates/update20050109.sql b/dbscripts/updates/update20050109.sql new file mode 100755 index 00000000..ce20f61e --- /dev/null +++ b/dbscripts/updates/update20050109.sql @@ -0,0 +1,39 @@ +-- update script 2003-12-12 by rk +-- +-- * adds filter and filtergroups to the database +-- +-- This script will terminate with an error the second time it's run, +-- so running this script when it isn't needed can't do any harm. +-- + +BEGIN TRANSACTION; + +CREATE SEQUENCE "filter_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + +CREATE TABLE "filter" ( + "id" integer DEFAULT nextval('filter_id_seq'::text) NOT NULL, + "priority" integer, + "filter_group_id" integer, + "type" character varying(255) NOT NULL, + "expression" character varying(255) NOT NULL, + "tag" character varying(255) NOT NULL, + "comment" text, + "articleaction" character varying(255) NOT NULL, + "commentaction" character varying(255) NOT NULL, + "last_hit" timestamp with time zone +); + +-- +-- filter_group +-- + +CREATE SEQUENCE "filter_group_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; + +CREATE TABLE "filter_group" ( + "id" integer DEFAULT nextval('filter_group_id_seq'::text) NOT NULL, + "name" character varying(255), + "priority" integer +); + +COMMIT TRANSACTION; + diff --git a/etc/objectstore.properties b/etc/objectstore.properties deleted file mode 100755 index 2bded21f..00000000 --- a/etc/objectstore.properties +++ /dev/null @@ -1,6 +0,0 @@ -StoreContainer.EntityDefaultSize 45 -StoreContainer.EntityListDefaultSize 15 -StorableObjectEntity.Entity.DefaultSize 300 -StorableObjectEntity.EntityList.DefaultSize 100 -EntityTopics.Entity.DefaultSize 200 -EntityTopics.EntityList.DefaultSize 20 diff --git a/source/Mir.java b/source/Mir.java index 91be32de..515d1ee1 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -45,6 +45,8 @@ import javax.servlet.UnavailableException; import javax.servlet.http.*; import java.io.IOException; import java.io.PrintWriter; +import java.io.PrintStream; +import java.io.StringWriter; import java.lang.reflect.Method; import java.util.*; @@ -319,6 +321,9 @@ public class Mir extends AbstractServlet { Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale()}); responseData.put("errorstring", anException.toString()); + StringWriter writer = new StringWriter(); + anException.printStackTrace(new PrintWriter(writer)); + responseData.put("stacktrace", writer.toString()); responseData.put("date", new GregorianCalendar().getTime()); ServletHelper.generateResponse(aResponse.getWriter(), responseData, MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate")); diff --git a/source/default.properties b/source/default.properties index 5b6d8415..187f383a 100755 --- a/source/default.properties +++ b/source/default.properties @@ -520,6 +520,7 @@ ServletModule.MediaType.DeleteConfirmationTemplate=confirm.template ServletModule.MediaType.EditTemplate=mediatype.template ServletModule.MediaType.ListTemplate=mediatypelist.template + # # Object store configuration # @@ -528,8 +529,8 @@ StoreContainer.EntityDefaultSize= 45 StoreContainer.EntityListDefaultSize= 15 StorableObjectEntity.Entity.DefaultSize= 300 StorableObjectEntity.EntityList.DefaultSize= 100 -EntityTopics.Entity.DefaultSize= 200 -EntityTopics.EntityList.DefaultSize= 20 +EntityTopics.Entity.DefaultSize=200 +EntityTopics.EntityList.DefaultSize=20 @@ -538,8 +539,10 @@ EntityTopics.EntityList.DefaultSize= 20 # # config for abuse -ServletModule.Abuse.EditFilter.Template = abuse.filter.template -ServletModule.Abuse.ListFilters.Template = abuse.filters.template +ServletModule.Abuse.EditFilter.Template = filter.template +ServletModule.Abuse.ListFilters.Template = filterlist.template +ServletModule.Abuse.EditFilterGroup.Template = filtergroup.template +ServletModule.Abuse.ListFilterGroups.Template = filtergrouplist.template ServletModule.Abuse.ViewLog.Template = abuse.log.template ServletModule.Abuse.Main.Template = abuse.template diff --git a/source/mir/entity/AbstractEntity.java b/source/mir/entity/AbstractEntity.java index a4e6585f..5cfd8292 100755 --- a/source/mir/entity/AbstractEntity.java +++ b/source/mir/entity/AbstractEntity.java @@ -35,7 +35,6 @@ import java.util.List; import java.util.Map; import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import mir.log.LoggerWrapper; import mir.storage.StorageObject; import mir.storage.StorageObjectExc; @@ -45,7 +44,7 @@ import mir.storage.StorageObjectFailure; * Base class the entities are derived from. Provides base functionality of * an entity. * - * @version $Id: AbstractEntity.java,v 1.8.2.3 2004/11/21 22:07:13 zapata Exp $ + * @version $Id: AbstractEntity.java,v 1.8.2.4 2005/01/09 20:37:07 zapata Exp $ */ public class AbstractEntity implements Entity { @@ -61,18 +60,8 @@ public class AbstractEntity implements Entity { values = new HashMap(); } - /** - * Constructor - * @param StorageObject The StorageObject of the Entity. - */ - public AbstractEntity(StorageObject StorageObject) { - this(); - - setStorage(StorageObject); - } - - public void setStorage(StorageObject storage) { - this.storageObject = storage; + public void setStorage(StorageObject aStorageObject) { + storageObject = aStorageObject; } /** {@inheritDoc} */ diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index a0e6e7a5..7aa6574f 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -29,29 +29,20 @@ */ package mir.entity; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; -import mir.log.LoggerWrapper; -import mir.storage.StorageObject; import mir.storage.StorageObjectExc; import mir.storage.StorageObjectFailure; +import java.util.List; +import java.util.Map; + /** * An Entity represents a persistent data object, typically * stored in a database.

* - * @version $Id: Entity.java,v 1.21.2.8 2004/02/08 21:05:01 zapata Exp $ + * @version $Id: Entity.java,v 1.21.2.9 2005/01/09 20:37:07 zapata Exp $ */ -public interface Entity -{ - public void setStorage(StorageObject storage); - +public interface Entity { /** * Sets the values of the Entity. (Only to be called by the Storage Object) * diff --git a/source/mir/entity/adapter/EntityAdapterEngine.java b/source/mir/entity/adapter/EntityAdapterEngine.java index 2ef7c694..f1ba0305 100755 --- a/source/mir/entity/adapter/EntityAdapterEngine.java +++ b/source/mir/entity/adapter/EntityAdapterEngine.java @@ -50,7 +50,7 @@ public class EntityAdapterEngine { /** * - * @param aStorage + * @param aModel * @param aDefinition * @param aQualifier * @param anOrder diff --git a/source/mir/entity/adapter/EntityAdapterFailure.java b/source/mir/entity/adapter/EntityAdapterFailure.java index 8620a93d..025379e7 100755 --- a/source/mir/entity/adapter/EntityAdapterFailure.java +++ b/source/mir/entity/adapter/EntityAdapterFailure.java @@ -32,8 +32,8 @@ package mir.entity.adapter; import multex.Failure; public class EntityAdapterFailure extends Failure { - public EntityAdapterFailure(String msg,Throwable cause) { - super(msg,cause); + public EntityAdapterFailure(String msg, Throwable cause) { + super(msg, cause); } public EntityAdapterFailure(Throwable aCause) { diff --git a/source/mir/entity/adapter/EntityAdapterModel.java b/source/mir/entity/adapter/EntityAdapterModel.java index 0d4ea50f..598596b3 100755 --- a/source/mir/entity/adapter/EntityAdapterModel.java +++ b/source/mir/entity/adapter/EntityAdapterModel.java @@ -42,7 +42,7 @@ public class EntityAdapterModel { entityAdapterMappings = new HashMap(); } - public EntityAdapter makeEntityAdapter( String aName, Entity anEntity ) throws EntityAdapterExc { + public EntityAdapter makeEntityAdapter( String aName, Entity anEntity ) { Mapping mapping = getMappingForName( aName ); return mapping.getDefinition().makeEntityAdapter( anEntity, this ); @@ -51,9 +51,7 @@ public class EntityAdapterModel { public EntityAdapter createNewEntity( String aName ) throws EntityAdapterExc { try { Mapping mapping = getMappingForName(aName); - StorageObject storage = mapping.storage; - Entity entity = (Entity) storage.getEntityClass().newInstance(); - entity.setStorage(storage); + Entity entity = mapping.storage.createNewEntity(); return mapping.getDefinition().makeEntityAdapter(entity, this); } @@ -66,9 +64,9 @@ public class EntityAdapterModel { entityAdapterMappings.put( aName, new Mapping( aStorage, aDefinition ) ); } - public Mapping getMappingForName( String aName ) throws EntityAdapterExc { + public Mapping getMappingForName( String aName ) { if (!entityAdapterMappings.containsKey(aName)) - throw new EntityAdapterExc( "'" + aName + "' not present in model" ); + throw new EntityAdapterFailure("'" + aName + "' not present in model", null); return (Mapping) entityAdapterMappings.get( aName ); } diff --git a/source/mir/entity/adapter/EntityIteratorAdapter.java b/source/mir/entity/adapter/EntityIteratorAdapter.java index dfa9ae7d..bdcb42db 100755 --- a/source/mir/entity/adapter/EntityIteratorAdapter.java +++ b/source/mir/entity/adapter/EntityIteratorAdapter.java @@ -49,20 +49,20 @@ public class EntityIteratorAdapter implements RewindableIterator { public EntityIteratorAdapter(String aWhereClause, String anOrderByClause, int aBatchSize, EntityAdapterModel aModel, String aDefinitionName ) - throws StorageObjectFailure, EntityAdapterExc { + throws StorageObjectFailure { this(new EntityBrowser(aModel.getMappingForName(aDefinitionName).getStorage(), aWhereClause, anOrderByClause, aBatchSize), aModel, aDefinitionName); } public EntityIteratorAdapter(String aWhereClause, String anOrderByClause, int aBatchSize, EntityAdapterModel aModel, String aDefinitionName, - int aLimit, int aSkip) throws StorageObjectFailure, EntityAdapterExc { + int aLimit, int aSkip) throws StorageObjectFailure { this(new EntityBrowser(aModel.getMappingForName(aDefinitionName).getStorage(), aWhereClause, anOrderByClause, aBatchSize, aLimit, aSkip), aModel, aDefinitionName); } public EntityIteratorAdapter(String aMainTablePrefix, List someExtraTables, String aWhereClause, String anOrderByClause, int aBatchSize, EntityAdapterModel aModel, String aDefinitionName, - int aLimit, int aSkip) throws StorageObjectFailure, EntityAdapterExc { + int aLimit, int aSkip) throws StorageObjectFailure { this(new EntityBrowser(aModel.getMappingForName(aDefinitionName).getStorage(), aMainTablePrefix, someExtraTables, aWhereClause, anOrderByClause, aBatchSize, aLimit, aSkip), aModel, aDefinitionName); } @@ -72,12 +72,7 @@ public class EntityIteratorAdapter implements RewindableIterator { } public Object next() { - try { - return model.makeEntityAdapter(definitionName, (Entity) iterator.next()); - } - catch (EntityAdapterExc e) { - return null; - } + return model.makeEntityAdapter(definitionName, (Entity) iterator.next()); } public void remove() { diff --git a/source/mir/entity/adapter/ToManyRelationField.java b/source/mir/entity/adapter/ToManyRelationField.java new file mode 100755 index 00000000..5c9c889f --- /dev/null +++ b/source/mir/entity/adapter/ToManyRelationField.java @@ -0,0 +1,56 @@ +/* + * 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; + +public class ToManyRelationField implements EntityAdapterDefinition.CalculatedField{ + private String fromField; + private String toField; + private String toEntity; + private String orderByField; + + public ToManyRelationField(String aFromField, String aToEntity, String aToField, String anOrderByField) { + fromField = aFromField; + toField = aToField; + toEntity = aToEntity; + orderByField = anOrderByField; + } + + public Object getValue(EntityAdapter anEntityAdapter) { + try { + return anEntityAdapter.getRelation( + toField + "=" + anEntityAdapter.get(fromField), + orderByField, + toEntity); + } + catch (Throwable t) { + throw new RuntimeException(t.getMessage()); + } + } +} diff --git a/source/mir/entity/adapter/ToOneRelationField.java b/source/mir/entity/adapter/ToOneRelationField.java new file mode 100755 index 00000000..d99ab9bc --- /dev/null +++ b/source/mir/entity/adapter/ToOneRelationField.java @@ -0,0 +1,54 @@ +/* + * 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; + +public class ToOneRelationField implements EntityAdapterDefinition.CalculatedField{ + private String fromField; + private String toField; + private String toEntity; + + public ToOneRelationField(String aFromField, String aToEntity, String aToField) { + fromField = aFromField; + toField = aToField; + toEntity = aToEntity; + } + + public Object getValue(EntityAdapter anEntityAdapter) { + try { + return anEntityAdapter.getToOneRelation( + toField + "=" + anEntityAdapter.get(fromField), + toField, + toEntity); + } + catch (Throwable t) { + throw new RuntimeException(t.getMessage()); + } + } +} diff --git a/source/mir/generator/FreemarkerGenerator.java b/source/mir/generator/FreemarkerGenerator.java index d4a4ee7b..b774a1d8 100755 --- a/source/mir/generator/FreemarkerGenerator.java +++ b/source/mir/generator/FreemarkerGenerator.java @@ -363,7 +363,8 @@ public class FreemarkerGenerator implements Generator { Template template = (Template) templateCache.getItem(anIdentifier, "template"); if (template==null) { - throw new GeneratorExc("FreemarkerGeneratorLibrary: Can't find template "+templateCache.getDirectory()+"/"+anIdentifier); + throw new GeneratorExc("FreemarkerGeneratorLibrary: Can't find template " + + templateCache.getDirectory() + File.separatorChar + anIdentifier); } return new FreemarkerGenerator(template); diff --git a/source/mir/generator/VelocityGenerator.java b/source/mir/generator/VelocityGenerator.java index 1735701d..31a671bd 100755 --- a/source/mir/generator/VelocityGenerator.java +++ b/source/mir/generator/VelocityGenerator.java @@ -29,17 +29,9 @@ */ package mir.generator; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.File; -import java.util.AbstractList; -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 mir.log.LoggerWrapper; +import mir.util.GeneratorFormatAdapters; +import mir.util.RewindableIterator; import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.beanutils.PropertyUtils; import org.apache.velocity.Template; @@ -49,9 +41,11 @@ import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.RuntimeServices; import org.apache.velocity.runtime.log.LogSystem; -import mir.log.LoggerWrapper; -import mir.util.GeneratorFormatAdapters; -import mir.util.RewindableIterator; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.*; public class VelocityGenerator implements Generator { private String templateIdentifier; @@ -229,7 +223,7 @@ public class VelocityGenerator implements Generator { } public Object call(Object aParameters[]) throws GeneratorExc { - List parameters = new Vector(); + List parameters = new ArrayList(); for (int i = 0; i, the Mir-coders group - * @version $Id: MediaHandler.java,v 1.1.2.3 2004/11/21 22:07:13 zapata Exp $ + * @version $Id: MediaHandler.java,v 1.1.2.4 2005/01/09 20:37:08 zapata Exp $ */ public interface MediaHandler { diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index aea424ba..94fbffb1 100755 --- a/source/mir/module/AbstractModule.java +++ b/source/mir/module/AbstractModule.java @@ -98,27 +98,12 @@ public class AbstractModule { * @exception ModuleExc * @exception ModuleFailure */ - public String add (Map theValues) throws ModuleExc, ModuleFailure { + public String add(Map theValues) throws ModuleExc, ModuleFailure { try { - Entity theEntity = (Entity)storage.getEntityClass().newInstance(); - theEntity.setStorage(storage); - theEntity.setFieldValues(theValues); - return theEntity.insert(); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * This function creates an Entity without yet storing it in the database - */ - public Entity createNew() throws ModuleExc, ModuleFailure { - try { - Entity result = (Entity)storage.getEntityClass().newInstance(); - result.setStorage(storage); + Entity entity = storage.createNewEntity(); + entity.setFieldValues(theValues); - return result; + return entity.insert(); } catch (Throwable e) { throw new ModuleFailure(e); @@ -134,7 +119,7 @@ public class AbstractModule { */ public String set (Map theValues) throws ModuleExc, ModuleFailure { try { - Entity theEntity = storage.selectById((String)theValues.get("id")); + Entity theEntity = storage.selectById((String) theValues.get("id")); if (theEntity == null) throw new ModuleExc("No object found with id " + theValues.get("id")); theEntity.setFieldValues(theValues); diff --git a/source/mir/producer/reader/ScriptedProducerFactory.java b/source/mir/producer/reader/ScriptedProducerFactory.java index 1964b3cd..5825ae96 100755 --- a/source/mir/producer/reader/ScriptedProducerFactory.java +++ b/source/mir/producer/reader/ScriptedProducerFactory.java @@ -29,7 +29,6 @@ */ package mir.producer.reader; -import java.util.Iterator; import java.util.List; import java.util.Map; diff --git a/source/mir/rss/RSS091Reader.java b/source/mir/rss/RSS091Reader.java index a6556b72..3a01811c 100755 --- a/source/mir/rss/RSS091Reader.java +++ b/source/mir/rss/RSS091Reader.java @@ -29,17 +29,13 @@ */ package mir.rss; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - import mir.util.HTTPClientHelper; -import mir.util.xml.*; import mir.util.xml.XMLParserEngine; +import mir.util.xml.XMLParserExc; +import mir.util.xml.XMLParserFailure; + +import java.io.InputStream; +import java.util.*; /** * @@ -205,7 +201,7 @@ public class RSS091Reader { public RSS091ChannelSectionHandler(RSSData aData) { data = aData; - items = new Vector(); + items = new ArrayList(); channel = new RDFResource("rss:channel"); attributes = new HashMap(); } @@ -326,7 +322,7 @@ public class RSS091Reader { private List items; public RDFSequenceSectionHandler() { - items = new Vector(); + items = new ArrayList(); } public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { diff --git a/source/mir/rss/RSSReader.java b/source/mir/rss/RSSReader.java index 6d89d49c..ad2958a8 100755 --- a/source/mir/rss/RSSReader.java +++ b/source/mir/rss/RSSReader.java @@ -41,16 +41,6 @@ import mir.util.xml.XMLParserEngine; import mir.util.xml.XMLParserExc; import mir.util.xml.XMLParserFailure; -/** - * - *

Title:

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

- * @author not attributable - * @version 1.0 - */ - public class RSSReader { public static final String RDF_NAMESPACE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; public static final String RSS_1_0_NAMESPACE_URI = "http://purl.org/rss/1.0/"; @@ -141,7 +131,7 @@ public class RSSReader { public RSSData parseUrl(String anUrl) throws RSSExc, RSSFailure { try { - HTTPClientHelper httpClientHelper = new HTTPClientHelper(); + HTTPClientHelper httpClientHelper = new HTTPClientHelper(); InputStream inputStream = httpClientHelper.getUrl(anUrl); if (inputStream==null) throw new RSSExc("RSSChannel.parseUrl: Can't get url content"); diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index d2d89e8f..02d4761f 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -29,11 +29,8 @@ */ package mir.servlet; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -48,18 +45,11 @@ import mir.storage.StorageObject; import mir.util.HTTPRequestParser; import mir.util.URLBuilder; import mircoders.global.MirGlobal; -import mircoders.servlet.ServletHelper; import mircoders.localizer.MirLocalizerExc; -import multex.Failure; +import mircoders.servlet.ServletHelper; /** * - *

Title:

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

- * @author not attributable - * @version 1.0 */ public abstract class ServletModule { @@ -77,8 +67,16 @@ public abstract class ServletModule { protected String deleteConfirmationGenerator; protected int nrEntitiesPerListPage; + /** the list of parameters that need to be propagated in the list */ + protected List propagatedParameters = new ArrayList(); public ServletModule(){ + propagatedParameters.add("searchfield"); + propagatedParameters.add("searchtext"); + propagatedParameters.add("searchispublished"); + propagatedParameters.add("searchstatus"); + propagatedParameters.add("searchorder"); + definition = null; try { model = MirGlobal.localizer().dataModel().adapterModel(); @@ -88,8 +86,6 @@ public abstract class ServletModule { throw new ServletModuleFailure("Can't retrieve model", e); } - - listGenerator = configuration.getString("ServletModule."+getOperationModuleName()+".ListTemplate"); editGenerator = configuration.getString("ServletModule."+getOperationModuleName()+".EditTemplate"); deleteConfirmationGenerator = configuration.getString("ServletModule."+getOperationModuleName()+".DeleteConfirmationTemplate"); @@ -129,17 +125,17 @@ public abstract class ServletModule { * this supersedes getLanguage for the new i18n */ public static Locale getLocale(HttpServletRequest aRequest) { - Locale loc = null; + Locale locale = null; HttpSession session = aRequest.getSession(false); if (session != null) { // session can be null in case of logout - loc = (Locale) session.getAttribute("locale"); + locale = (Locale) session.getAttribute("locale"); } // if there is nothing in the session get it fron the accept-language - if (loc == null) { - loc = aRequest.getLocale(); + if (locale == null) { + locale = aRequest.getLocale(); } - return loc; + return locale; } /** @@ -158,7 +154,7 @@ public abstract class ServletModule { */ public String getDefaultListOrdering() { - if (mainModule!=null && mainModule.getStorageObject()!=null){ + if (mainModule!=null && mainModule.getStorageObject()!=null) { if (mainModule.getStorageObject().getFieldNames().contains("webdb_create")) return "webdb_create desc"; } @@ -170,8 +166,7 @@ public abstract class ServletModule { * Generic list servlet method */ - public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc - { + public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); String where = requestParser.getParameter("where"); @@ -184,10 +179,13 @@ public abstract class ServletModule { public void returnList(HttpServletRequest aRequest, HttpServletResponse aResponse, String aWhereClause, String anOrderByClause, int anOffset) throws ServletModuleExc { + returnList(aRequest, aResponse, aWhereClause, anOrderByClause, anOffset, Collections.EMPTY_MAP); + } - HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); + public void returnList(HttpServletRequest aRequest, HttpServletResponse aResponse, + String aWhereClause, String anOrderByClause, int anOffset, Map anOverridingRequestParameters) throws ServletModuleExc { + HTTPRequestParser requestParser = new HTTPRequestParser(aRequest, anOverridingRequestParameters); URLBuilder urlBuilder = new URLBuilder(); - int count; try { Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, getLocales(aRequest)); @@ -199,30 +197,19 @@ public abstract class ServletModule { responseData.put("prevurl", null); responseData.put("module", getOperationModuleName()); - count=mainModule.getSize(aWhereClause); - urlBuilder.setValue("module", getOperationModuleName()); urlBuilder.setValue("do", "list"); urlBuilder.setValue("where", aWhereClause); urlBuilder.setValue("order", anOrderByClause); - urlBuilder.setValue("searchfield", requestParser.getParameter("searchfield")); - urlBuilder.setValue("searchtext", requestParser.getParameter("searchtext")); - urlBuilder.setValue("searchispublished", requestParser.getParameter("searchispublished")); - urlBuilder.setValue("searchstatus", requestParser.getParameter("searchstatus")); - urlBuilder.setValue("searchorder", requestParser.getParameter("searchorder")); - - responseData.put("searchfield", requestParser.getParameter("searchfield")); - responseData.put("searchtext", requestParser.getParameter("searchtext")); - responseData.put("searchispublished", requestParser.getParameter("searchispublished")); - responseData.put("searchstatus", requestParser.getParameter("searchstatus")); - responseData.put("searchorder", requestParser.getParameter("searchorder")); urlBuilder.setValue("offset", anOffset); responseData.put("offset" , new Integer(anOffset).toString()); responseData.put("thisurl" , urlBuilder.getQuery()); - if (count>anOffset+nrEntitiesPerListPage) { + propagateFields(requestParser, urlBuilder, responseData); + + if (list.size()>=nrEntitiesPerListPage) { urlBuilder.setValue("offset", anOffset + nrEntitiesPerListPage); responseData.put("nexturl" , urlBuilder.getQuery()); } @@ -234,8 +221,8 @@ public abstract class ServletModule { responseData.put("entities", list); responseData.put("from" , Integer.toString(anOffset+1)); - responseData.put("count", Integer.toString(count)); - responseData.put("to", Integer.toString(Math.min(anOffset+nrEntitiesPerListPage, count))); + responseData.put("count", "?"); + responseData.put("to", Integer.toString(anOffset+list.size()-1)); ServletHelper.generateResponse(aResponse.getWriter(), responseData, listGenerator); } @@ -471,4 +458,14 @@ public abstract class ServletModule { } return withValues; } + + private void propagateFields(HTTPRequestParser aRequest, URLBuilder aUrlBuilder, Map aResponseData) { + Iterator i = propagatedParameters.iterator(); + while (i.hasNext()) { + String parameter = (String) i.next(); + String value = aRequest.getParameter(parameter); + aUrlBuilder.setValue(parameter, value); + aResponseData.put(parameter, value); + } + } } \ No newline at end of file diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index 98767916..f41f5058 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -33,6 +33,7 @@ import mir.config.MirPropertiesConfiguration; import mir.entity.Entity; import mir.entity.EntityList; import mir.entity.StorableObjectEntity; +import mir.entity.AbstractEntity; import mir.log.LoggerWrapper; import mir.misc.StringUtil; import mir.storage.store.*; @@ -51,7 +52,7 @@ import java.util.*; /** * Implements database access. * - * @version $Id: Database.java,v 1.44.2.23 2004/11/21 22:07:13 zapata Exp $ + * @version $Id: Database.java,v 1.44.2.24 2005/01/09 20:37:09 zapata Exp $ * @author rk * */ @@ -70,8 +71,7 @@ public class Database implements StorageObject { protected List fieldNames; protected int[] fieldTypes; - protected Class theEntityClass; - protected boolean hasTimestamp = true; + protected Class entityClass; private int defaultLimit; TimeZone timezone; @@ -100,7 +100,7 @@ public class Database implements StorageObject { defaultLimit = Integer.parseInt(configuration.getString("Database.Limit")); try { - theEntityClass = GENERIC_ENTITY_CLASS; + entityClass = GENERIC_ENTITY_CLASS; } catch (Throwable e) { logger.error("Error in Database() constructor with " + theAdaptorName + " -- " + e.getMessage()); @@ -116,7 +116,19 @@ public class Database implements StorageObject { * @return Class-Objekt der Entity */ public java.lang.Class getEntityClass() { - return theEntityClass; + return entityClass; + } + + public Entity createNewEntity() throws StorageObjectFailure { + try { + AbstractEntity result = (AbstractEntity) entityClass.newInstance(); + result.setStorage(this); + + return result; + } + catch (Throwable t) { + throw new StorageObjectFailure(t); + } } /** @@ -315,14 +327,14 @@ public class Database implements StorageObject { } // ask object store for object - if (StoreUtil.extendsStorableEntity(theEntityClass)) { + if (StoreUtil.extendsStorableEntity(entityClass)) { String uniqueId = id; - if (theEntityClass.equals(StorableObjectEntity.class)) { + if (entityClass.equals(StorableObjectEntity.class)) { uniqueId += ("@" + mainTable); } - StoreIdentifier search_sid = new StoreIdentifier(theEntityClass, uniqueId); + StoreIdentifier search_sid = new StoreIdentifier(entityClass, uniqueId); logger.debug("CACHE: (dbg) looking for sid " + search_sid.toString()); Entity hit = (Entity) o_store.use(search_sid); @@ -503,8 +515,8 @@ public class Database implements StorageObject { // check o_store for entitylist // only if no relational select if (anExtraTables==null) { - if (StoreUtil.extendsStorableEntity(theEntityClass)) { - StoreIdentifier searchSid = new StoreIdentifier(theEntityClass, + if (StoreUtil.extendsStorableEntity(entityClass)) { + StoreIdentifier searchSid = new StoreIdentifier(entityClass, StoreContainerType.STOC_TYPE_ENTITYLIST, StoreUtil.getEntityListUniqueIdentifierFor(mainTable, aWhereClause, anOrderByClause, anOffset, aLimit)); @@ -617,7 +629,7 @@ public class Database implements StorageObject { theReturnList.setNextBatch(anOffset + aLimit); } - if (anExtraTables==null && StoreUtil.extendsStorableEntity(theEntityClass)) { + if (anExtraTables==null && StoreUtil.extendsStorableEntity(entityClass)) { StoreIdentifier sid = theReturnList.getStoreIdentifier(); logger.debug("CACHE (add): " + sid.toString()); o_store.add(sid); @@ -639,12 +651,6 @@ public class Database implements StorageObject { return theReturnList; } - /** - * Bastelt aus einer Zeile der Datenbank ein EntityObjekt. - * - * @param rs Das ResultSetObjekt. - * @return Entity Die Entity. - */ private Entity makeEntityFromResultSet(ResultSet rs) throws StorageObjectFailure { Map theResultHash = new HashMap(); @@ -653,9 +659,9 @@ public class Database implements StorageObject { Entity returnEntity = null; try { - if (StoreUtil.extendsStorableEntity(theEntityClass)) { + if (StoreUtil.extendsStorableEntity(entityClass)) { StoreIdentifier searchSid = StorableObjectEntity.getStoreIdentifier(this, - theEntityClass, rs); + entityClass, rs); Entity hit = (Entity) o_store.use(searchSid); if (hit != null) return hit; } @@ -693,9 +699,8 @@ public class Database implements StorageObject { } } - if (theEntityClass != null) { - returnEntity = (Entity) theEntityClass.newInstance(); - returnEntity.setStorage(this); + if (entityClass != null) { + returnEntity = createNewEntity(); returnEntity.setFieldValues(theResultHash); if (returnEntity instanceof StorableObject) { @@ -703,18 +708,12 @@ public class Database implements StorageObject { o_store.add(((StorableObject) returnEntity).getStoreIdentifier()); } } else { - throwStorageObjectException("Internal Error: theEntityClass not set!"); + throwStorageObjectException("Internal Error: entityClass not set!"); } } - catch (IllegalAccessException e) { - throwStorageObjectException("No access! -- " + e.getMessage()); - } catch (IOException e) { throwStorageObjectException("IOException! -- " + e.getMessage()); } - catch (InstantiationException e) { - throwStorageObjectException("No Instatiation! -- " + e.getMessage()); - } catch (SQLException sqe) { throwSQLException(sqe, "makeEntityFromResultSet"); @@ -727,10 +726,10 @@ public class Database implements StorageObject { /** * Inserts an entity into the database. * - * @param theEntity + * @param anEntity * @return der Wert des Primary-keys der eingef?gten Entity */ - public String insert(Entity theEntity) throws StorageObjectFailure { + public String insert(Entity anEntity) throws StorageObjectFailure { invalidateStore(); String returnId = null; @@ -752,16 +751,16 @@ public class Database implements StorageObject { aValue = null; // exceptions - if (!theEntity.hasFieldValue(aField) && ( + if (!anEntity.hasFieldValue(aField) && ( aField.equals("webdb_create") || aField.equals("webdb_lastchange"))) { aValue = "NOW()"; } else { - if (theEntity.hasFieldValue(aField)) { + if (anEntity.hasFieldValue(aField)) { aValue = "'" + - JDBCStringRoutines.escapeStringLiteral(theEntity.getFieldValue(aField)) + "'"; + JDBCStringRoutines.escapeStringLiteral(anEntity.getFieldValue(aField)) + "'"; } } @@ -803,7 +802,7 @@ public class Database implements StorageObject { // pstmt = con.prepareStatement("select currval('" + + "_id_seq')"); returnId = getLatestInsertedId(con); - theEntity.setId(returnId); + anEntity.setId(returnId); } catch (SQLException sqe) { throwSQLException(sqe, "insert"); @@ -938,17 +937,17 @@ public class Database implements StorageObject { */ public boolean delete(String id) throws StorageObjectFailure { // ostore send notification - if (StoreUtil.extendsStorableEntity(theEntityClass)) { + if (StoreUtil.extendsStorableEntity(entityClass)) { String uniqueId = id; - if (theEntityClass.equals(StorableObjectEntity.class)) { + if (entityClass.equals(StorableObjectEntity.class)) { uniqueId += ("@" + mainTable); } logger.debug("CACHE: (del) " + id); StoreIdentifier search_sid = - new StoreIdentifier(theEntityClass, + new StoreIdentifier(entityClass, StoreContainerType.STOC_TYPE_ENTITY, uniqueId); o_store.invalidate(search_sid); } @@ -1337,10 +1336,10 @@ public class Database implements StorageObject { * Invalidates any cached entity list */ private void invalidateStore() { - // invalidating all EntityLists corresponding with theEntityClass - if (StoreUtil.extendsStorableEntity(theEntityClass)) { + // invalidating all EntityLists corresponding with entityClass + if (StoreUtil.extendsStorableEntity(entityClass)) { StoreContainerType stoc_type = - StoreContainerType.valueOf(theEntityClass, StoreContainerType.STOC_TYPE_ENTITYLIST); + StoreContainerType.valueOf(entityClass, StoreContainerType.STOC_TYPE_ENTITYLIST); o_store.invalidate(stoc_type); } } diff --git a/source/mir/storage/StorageObject.java b/source/mir/storage/StorageObject.java index 5f4ecc9e..483fde52 100755 --- a/source/mir/storage/StorageObject.java +++ b/source/mir/storage/StorageObject.java @@ -77,6 +77,8 @@ public interface StorageObject { public Class getEntityClass(); + public Entity createNewEntity() throws StorageObjectFailure; + public String getIdName(); public String getTableName(); diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java index 358a5c5b..fab5a7d2 100755 --- a/source/mir/storage/store/StoreIdentifier.java +++ b/source/mir/storage/store/StoreIdentifier.java @@ -62,8 +62,6 @@ public class StoreIdentifier { protected LoggerWrapper logger = new LoggerWrapper("Database.ObjectStore"); - /** @todo initialize logfile */ - private StoreIdentifier() {} public StoreIdentifier(StorableObject reference, int storeType, @@ -91,12 +89,6 @@ public class StoreIdentifier { this.stocType = StoreContainerType.valueOf(theClass, storeType); } - /** - * Method: ivalidate - * Description: - * - * @return - */ public void invalidate() { logger.info("Invalidating: " + toString()); // avoid deadlock due to propagation. diff --git a/source/mir/util/CachingRewindableIterator.java b/source/mir/util/CachingRewindableIterator.java index 5b6b2a36..1bbfc0a8 100755 --- a/source/mir/util/CachingRewindableIterator.java +++ b/source/mir/util/CachingRewindableIterator.java @@ -29,10 +29,9 @@ */ package mir.util; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Vector; -import java.util.ArrayList; public class CachingRewindableIterator implements RewindableIterator { private Iterator master; diff --git a/source/mir/util/ExceptionFunctions.java b/source/mir/util/ExceptionFunctions.java index d831028e..916692c7 100755 --- a/source/mir/util/ExceptionFunctions.java +++ b/source/mir/util/ExceptionFunctions.java @@ -29,10 +29,9 @@ */ package mir.util; -import java.lang.reflect.InvocationTargetException; -import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; import multex.Failure; diff --git a/source/mir/util/HTTPClientHelper.java b/source/mir/util/HTTPClientHelper.java index 666f4cf7..be02f67e 100755 --- a/source/mir/util/HTTPClientHelper.java +++ b/source/mir/util/HTTPClientHelper.java @@ -31,16 +31,13 @@ package mir.util; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; -import mir.util.UtilExc; - public class HTTPClientHelper { private HttpClient client; private HttpMethod method; diff --git a/source/mir/util/HTTPRequestParser.java b/source/mir/util/HTTPRequestParser.java index 9b50247c..46954688 100755 --- a/source/mir/util/HTTPRequestParser.java +++ b/source/mir/util/HTTPRequestParser.java @@ -32,23 +32,25 @@ package mir.util; import java.util.ArrayList; import java.util.List; +import java.util.Collections; +import java.util.Map; import javax.servlet.http.HttpServletRequest; public class HTTPRequestParser { private HttpServletRequest request; - private String encoding; + private Map overridingParameters; public HTTPRequestParser(HttpServletRequest aRequest) { - this(aRequest, aRequest.getCharacterEncoding()); + this(aRequest, Collections.EMPTY_MAP); } - public HTTPRequestParser(HttpServletRequest aRequest, String anEncoding) { + public HTTPRequestParser(HttpServletRequest aRequest, Map anOverridingParameters) { request = aRequest; - encoding = anEncoding; + overridingParameters = anOverridingParameters; } public boolean hasParameter(String aName) { - return request.getParameter(aName)!=null; + return (request.getParameter(aName)!=null) || overridingParameters.containsKey(aName); } public String getParameterWithDefault(String aName, String aDefault) { @@ -61,13 +63,10 @@ public class HTTPRequestParser { public String getParameter(String aName) { try { String result = request.getParameter(aName); -// String requestEncoding = request.getCharacterEncoding(); -// if (requestEncoding==null) -// requestEncoding = "ISO-8859-1"; -// if (result != null && encoding!=null && !encoding.equals(requestEncoding)) { -// result = new String(result.getBytes(requestEncoding), encoding); -// } + if (result==null) { + result = (String) overridingParameters.get(aName); + } return result; } diff --git a/source/mir/util/ParameterExpander.java b/source/mir/util/ParameterExpander.java index 734bec98..e397f6f3 100755 --- a/source/mir/util/ParameterExpander.java +++ b/source/mir/util/ParameterExpander.java @@ -29,19 +29,14 @@ */ package mir.util; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - import mir.generator.Generator; import mir.generator.GeneratorExc; import multex.Exc; - import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.beanutils.PropertyUtils; +import java.util.*; + /** * Class to work with expressions. Will be gradually phased out and replaced * with {@link mir.util.expressions.ExpressionParser} @@ -576,7 +571,7 @@ public class ParameterExpander { private List parseList() { Token token; Object expression; - List result = new Vector(); + List result = new ArrayList(); token = scanner.scan(); if (!(token instanceof LeftParenthesisToken)) { diff --git a/source/mir/util/PropertiesManipulator.java b/source/mir/util/PropertiesManipulator.java index 25d3e55e..0044577e 100755 --- a/source/mir/util/PropertiesManipulator.java +++ b/source/mir/util/PropertiesManipulator.java @@ -35,11 +35,7 @@ import java.io.LineNumberReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; +import java.util.*; import multex.Exc; import multex.Failure; @@ -49,7 +45,7 @@ public class PropertiesManipulator { private Map values; public PropertiesManipulator() { - entries = new Vector(); + entries = new ArrayList(); values = new HashMap(); } diff --git a/source/mir/util/StructuredContentParser.java b/source/mir/util/StructuredContentParser.java index 412ecad5..7f3f3540 100755 --- a/source/mir/util/StructuredContentParser.java +++ b/source/mir/util/StructuredContentParser.java @@ -33,7 +33,7 @@ package mir.util; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Vector; +import java.util.ArrayList; /** @@ -138,7 +138,7 @@ public class StructuredContentParser { } public static List parseList(Scanner aScanner) { - List result = new Vector(); + List result = new ArrayList(); aScanner.skipSpace(); if (aScanner.peek() == '[') aScanner.scan(); diff --git a/source/mir/util/generator/ReflectionGeneratorFunctionAdapter.java b/source/mir/util/generator/ReflectionGeneratorFunctionAdapter.java index 1e98f7cb..3478665a 100755 --- a/source/mir/util/generator/ReflectionGeneratorFunctionAdapter.java +++ b/source/mir/util/generator/ReflectionGeneratorFunctionAdapter.java @@ -29,16 +29,14 @@ */ package mir.util.generator; +import java.lang.reflect.InvocationTargetException; +import java.util.List; + import mir.generator.Generator; import mir.generator.GeneratorExc; import mir.generator.GeneratorFailure; import mir.util.ReflectionRoutines; -import java.util.List; -import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.beanutils.MethodUtils; - /** * Class to adapt methods with some name to a * {@link Generator.Function} diff --git a/source/mircoders/abuse/AbstractFilterType.java b/source/mircoders/abuse/AbstractFilterType.java new file mode 100755 index 00000000..85b197e3 --- /dev/null +++ b/source/mircoders/abuse/AbstractFilterType.java @@ -0,0 +1,43 @@ +/* + * 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.abuse; + + +public abstract class AbstractFilterType implements FilterType { + private String name; + + public AbstractFilterType(String aName) { + name = aName; + } + + public String getName() { + return name; + } +} diff --git a/source/mircoders/abuse/AbuseExc.java b/source/mircoders/abuse/AbuseExc.java new file mode 100755 index 00000000..903f121e --- /dev/null +++ b/source/mircoders/abuse/AbuseExc.java @@ -0,0 +1,39 @@ +/* + * 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.abuse; + +import multex.Exc; + +public class AbuseExc extends Exc { + public AbuseExc(String aMessage) { + super(aMessage); + } +} diff --git a/source/mircoders/abuse/AbuseFailure.java b/source/mircoders/abuse/AbuseFailure.java new file mode 100755 index 00000000..429154c4 --- /dev/null +++ b/source/mircoders/abuse/AbuseFailure.java @@ -0,0 +1,43 @@ +/* + * 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.abuse; + +import multex.Failure; + +public class AbuseFailure extends Failure { + + public AbuseFailure(String msg,Throwable cause) { + super(msg,cause); + } + + public AbuseFailure(Throwable aCause) { + this (aCause.getMessage(), aCause); + } +} diff --git a/source/mircoders/abuse/FilterEngine.java b/source/mircoders/abuse/FilterEngine.java new file mode 100755 index 00000000..79f63d82 --- /dev/null +++ b/source/mircoders/abuse/FilterEngine.java @@ -0,0 +1,449 @@ +/* + * 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.abuse; + +import mir.entity.Entity; +import mir.entity.adapter.EntityAdapter; +import mir.entity.adapter.EntityAdapterModel; +import mir.entity.adapter.EntityIteratorAdapter; +import mir.log.LoggerWrapper; +import mir.storage.StorageObjectExc; +import mir.session.Request; +import mir.config.MirPropertiesConfiguration; +import mircoders.storage.DatabaseFilter; +import mircoders.storage.DatabaseFilterGroup; +import mircoders.global.MirGlobal; + +import java.util.*; +import java.text.SimpleDateFormat; + +public class FilterEngine { + private Map filterTypes; + private List filterTypeIds; + + private List filterGroups; + private Map idToFilterGroup; + private LoggerWrapper logger; + private EntityAdapterModel model; + private SimpleDateFormat dateFormat; + private MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance(); + + public FilterEngine(EntityAdapterModel aModel) { + logger = new LoggerWrapper("Global.Abuse.FilterEngine"); + filterGroups = new ArrayList(); + idToFilterGroup = new HashMap(); + + filterTypes = new HashMap(); + filterTypeIds = new ArrayList(); + try { + Iterator i = MirGlobal.localizer().openPostings().getAntiAbuseFilterTypes().iterator(); + while (i.hasNext()) { + FilterType filterType = (FilterType) i.next(); + + filterTypes.put(filterType.getName(), filterType); + filterTypeIds.add(filterType.getName()); + } + } + catch (Throwable t) { + throw new RuntimeException(t.getMessage()); + } + + model = aModel; + + dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + dateFormat.setTimeZone(TimeZone.getTimeZone(configuration.getString("Mir.DefaultTimezone"))); + reload(); + } + + public Filter testPosting(Entity anEntity, Request aRequest) { + Iterator i = filterGroups.iterator(); + while (i.hasNext()) { + FilterGroup group = (FilterGroup) i.next(); + Iterator j = group.getFilters().iterator(); + while (j.hasNext()) { + Filter filter = (Filter) j.next(); + try { + if (filter.test(anEntity, aRequest)) { + return filter; + } + } + catch (Throwable t) { + logger.warn("Exception thrown while testing filter " + filter.getType() + " ( " + filter.getExpression() + ") " + t.toString()); + } + } + } + + return null; + } + + public List getFilterTypes() { + try { + List result = new ArrayList(); + + Iterator i = filterTypeIds.iterator(); + while (i.hasNext()) { + String id = (String) i.next(); + + Map action = new HashMap(); + action.put("resource", id); + action.put("identifier", id); + + result.add(action); + } + + return result; + } + catch (Throwable t) { + throw new RuntimeException("can't get article actions"); + } + } + + public class FilterGroup { + private List filters; + private Entity entity; + private Map idToFilter; + + public FilterGroup(Entity anEntity) { + this (anEntity, Collections.EMPTY_LIST); + } + + public FilterGroup(Entity anEntity, List aFilters) { + entity = anEntity; + filters = new ArrayList(); + idToFilter = new HashMap(); + Iterator i = aFilters.iterator(); + + while (i.hasNext()) { + Entity entity = (Entity) i.next(); + try { + Filter filter = new Filter(entity); + introduceFilter(filter); + } + catch (AbuseExc e) { + } + } + } + + public Entity getEntity() { + return entity; + } + + public EntityAdapter getEntityAdapter() { + return model.makeEntityAdapter("filterGroup", entity); + } + + public List getFilterEntityAdapterList() { + List result = new ArrayList(); + + Iterator i = filters.iterator(); + while (i.hasNext()) { + Filter filter = (Filter) i.next(); + result.add(filter.getEntityAdapter()); + } + + return result; + } + + public List getFilters() { + return filters; + } + + public Filter getFilterForId(String anId) { + Filter result = (Filter) idToFilter.get(anId); + if (result==null) { + throw new NullPointerException("No such filter"); + } + + return result; + } + + private void introduceFilter(Filter aFilter) { + filters.add(aFilter); + idToFilter.put(aFilter.getEntity().getId(), aFilter); + } + + private void removeFilter(Filter aFilter) { + filters.remove(aFilter); + idToFilter.remove(aFilter.getEntity().getId()); + } + + private void deleteFilter(String anId) { + Filter filter = getFilterForId(anId); + removeFilter(filter); + DatabaseFilter.getInstance().delete(anId); + } + + public void populateFilterEntity(Entity anEntity, String aType, String anExpression, + String aComments, String aTag, String anArticleAction, + String aCommentAction) { + + anEntity.setFieldValue("type", aType); + anEntity.setFieldValue("expression", anExpression); + anEntity.setFieldValue("comment", aComments); + anEntity.setFieldValue("tag", aTag); + anEntity.setFieldValue("articleaction", anArticleAction); + anEntity.setFieldValue("commentaction", aCommentAction); + } + + public String updateFilter(String anId, String aType, String anExpression, + String aComments, String aTag, String anArticleAction, + String aCommentAction) { + + try { + getFilterTypeForId(aType).constructFilterInstance(anExpression); + } + catch (AbuseExc e) { + return e.getMessage(); + } + + Entity entity = getFilterForId(anId).getEntity(); + populateFilterEntity(entity, aType, anExpression, aComments, aTag, + anArticleAction, aCommentAction); + entity.update(); + + return ""; + } + + public String createFilter(String aType, String anExpression, + String aComments, String aTag, String anArticleAction, + String aCommentAction) throws StorageObjectExc { + FilterInstance instance; + + try { + instance = getFilterTypeForId(aType).constructFilterInstance(anExpression); + } + catch (AbuseExc e) { + return e.getMessage(); + } + + Entity entity = DatabaseFilter.getInstance().createNewEntity(); + populateFilterEntity(entity, aType, anExpression, aComments, aTag, + anArticleAction, aCommentAction); + entity.setFieldValue("priority", "1"); + entity.setFieldValue("filter_group_id", getEntity().getId()); + entity.insert(); + + Filter filter = new Filter(entity, instance); + introduceFilter(filter); + + return ""; + } + + public String getName() { + return entity.getFieldValue("name"); + } + } + + public class Filter { + private Entity entity; + private FilterInstance instance; + + public Filter(Entity anEntity) throws AbuseExc { + this(anEntity, getFilterTypeForId(anEntity.getFieldValue("type")).constructFilterInstance(anEntity.getFieldValue("expression"))); + } + + public Filter(Entity anEntity, FilterInstance anInstance) { + entity = anEntity; + instance = anInstance; + } + + public Entity getEntity() { + return entity; + } + + public EntityAdapter getEntityAdapter() { + return model.makeEntityAdapter("filter", entity); + } + + public void update(String aType, String anExpression, String aComments, String aTag, + String anArticleAction, String aCommentAction) throws AbuseExc { + + instance = getFilterTypeForId(aType).constructFilterInstance(anExpression); + + entity.setFieldValue("type", aType); + entity.setFieldValue("expression", anExpression); + entity.setFieldValue("tag", aType); + entity.setFieldValue("comment", aComments); + entity.setFieldValue("articleaction", anArticleAction); + entity.setFieldValue("commentaction", aCommentAction); + entity.setFieldValue("last_hit", null); + entity.update(); + } + + public void updateLastHit(Date aDate) { + entity.setFieldValue("last_hit", dateFormat.format(aDate)); + entity.update(); + } + + public String getType() { + return entity.getFieldValue("type"); + } + + public String getExpression() { + return entity.getFieldValue("expression"); + } + + public String getTag() { + return entity.getFieldValue("tag"); + } + + public String getComment() { + return entity.getFieldValue("comment"); + } + + public String getArticleAction() { + return entity.getFieldValue("articleaction"); + } + + public String getCommentAction() { + return entity.getFieldValue("commentaction"); + } + + public FilterInstance getInstance() { + return instance; + } + + public boolean test(Entity anEntity, Request aRequest) { + return instance.test(anEntity, aRequest); + } + } + + public synchronized void reload() { + filterGroups.clear(); + idToFilterGroup.clear(); + + Iterator i = new EntityIteratorAdapter("", "priority asc", 100, model, "filterGroup"); + + while (i.hasNext()) { + EntityAdapter entityAdapter = (EntityAdapter) i.next(); + List filters = new ArrayList(); + Iterator j = (Iterator) entityAdapter.get("to_filters"); + while (j.hasNext()) { + filters.add(((EntityAdapter) j.next()).getEntity()); + } + + FilterGroup filterGroup = new FilterGroup(entityAdapter.getEntity(), filters); + introduceFilterGroup(filterGroup); + } + } + + public synchronized List getFilterGroups() { + List result = new ArrayList(); + Iterator i = filterGroups.iterator(); + while (i.hasNext()) { + result.add(((FilterGroup) i.next()).getEntityAdapter()); + } + + return result; + } + + public synchronized void updateFilterGroup(String anId, String aName) { + FilterGroup filterGroup = getFilterGroupForId(anId); + filterGroup.getEntity().setFieldValue("name", aName); + filterGroup.getEntity().update(); + } + + public synchronized void addFilterGroup(String aName) throws StorageObjectExc { + Entity entity = DatabaseFilterGroup.getInstance().createNewEntity(); + entity.setFieldValue("name", aName); + entity.setFieldValue("priority", "1"); + entity.insert(); + + FilterGroup filterGroup = new FilterGroup(entity); + introduceFilterGroup(filterGroup); + } + + public synchronized void deleteFilterGroup(String anId) { + + FilterGroup filterGroup = getFilterGroupForId(anId); + removeFilterGroup(filterGroup); + DatabaseFilter.getInstance().deleteByWhereClause("filter_group_id = " + anId); + DatabaseFilterGroup.getInstance().delete(anId); + } + + public synchronized void deleteFilter(String aGroupId, String anId) { + getFilterGroupForId(aGroupId).deleteFilter(anId); + } + + + public synchronized String updateFilter(String aGroupId, String anId, + String aType, String anExpression, + String aComments, + String aTag, + String anArticleAction, + String aCommentAction) { + return getFilterGroupForId(aGroupId).updateFilter(anId, aType, + anExpression, aComments, aTag, anArticleAction, aCommentAction); + } + + public synchronized String addFilter(String aGroupId, + String aType, String anExpression, + String aComments, + String aTag, + String anArticleAction, + String aCommentAction) throws StorageObjectExc { + return getFilterGroupForId(aGroupId).createFilter(aType, anExpression, + aComments, aTag, anArticleAction, aCommentAction); + } + + + public FilterGroup getFilterGroupForId(String anId) { + FilterGroup result = (FilterGroup) idToFilterGroup.get(anId); + if (result == null) { + throw new NullPointerException("No such filter group"); + } + + return result; + } + + public Filter getFilterForId(String aGroupId, String anId) { + return getFilterGroupForId(aGroupId).getFilterForId(anId); + } + + + public List getFilters(String aFilterGroupId) { + return getFilterGroupForId(aFilterGroupId).getFilterEntityAdapterList(); + } + + private void introduceFilterGroup(FilterGroup aFilterGroup) { + filterGroups.add(aFilterGroup); + idToFilterGroup.put(aFilterGroup.getEntity().getId(), aFilterGroup); + } + + private void removeFilterGroup(FilterGroup aFilterGroup) { + filterGroups.remove(aFilterGroup); + idToFilterGroup.remove(aFilterGroup.getEntity().getId()); + } + + private FilterType getFilterTypeForId(String anId) { + return (FilterType) filterTypes.get(anId); + } +} diff --git a/source/mircoders/abuse/FilterInstance.java b/source/mircoders/abuse/FilterInstance.java new file mode 100755 index 00000000..dd20409e --- /dev/null +++ b/source/mircoders/abuse/FilterInstance.java @@ -0,0 +1,46 @@ +/* + * 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.abuse; + +import mir.entity.Entity; +import mir.session.Request; + +public interface FilterInstance { + /** + * Must return true if the posting matches the filter. + */ + public boolean test(Entity anEntity, Request aRequest); + + /** + * May return a desription of the "status" of this filter. (E.g. the number + * of hits) + */ + public String status(); +} diff --git a/source/mircoders/abuse/FilterParseExc.java b/source/mircoders/abuse/FilterParseExc.java new file mode 100755 index 00000000..aeb43c14 --- /dev/null +++ b/source/mircoders/abuse/FilterParseExc.java @@ -0,0 +1,36 @@ +/* + * 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.abuse; + +public class FilterParseExc extends AbuseExc { + public FilterParseExc(String aMessage) { + super(aMessage); + } +} diff --git a/source/mircoders/abuse/FilterType.java b/source/mircoders/abuse/FilterType.java new file mode 100755 index 00000000..acf37266 --- /dev/null +++ b/source/mircoders/abuse/FilterType.java @@ -0,0 +1,51 @@ +/* + * 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.abuse; + + + +/** + * Interface to define filter types for the anti-abuse system + */ + +public interface FilterType { + /** + * The identifying name of the filter type. Must be unique. + * + * @return + */ + public String getName(); + + /** + * Must construct a filter instance or throw an exception if + * anExpression is not a valid expression. + */ + public FilterInstance constructFilterInstance(String anExpression) throws AbuseExc; +} \ No newline at end of file diff --git a/source/mircoders/abuse/IPFilterType.java b/source/mircoders/abuse/IPFilterType.java new file mode 100755 index 00000000..e6018317 --- /dev/null +++ b/source/mircoders/abuse/IPFilterType.java @@ -0,0 +1,80 @@ +/* + * 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.abuse; + +import mir.util.InternetFunctions; +import mir.entity.Entity; +import mir.session.Request; + +/** + * A basic ip filter type. Supports x.x.x.x, x.x.x.x/x and x.x.x.x/x.x.x.x expressions. + */ +public class IPFilterType extends AbstractFilterType { + public IPFilterType(String aName) { + super(aName); + } + + /** + * + */ + public boolean validate(String anExpression) { + try { + InternetFunctions.isIpAddressInNetwork("1.1.1.1", anExpression); + return true; + } + catch (Throwable t) { + return false; + } + } + + public FilterInstance constructFilterInstance(final String anExpression) throws AbuseExc { + try { + InternetFunctions.isIpAddressInNetwork("1.1.1.1", anExpression); + } + catch (Throwable t) { + throw new AbuseExc("Invalid expression: " + anExpression); + } + + return new FilterInstance() { + public boolean test(Entity anEntity, Request aRequest) { + try { + return InternetFunctions.isIpAddressInNetwork(aRequest.getHeader("ip"), anExpression); + } + catch (Exception e) { + return false; + } + } + + public String status() { + return ""; + } + }; + } +} diff --git a/source/mircoders/abuse/RegularExpressionFilterType.java b/source/mircoders/abuse/RegularExpressionFilterType.java new file mode 100755 index 00000000..13d1db52 --- /dev/null +++ b/source/mircoders/abuse/RegularExpressionFilterType.java @@ -0,0 +1,152 @@ +/* + * 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.abuse; + +import gnu.regexp.RE; +import mir.entity.Entity; +import mir.session.Request; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + + +/** + * A regular expression filter. + */ + public class RegularExpressionFilterType extends AbstractFilterType { + private boolean exactMatch; + private boolean caseSensitive; + private int fieldKind; + private List selectedFields; + + public static final int ENTITY_FIELDS = 0; + public static final int REQUEST_HEADERS = 2; + + public RegularExpressionFilterType(String aName) { + this(aName, false, false, null); + } + + public RegularExpressionFilterType(String aName, boolean aCaseSensitive, boolean anExactMatch, String[] aSelectedFields) { + this (aName, aCaseSensitive, anExactMatch, ENTITY_FIELDS, aSelectedFields); + } + + public RegularExpressionFilterType(String aName, boolean aCaseSensitive, boolean anExactMatch, int aFieldKind, String[] aSelectedFields) { + super(aName); + + fieldKind = aFieldKind; + + caseSensitive = aCaseSensitive; + exactMatch = anExactMatch; + if (aSelectedFields==null) + selectedFields = null; + else + selectedFields = Arrays.asList(aSelectedFields); + } + + + public FilterInstance constructFilterInstance(final String anExpression) throws AbuseExc { + try { + new RE(anExpression); + + return new FilterInstance() { + + public boolean test(Entity anEntity, Request aRequest) { + + try { + Iterator j; + int flags = 0; + + if (!caseSensitive) { + flags |= RE.REG_ICASE; + } + + RE regularExpression = new RE(anExpression, flags); + + switch (fieldKind) { + case REQUEST_HEADERS: + if (selectedFields != null) { + j = selectedFields.iterator(); + + while (j.hasNext()) { + String fieldName = (String) j.next(); + String field = aRequest.getHeader(fieldName); + + if (exactMatch) { + if (field != null && regularExpression.isMatch(field)) { + return true; + } + } + else { + if (field != null && regularExpression.getMatch(field) != null) { + return true; + } + } + } + } + break; + case ENTITY_FIELDS: + if (selectedFields != null) + j = selectedFields.iterator(); + else + j = anEntity.getFieldNames().iterator(); + + while (j.hasNext()) { + String field = anEntity.getFieldValue( (String) j.next()); + + if (exactMatch) { + if (field != null && regularExpression.isMatch(field)) { + return true; + } + } + else { + if (field != null && regularExpression.getMatch(field) != null) { + return true; + } + } + } + } + } + catch (Throwable t) { + } + return false; + } + + public String status() { + return null; + } + }; + } + catch (Throwable t) { + throw new AbuseExc("Invalid expression: " + t.getMessage()); + } + } +} \ No newline at end of file diff --git a/source/mircoders/abuse/ThrottleFilter.java b/source/mircoders/abuse/ThrottleFilter.java new file mode 100755 index 00000000..714f2058 --- /dev/null +++ b/source/mircoders/abuse/ThrottleFilter.java @@ -0,0 +1,151 @@ +/* + * 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.abuse; + +import mir.entity.Entity; +import mir.session.Request; +import mir.util.StringRoutines; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * A ip-based throttling filter. + * + *

+ * Expressions have the form

Title: Experimental session handler for comment postings

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

+ * Session handler for comment postings + * * @author Zapata - * @version 1.0 */ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler { - protected ModuleComment commentModule = new ModuleComment(); + protected DatabaseComment commentDatabase = DatabaseComment.getInstance(); protected DatabaseCommentToMedia commentToMedia = DatabaseCommentToMedia.getInstance(); @@ -122,7 +124,7 @@ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler String id; Map values = getIntersectingValues(aRequest, DatabaseComment.getInstance()); - EntityComment comment = (EntityComment) commentModule.createNew(); + EntityComment comment = (EntityComment) commentDatabase.createNewEntity(); comment.setFieldValues(values); finalizeComment(aRequest, aSession, comment); id = comment.insert(); diff --git a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java index 4a41049f..89e1914c 100755 --- a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java @@ -31,9 +31,7 @@ package mircoders.localizer.basic; import mir.config.MirPropertiesConfiguration; import mir.entity.Entity; -import mir.entity.adapter.EntityAdapter; -import mir.entity.adapter.EntityAdapterDefinition; -import mir.entity.adapter.EntityAdapterModel; +import mir.entity.adapter.*; import mir.generator.Generator; import mir.generator.GeneratorExc; import mir.generator.GeneratorFailure; @@ -69,13 +67,12 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { anEntityAdapterDefinition.addDBDateField("changedate", "webdb_lastchange", configuration.getString("Mir.DefaultTimezone")); anEntityAdapterDefinition.addMirDateField("date", "date", configuration.getString("Mir.DefaultTimezone")); - anEntityAdapterDefinition.addCalculatedField("lockinguser", new ContentToUserField("to_locking_user")); + anEntityAdapterDefinition.addCalculatedField("lockinguser", new ToOneRelationField("to_locking_user", "id", "user")); anEntityAdapterDefinition.addCalculatedField("is_locked", new ContentToIsLockedField()); anEntityAdapterDefinition.addCalculatedField("to_topics", new ContentToTopicsField()); anEntityAdapterDefinition.addCalculatedField("to_comments", new ContentToCommentsField()); - anEntityAdapterDefinition.addCalculatedField("language", new ContentToLanguageField()); - + anEntityAdapterDefinition.addCalculatedField("language", new ToOneRelationField("to_language", "language", "id")); anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'")); anEntityAdapterDefinition.addCalculatedField("fullcommentcount", new ContentCommentCountField("")); @@ -101,13 +98,13 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new ContentToMediaField( "otherMedia", false)); anEntityAdapterDefinition.addCalculatedField("to_media_icon", new ContentToIconField()); - anEntityAdapterDefinition.addCalculatedField("article_type", new ContentToArticleTypeField()); + anEntityAdapterDefinition.addCalculatedField("article_type", new ToOneRelationField("to_article_type", "articleType", "id")); anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description")); anEntityAdapterDefinition.addCalculatedField("content_data_parsed", new FilteredField("content_data")); anEntityAdapterDefinition.addCalculatedField("children", new ContentToChildrenField()); - anEntityAdapterDefinition.addCalculatedField("parent", new ContentToParentField()); + anEntityAdapterDefinition.addCalculatedField("parent", new ToOneRelationField("to_content", "content", "id")); anEntityAdapterDefinition.addCalculatedField("publicurl", new ExpandedField(configuration.getString("Article.PublicUrl"))); @@ -142,7 +139,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { protected void constructCommentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure { try { anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone")); - anEntityAdapterDefinition.addCalculatedField("to_content", new CommentToContentField()); + anEntityAdapterDefinition.addCalculatedField("to_content", new ToOneRelationField("to_media", "content", "id")); anEntityAdapterDefinition.addCalculatedField("status", new CommentToStatusField()); anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new CommentToMediaField( "uploadedMedia" )); @@ -196,27 +193,27 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { result.addMapping( "internalMessage", DatabaseMessages.getInstance(), definition); definition = new EntityAdapterDefinition(); - definition.addCalculatedField("mediafolder", new MediaToMediaFolderField()); + definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id")); definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value")); definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone")); definition.addCalculatedField("info", new MediaToMediaInfoField()); result.addMapping( "uploadedMedia", DatabaseUploadedMedia.getInstance(), definition); definition = new EntityAdapterDefinition(); - definition.addCalculatedField("mediafolder", new MediaToMediaFolderField()); + definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id")); definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value")); definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone")); definition.addCalculatedField("info", new MediaToMediaInfoField()); definition.addCalculatedField("big_icon", new MediaToBigIconField()); result.addMapping( "image", DatabaseImages.getInstance(), definition); definition = new EntityAdapterDefinition(); - definition.addCalculatedField("mediafolder", new MediaToMediaFolderField()); + definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id")); definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value")); definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone")); definition.addCalculatedField("info", new MediaToMediaInfoField()); definition.addCalculatedField("big_icon", new MediaToBigIconField()); result.addMapping( "audio", DatabaseAudio.getInstance(), definition); definition = new EntityAdapterDefinition(); - definition.addCalculatedField("mediafolder", new MediaToMediaFolderField()); + definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id")); definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value")); definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone")); definition.addCalculatedField("info", new MediaToMediaInfoField()); @@ -224,7 +221,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { result.addMapping( "video", DatabaseVideo.getInstance(), definition); definition = new EntityAdapterDefinition(); - definition.addCalculatedField("mediafolder", new MediaToMediaFolderField()); + definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id")); definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value")); definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone")); definition.addCalculatedField("info", new MediaToMediaInfoField()); @@ -246,6 +243,15 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { result.addMapping( "content_x_topic", DatabaseContentToTopics.getInstance(), new EntityAdapterDefinition()); + definition = new EntityAdapterDefinition(); + definition.addCalculatedField("to_filters", + new ToManyRelationField("id", "filter", "filter_group_id", "priority asc")); + result.addMapping("filterGroup", DatabaseFilterGroup.getInstance(), definition); + definition = new EntityAdapterDefinition(); + definition.addDBDateField("lasthit", "last_hit", configuration.getString("Mir.DefaultTimezone")); + definition.addCalculatedField("to_filter_group", + new ToOneRelationField("filter_group_id", "filter_group", "id")); + result.addMapping("filter", DatabaseFilter.getInstance(), definition); } catch (Throwable t) { throw new MirLocalizerFailure(t.getMessage(), t); @@ -254,20 +260,6 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { return result; } - protected class CommentToContentField implements EntityAdapterDefinition.CalculatedField { - public Object getValue(EntityAdapter anEntityAdapter) { - try { - return anEntityAdapter.getToOneRelation( - "id="+anEntityAdapter.get("to_media"), - "id", - "content" ); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - } - protected class CommentToStatusField implements EntityAdapterDefinition.CalculatedField { public Object getValue(EntityAdapter anEntityAdapter) { try { @@ -292,7 +284,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { public Object getValue(EntityAdapter anEntityAdapter) { try { Iterator i = operations.iterator(); - List availableOperations = new Vector(); + List availableOperations = new ArrayList(); while (i.hasNext()) { MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = @@ -384,21 +376,6 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } } - protected class ContentToParentField implements EntityAdapterDefinition.CalculatedField { - public Object getValue(EntityAdapter anEntityAdapter) { - try { - logger.debug("ContentToParentField.getFieldValue"); - return anEntityAdapter.getToOneRelation( - "id="+anEntityAdapter.get("to_content"), - "id", - "content" ); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - } - protected class ContentToChildrenField implements EntityAdapterDefinition.CalculatedField { public Object getValue(EntityAdapter anEntityAdapter) { try { @@ -412,49 +389,6 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } } } - - protected class ContentToLanguageField implements EntityAdapterDefinition.CalculatedField { - public Object getValue(EntityAdapter anEntityAdapter) { - try { - return anEntityAdapter.getToOneRelation( - "id="+anEntityAdapter.get("to_language"), - "id", - "language" ); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - } - - protected class ContentToArticleTypeField implements EntityAdapterDefinition.CalculatedField { - public Object getValue(EntityAdapter anEntityAdapter) { - try { - return anEntityAdapter.getToOneRelation( - "id="+anEntityAdapter.get("to_article_type"), - "id", - "articleType" ); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - } - - protected class MediaToMediaFolderField implements EntityAdapterDefinition.CalculatedField { - public Object getValue(EntityAdapter anEntityAdapter) { - try { - return anEntityAdapter.getToOneRelation( - "id="+anEntityAdapter.get("to_media_folder"), - "id", - "mediaFolder" ); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - } - public static class MediaInfo { private MediaHandler mediaHandler; @@ -550,7 +484,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { public Object getValue(EntityAdapter anEntityAdapter) { try { - Vector extraTable = new Vector(); + ArrayList extraTable = new ArrayList(); extraTable.add("content_x_topic cxt"); String condition = "cxt.content_id="+anEntityAdapter.get("id")+ " and cxt.topic_id=t.id"; @@ -587,7 +521,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { if (published) condition = "is_published='t' and " + condition; - List extraTables = new Vector(); + List extraTables = new ArrayList(); extraTables.add("content_x_media cxm"); return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition); @@ -618,7 +552,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { if (published) condition = "is_published='t' and " + condition; - List extraTables = new Vector(); + List extraTables = new ArrayList(); extraTables.add("content_x_media cxm"); return anEntityAdapter.getComplexToOneRelation("m", extraTables, condition, "id", definition); @@ -650,7 +584,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { if (published) condition = "is_published='t' and " + condition; - List extraTables = new Vector(); + List extraTables = new ArrayList(); extraTables.add("comment_x_media cxm"); return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition); @@ -759,7 +693,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { public Object getValue(EntityAdapter anEntityAdapter) { try { - Vector extraTable = new Vector(); + ArrayList extraTable = new ArrayList(); extraTable.add(table+" m"); String selectSql = "cxm.media_id=m.id and cxm.content_id="+ anEntityAdapter.get("id"); @@ -776,26 +710,6 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } } - protected class ContentToUserField implements EntityAdapterDefinition.CalculatedField { - private String fieldName; - - public ContentToUserField(String aFieldName) { - fieldName = aFieldName; - } - - public Object getValue(EntityAdapter anEntityAdapter) { - try { - return anEntityAdapter.getToOneRelation( - "id=" + anEntityAdapter.get(fieldName), - "id", - "user"); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - } - protected class ContentToIsLockedField implements EntityAdapterDefinition.CalculatedField { private ModuleContent contentModule; diff --git a/source/mircoders/localizer/basic/MirBasicEmailArticleHandler.java b/source/mircoders/localizer/basic/MirBasicEmailArticleHandler.java index 39d0908f..1df0a86b 100755 --- a/source/mircoders/localizer/basic/MirBasicEmailArticleHandler.java +++ b/source/mircoders/localizer/basic/MirBasicEmailArticleHandler.java @@ -32,12 +32,12 @@ package mircoders.localizer.basic; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Vector; -import java.util.Collections; +import java.util.ArrayList; import mir.config.MirPropertiesConfiguration; import mir.generator.Generator; @@ -56,7 +56,6 @@ import mircoders.entity.EntityContent; import mircoders.global.CacheKey; import mircoders.global.MirGlobal; import mircoders.module.ModuleContent; -import mircoders.storage.DatabaseContent; import org.apache.commons.net.smtp.SMTPClient; import org.apache.commons.net.smtp.SMTPReply; @@ -292,7 +291,7 @@ public class MirBasicEmailArticleHandler implements SessionHandler { protected void subsequentRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure { - List validationErrors = new Vector(); + List validationErrors = new ArrayList(); if (shouldSendMail(aRequest,aSession,aResponse,validationErrors)){ sendMail(aRequest,aSession,aResponse); diff --git a/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java b/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java index d5a898c8..5501e7ae 100755 --- a/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java @@ -34,15 +34,17 @@ import mir.log.LoggerWrapper; import mir.session.Request; import mir.session.Session; import mir.session.SessionHandler; +import mircoders.abuse.FilterType; +import mircoders.abuse.ThrottleFilter; +import mircoders.abuse.IPFilterType; +import mircoders.abuse.RegularExpressionFilterType; import mircoders.entity.EntityComment; import mircoders.entity.EntityContent; import mircoders.global.MirGlobal; import mircoders.global.ProducerEngine; -import mircoders.localizer.MirAntiAbuseFilterType; import mircoders.localizer.MirLocalizerExc; import mircoders.localizer.MirLocalizerFailure; import mircoders.localizer.MirOpenPostingLocalizer; -import mircoders.localizer.basic.filters.ThrottleFilter; import java.util.*; @@ -77,26 +79,26 @@ public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer { throw new MirLocalizerFailure(t); } - filterTypes = new Vector(); + filterTypes = new ArrayList(); filterTypesMap = new HashMap(); - addSimpleAntiAbuseFilterType(new MirBasicAntiAbuseFilterTypes.RegularExpressionFilter("regexp")); - addSimpleAntiAbuseFilterType(new MirBasicAntiAbuseFilterTypes.RegularExpressionFilter("useragent", false, false, - MirBasicAntiAbuseFilterTypes.RegularExpressionFilter.REQUEST_HEADERS, new String[] {"User-Agent"})); - addSimpleAntiAbuseFilterType(new MirBasicAntiAbuseFilterTypes.IPFilter("ip")); - addSimpleAntiAbuseFilterType(new MirBasicAntiAbuseFilterTypes.RegularExpressionFilter("hostname", false, false, - MirBasicAntiAbuseFilterTypes.RegularExpressionFilter.REQUEST_HEADERS, new String[] {"hostname"})); + addSimpleAntiAbuseFilterType(new RegularExpressionFilterType("regexp")); + addSimpleAntiAbuseFilterType(new RegularExpressionFilterType("useragent", false, false, + RegularExpressionFilterType.REQUEST_HEADERS, new String[] {"User-Agent"})); + addSimpleAntiAbuseFilterType(new IPFilterType("ip")); + addSimpleAntiAbuseFilterType(new RegularExpressionFilterType("hostname", false, false, + RegularExpressionFilterType.REQUEST_HEADERS, new String[] {"hostname"})); addSimpleAntiAbuseFilterType(new ThrottleFilter("throttle", 60*60*1000)); } public SessionHandler getOpenSessionHandler(String aSessionType) throws MirLocalizerExc, MirLocalizerFailure { - if (aSessionType!=null && aSessionType.equals("email")) + if ("email".equals(aSessionType)) return new MirBasicEmailArticleHandler(); - if (aSessionType!=null && aSessionType.equals("comment")) + if ("comment".equals(aSessionType)) return new MirBasicCommentPostingHandler(configuration.getBoolean("Localizer.OpenSession.PersistentUploadedFiles")); - if (aSessionType.equals("translation")) + if ("translation".equals(aSessionType)) return new MirBasicTranslationPostingHandler(); return new MirBasicArticlePostingHandler(configuration.getBoolean("Localizer.OpenSession.PersistentUploadedFiles")); @@ -173,7 +175,7 @@ public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer { filterTypesMap.remove(aName); } - public void addSimpleAntiAbuseFilterType(MirAntiAbuseFilterType aFilterType) { + public void addSimpleAntiAbuseFilterType(FilterType aFilterType) { removeSimpleAntiAbuseFilterType(aFilterType.getName()); filterTypesMap.put(aFilterType.getName(), aFilterType); filterTypes.add(aFilterType); diff --git a/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java b/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java index d762c0d3..4839f724 100755 --- a/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java +++ b/source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java @@ -29,19 +29,35 @@ */ package mircoders.localizer.basic; +import java.io.File; +import java.io.FileInputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + import mir.config.MirPropertiesConfiguration; import mir.log.LoggerWrapper; -import mir.session.*; +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.storage.StorageObject; import mir.util.ExceptionFunctions; import mir.util.FileFunctions; import mircoders.global.MirGlobal; -import mircoders.module.ModuleMediaType; import mircoders.media.UnsupportedMediaTypeExc; -import java.io.*; -import java.util.*; - /** * Extensible handler for open postings. * Behaviour can be altered by overriding methods. diff --git a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java index 66d55962..a1a0982e 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java @@ -30,11 +30,7 @@ package mircoders.localizer.basic; import java.io.File; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; +import java.util.*; import mir.entity.adapter.EntityAdapterModel; import mir.generator.Generator; @@ -66,7 +62,7 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { logger = new LoggerWrapper("Localizer.Basic.Producer"); producerRecipes = new HashMap(); - producerRecipeNames = new Vector(); + producerRecipeNames = new ArrayList(); String[] recipes = MirGlobal.config().getStringArray("Mir.Localizer.Producer.ProducerRecipes"); for (int i = 0; iTitle: Session handler for translation postings

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

- * @author Zapata - * @version 1.0 - */ - public class MirBasicTranslationPostingHandler extends MirBasicChildArticlePostingHandler { public MirBasicTranslationPostingHandler() { super(); diff --git a/source/mircoders/localizer/basic/MirBasicUtilityFunctions.java b/source/mircoders/localizer/basic/MirBasicUtilityFunctions.java index 363b9972..1e6b304d 100755 --- a/source/mircoders/localizer/basic/MirBasicUtilityFunctions.java +++ b/source/mircoders/localizer/basic/MirBasicUtilityFunctions.java @@ -29,12 +29,17 @@ */ package mircoders.localizer.basic; -import mir.util.*; -import mir.config.MirPropertiesConfiguration; - import java.util.Collections; import java.util.List; +import mir.util.HTMLRoutines; +import mir.util.JDBCStringRoutines; +import mir.util.ParameterExpander; +import mir.util.RewindableIterator; +import mir.util.StringRoutines; +import mir.util.StructuredContentParser; +import mir.util.SubsetIterator; + public class MirBasicUtilityFunctions { public String encodeXML(Object anObject) throws Exception { return HTMLRoutines.encodeXML(StringRoutines.interpretAsString(anObject)); diff --git a/source/mircoders/localizer/basic/filters/ThrottleFilter.java b/source/mircoders/localizer/basic/filters/ThrottleFilter.java deleted file mode 100755 index 65b47320..00000000 --- a/source/mircoders/localizer/basic/filters/ThrottleFilter.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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.filters; - -import mircoders.localizer.basic.MirBasicAntiAbuseFilterTypes; -import mircoders.entity.EntityComment; - -import java.util.*; - -import mir.util.StringRoutines; -import mir.entity.Entity; -import mir.session.Request; - -/** - * A ip-based throttling filter. - * - *

- * Expressions have the form

${lang("abuse.filtererror."+errormessage)} -

- - - - - - - - - - - - - - - - - - - - - - -

[<] ${lang("back")}  

- - - diff --git a/templates/admin/abuse.filters.template b/templates/admin/abuse.filters.template deleted file mode 100755 index 5c9db62b..00000000 --- a/templates/admin/abuse.filters.template +++ /dev/null @@ -1,80 +0,0 @@ - - - ${config["Mir.Name"]} | ${lang("abuse.filters.htmltitle")} - - - - - - - -

- [ < ] ${lang("back")}   - [+] ${lang("add")}   - - ${lang("abuse.showlog")} - -

-

- - - - - - - - - - - - - - -

- [ < ] ${lang("back")}   - [+] ${lang("add")}   - - ${lang("abuse.showlog")} - -

-

- - - - - - - - diff --git a/templates/admin/abuse.template b/templates/admin/abuse.template index 53e27cd0..185b5d5a 100755 --- a/templates/admin/abuse.template +++ b/templates/admin/abuse.template @@ -60,7 +60,7 @@ > ${lang("abuse.showlog")}
- > ${lang("abuse.showfilters")} + > ${lang("abuse.showfiltergroups")}

diff --git a/templates/admin/contentlist.template b/templates/admin/contentlist.template index b89e0aa1..8aaaf745 100755 --- a/templates/admin/contentlist.template +++ b/templates/admin/contentlist.template @@ -24,7 +24,7 @@ - + @@ -60,7 +60,7 @@ - + class="listrow1"class="listrow2"> ${entry.creationdate.format(config["Mir.DefaultDateTimeFormat"])}
diff --git a/templates/admin/error.template b/templates/admin/error.template index 65f7d009..402dbb88 100755 --- a/templates/admin/error.template +++ b/templates/admin/error.template @@ -11,6 +11,7 @@

${lang("error.title")}

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])}


${date.format(config["Mir.DefaultDateTimeFormat"])} -- ${errorstring}

+


${utility.prettyEncodeHTML(stacktrace)}

${lang("error.text2", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])}

diff --git a/templates/admin/filter.template b/templates/admin/filter.template new file mode 100755 index 00000000..285aa106 --- /dev/null +++ b/templates/admin/filter.template @@ -0,0 +1,47 @@ + + + ${lang("filter.htmltitle")} + + + + + + + + + + + + +

${utility.prettyEncodeHTML(errormessage)} +

+
+ + + + + + + + + + + + + + + + + + + + + + +

[<] ${lang("back")}  

+ + + diff --git a/templates/admin/filtergroup.template b/templates/admin/filtergroup.template new file mode 100755 index 00000000..4c8388d2 --- /dev/null +++ b/templates/admin/filtergroup.template @@ -0,0 +1,36 @@ + + + ${lang("abuse.filtergroup.htmltitle")} + + + + + + + + + + + + + + + + + + + + + + + + + + +

[<] ${lang("back")}  

+ + + diff --git a/templates/admin/filtergrouplist.template b/templates/admin/filtergrouplist.template new file mode 100755 index 00000000..a4a78929 --- /dev/null +++ b/templates/admin/filtergrouplist.template @@ -0,0 +1,42 @@ + + + ${config["Mir.Name"]} | ${lang("filtergrouplist.htmltitle")} + + + + + + + +

+ [ < ] ${lang("back")}   + [+] ${lang("add")}   + + ${lang("abuse.showlog")} + +

+

+ + + + + + + + + +

+ [ < ] ${lang("back")}   + [+] ${lang("add")}   +

+

+ + + + \ No newline at end of file diff --git a/templates/admin/filterlist.template b/templates/admin/filterlist.template new file mode 100755 index 00000000..c708b52e --- /dev/null +++ b/templates/admin/filterlist.template @@ -0,0 +1,86 @@ + + + ${config["Mir.Name"]} | ${lang("filterlist.htmltitle")} + + + + + + + +

+ [ < ] ${lang("back")}   + [+] ${lang("add")}   + + ${lang("showlog")} + +

+

+ + + + + + + + + + + + + + + + +

+ [ < ] ${lang("back")}   + [+] ${lang("add")}   + + ${lang("showlog")} + +

+

+ + + + + + + +